See the top rated post in this thread. Click here

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: writing a LISP to automate daily practice

  1. #11
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    2

    Default Re: writing a LISP to automate daily practice

    I concur with Tom on the Student Version drawings. However, you can still automate a lot of these steps.

    I would first create the template drawing containing this CROSS block used by your surveyor. In that template, modify the CROSS block to fit your desired output. I would add three ATTRIBUTE DEFINITIONS to the block with each mimicking the text provided by the surveyor in your desired height and the layer the text is currently on. For the HEIGHT attribute, I would add a block placeholder for the Z coordinate with the appropriate precision. For the CO_ORD attribute, I would do the same for the X and Y coordinates with similar precision. Once you have that you can continue to the automation.

    Using your template, INSERT and EXPLODE your surveyor's drawing. This will make your CROSS block take precedence over the surveyor's block. All of the surveyor's CROSS blocks will be rewritten to match your CROSS block definition. You would then use the ATTSYNC command to update the location labels for the block.

    Once the surveyor's drawing is inserted and exploded, you can use the SSGET AutoLISP function to create a selection set of different elements from the drawing by providing filters to the function. With this function, you can select elements from the entire drawing database. I would do this once for the ID text, and then once for all of the CROSS block INSERT locations.

    REPEATing through each selection set and append each element to a list. Properties of these elements that would be helpful could be the entity's handle (group code 5) and the insertion point of the block (group code 10) or the text attachment point (group code 11). Once you have two lists continue to the next step.

    Let's run through the list containing the TEXT elements. We can do this using the FOREACH AutoLISP function. Inside this FOREACH loop, let's run through the BLOCK element list using another FOREACH loop. Inside the BLOCK FOREACH loop, we need to compare the coordinates between the text and the block insertion point. Unfortunately, the coordinates do not exactly match, but are close. To get around this, we can use the EQUAL AutoLISP function with a fuzz factor. If the coordinates match, then do something.

    In this something branch of the IF statement, we should probably do a bunch of steps. To do that in an IF statement in AutoLISP, you would need to wrap all of those steps in a PROGN function. The first step in this group of steps in the true leg of the IF/PROGN statement, we should update the ID attribute of the CROSS block we created earlier. You can use PutBlkAttribute routine found in this post found in the forums here. This routine requires you to provide the block or entity. Here you could provide the entity name by retrieving it with the HANDENT AutoLISP function. We would get this from the current element being reviewed in the BLOCK FOREACH list. The other parameters of the PutBlkAttribute routine would be the attribute name we defined earlier, probably ID, and then the value of the attribute. That would be the text value (group code 1) of the current element being reviewed in the TEXT FOREACH list.

    The next step would be deleting the TEXT element from the text list. Doing so in the FOREACH loop may cause issues, therefore, I would recommend appending the handle of the TEXT element to a new list. We can then process this new list after we complete the attribute updating.

    Another step would be putting the block insertion on the layer you desired. We can evaluate the text value for the ID to either create or verify the desired layer exists. If the layer exists, then set the layer (group code for the block to the desired layer.

    You will probably be done with that group of FOREACH loops by now, so you could then delete the text using another FOREACH loop on the new list we created.

    Your code you posted earlier to draw lines could be modified to cycle through the layers and connected the insertion points of the blocks.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  2. #12
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    1

    Default Re: writing a LISP to automate daily practice

    And to add to what I have added above, try some of this code. This would be executed after the surveyor's drawing is inserted and exploded and the attributes are synced.

    It may, or may not work for you as it is not completely tested.
    Code:
    (defun c:EasyButton (/ ssIds ssBlk lstText lstBlks lstDel blk val) 
      (defun op:SSHandlesToList (ss gcode / ent lst) 
        (repeat (setq cnt (sslength ss)) 
          (setq ent (entget (ssname ss (setq cnt (1- cnt))))
                lst (append lst 
                            (list (cons (cdr (assoc 5 ent)) (cdr (assoc gcode ent))))
                    )
          )
        )
        lst
      )
      (defun op:GetIDLayerName (val / spot1 str) 
        (if (setq spot1 (vl-string-search "_" val)) 
          (setq str (strcat 
                      (substr val 
                              spot1
                              (- (vl-string-search "." val) (vl-string-search "_" val))
                      )
                      "-"
                      (rtos (getvar 'cdate) 2 0)
                    )
          )
        )
        str
      )
      (setq ssIds   (ssget "X" 
                           '((0 . "TEXT")
                             (8 . "PT_ID")
                            )
                    )
            ssBlk   (ssget "X" 
                           '((0 . "INSERT")
                             (2 . "CROSS")
                            )
                    )
            lstText '()
            lstBlks '()
            lstDel  '()
      )
      (if 
        (and (> (sslength ssIds) 0) 
             (> (sslength ssBlk) 0)
        )
        (progn 
          (setq lstText (op:SSHandlesToList ssIds 11)
                lstBlks (op:SSHandlesToList ssBlk 10)
          )
          (foreach n lstText 
            (foreach j lstBlks 
              (if (equal (cdr n) (cdr j) 0.0001) 
                (progn 
                  (PutBlkAttrib 
                    (setq blk (handent (car j)))
                    "ID"
                    (setq val (cdr (assoc 1 (entget (handent (car n))))))
                  )
                  (setq lstDel (append lstDel (list car n))
                        sLayer (op:GetIDLayerName val)
                  )
                  (if (not (tblsearch "LAYER" sLayer)) 
                    (command "-layer" "m" sLayer "")
                  )
                  (entmod (subst (cons 8 sLayer) (assoc 8 blk) blk))
                )
              )
            )
          )
          (foreach n lstDel 
            (entdel n)
          )
        )
      )
    )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #13
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    You did not answer if you can get a csv of all the points a dump of say the total station output. Much simpler way to approach.

  4. #14
    Member
    Join Date
    2020-04
    Posts
    11
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    Quote Originally Posted by BIG-AL View Post
    You did not answer if you can get a csv of all the points a dump of say the total station output. Much simpler way to approach.
    I used to get a csv file indeed, but it was too much work for me therefor I requested DWGs.
    when I used to get a csv I used to import it in excel, seperate the point goups (based on name), copy each group into a note bad and save it named after the point group. then go into autocad, creat a layer for same name import the TXT file through a plugin, and have the points in the drawing. from there draw the lines etc..

    it is a pain either way honestly, unless you have better ideas.

    - - - Updated - - -

    Quote Originally Posted by Opie View Post
    I concur with Tom on the Student Version drawings. However, you can still automate a lot of these steps.

    I would first create the template drawing containing this CROSS block used by your surveyor. In that template, modify the CROSS block to fit your desired output. I would add three ATTRIBUTE DEFINITIONS to the block with each mimicking the text provided by the surveyor in your desired height and the layer the text is currently on. For the HEIGHT attribute, I would add a block placeholder for the Z coordinate with the appropriate precision. For the CO_ORD attribute, I would do the same for the X and Y coordinates with similar precision. Once you have that you can continue to the automation.

    Using your template, INSERT and EXPLODE your surveyor's drawing. This will make your CROSS block take precedence over the surveyor's block. All of the surveyor's CROSS blocks will be rewritten to match your CROSS block definition. You would then use the ATTSYNC command to update the location labels for the block.

    Once the surveyor's drawing is inserted and exploded, you can use the SSGET AutoLISP function to create a selection set of different elements from the drawing by providing filters to the function. With this function, you can select elements from the entire drawing database. I would do this once for the ID text, and then once for all of the CROSS block INSERT locations.

    REPEATing through each selection set and append each element to a list. Properties of these elements that would be helpful could be the entity's handle (group code 5) and the insertion point of the block (group code 10) or the text attachment point (group code 11). Once you have two lists continue to the next step.

    Let's run through the list containing the TEXT elements. We can do this using the FOREACH AutoLISP function. Inside this FOREACH loop, let's run through the BLOCK element list using another FOREACH loop. Inside the BLOCK FOREACH loop, we need to compare the coordinates between the text and the block insertion point. Unfortunately, the coordinates do not exactly match, but are close. To get around this, we can use the EQUAL AutoLISP function with a fuzz factor. If the coordinates match, then do something.

    In this something branch of the IF statement, we should probably do a bunch of steps. To do that in an IF statement in AutoLISP, you would need to wrap all of those steps in a PROGN function. The first step in this group of steps in the true leg of the IF/PROGN statement, we should update the ID attribute of the CROSS block we created earlier. You can use PutBlkAttribute routine found in this post found in the forums here. This routine requires you to provide the block or entity. Here you could provide the entity name by retrieving it with the HANDENT AutoLISP function. We would get this from the current element being reviewed in the BLOCK FOREACH list. The other parameters of the PutBlkAttribute routine would be the attribute name we defined earlier, probably ID, and then the value of the attribute. That would be the text value (group code 1) of the current element being reviewed in the TEXT FOREACH list.

    The next step would be deleting the TEXT element from the text list. Doing so in the FOREACH loop may cause issues, therefore, I would recommend appending the handle of the TEXT element to a new list. We can then process this new list after we complete the attribute updating.

    Another step would be putting the block insertion on the layer you desired. We can evaluate the text value for the ID to either create or verify the desired layer exists. If the layer exists, then set the layer (group code for the block to the desired layer.

    You will probably be done with that group of FOREACH loops by now, so you could then delete the text using another FOREACH loop on the new list we created.

    Your code you posted earlier to draw lines could be modified to cycle through the layers and connected the insertion points of the blocks.


    Thank you for this. will have to read it few times to get my head around it, it is all new for me.
    will get back to you with comments for sure

  5. #15
    Member
    Join Date
    2020-04
    Posts
    11
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    Quote Originally Posted by Opie View Post
    I concur with Tom on the Student Version drawings. However, you can still automate a lot of these steps.

    I would first create the template drawing containing this CROSS block used by your surveyor. In that template, modify the CROSS block to fit your desired output. I would add three ATTRIBUTE DEFINITIONS to the block with each mimicking the text provided by the surveyor in your desired height and the layer the text is currently on. For the HEIGHT attribute, I would add a block placeholder for the Z coordinate with the appropriate precision. For the CO_ORD attribute, I would do the same for the X and Y coordinates with similar precision. Once you have that you can continue to the automation.

    Using your template, INSERT and EXPLODE your surveyor's drawing. This will make your CROSS block take precedence over the surveyor's block. All of the surveyor's CROSS blocks will be rewritten to match your CROSS block definition. You would then use the ATTSYNC command to update the location labels for the block.

    Once the surveyor's drawing is inserted and exploded, you can use the SSGET AutoLISP function to create a selection set of different elements from the drawing by providing filters to the function. With this function, you can select elements from the entire drawing database. I would do this once for the ID text, and then once for all of the CROSS block INSERT locations.

    REPEATing through each selection set and append each element to a list. Properties of these elements that would be helpful could be the entity's handle (group code 5) and the insertion point of the block (group code 10) or the text attachment point (group code 11). Once you have two lists continue to the next step.

    Let's run through the list containing the TEXT elements. We can do this using the FOREACH AutoLISP function. Inside this FOREACH loop, let's run through the BLOCK element list using another FOREACH loop. Inside the BLOCK FOREACH loop, we need to compare the coordinates between the text and the block insertion point. Unfortunately, the coordinates do not exactly match, but are close. To get around this, we can use the EQUAL AutoLISP function with a fuzz factor. If the coordinates match, then do something.

    In this something branch of the IF statement, we should probably do a bunch of steps. To do that in an IF statement in AutoLISP, you would need to wrap all of those steps in a PROGN function. The first step in this group of steps in the true leg of the IF/PROGN statement, we should update the ID attribute of the CROSS block we created earlier. You can use PutBlkAttribute routine found in this post found in the forums here. This routine requires you to provide the block or entity. Here you could provide the entity name by retrieving it with the HANDENT AutoLISP function. We would get this from the current element being reviewed in the BLOCK FOREACH list. The other parameters of the PutBlkAttribute routine would be the attribute name we defined earlier, probably ID, and then the value of the attribute. That would be the text value (group code 1) of the current element being reviewed in the TEXT FOREACH list.

    The next step would be deleting the TEXT element from the text list. Doing so in the FOREACH loop may cause issues, therefore, I would recommend appending the handle of the TEXT element to a new list. We can then process this new list after we complete the attribute updating.

    Another step would be putting the block insertion on the layer you desired. We can evaluate the text value for the ID to either create or verify the desired layer exists. If the layer exists, then set the layer (group code for the block to the desired layer.

    You will probably be done with that group of FOREACH loops by now, so you could then delete the text using another FOREACH loop on the new list we created.

    Your code you posted earlier to draw lines could be modified to cycle through the layers and connected the insertion points of the blocks.
    ok, so back at this.

    am not sure why you guys insist on the block issue. I am not sure but it seems extra steps.
    I mean, the point ID and the height is the only info I need on the drawing. the point it self is there only for indication.
    why do you feel it is necessary to recreate the block??
    also on the other hand I couldn't quiet understand the part of "correcting coordinates", honestly I am not keen on changing anything surveyed. it is a sensitive data and I use it as reference of photographer and ortho-rectification, I'd rather keep the survey as received.


    Let's assume two things:
    1- there is no blocks in the drawing at all
    2- there is no scaling text required
    how can we go from there into automating the process of grouping the selection based on point Id, and sorting the selection into separate layers, and then drawing the lines?

  6. #16
    Member
    Join Date
    2020-04
    Posts
    11
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    Quote Originally Posted by Opie View Post

    Your code you posted earlier to draw lines could be modified to cycle through the layers and connected the insertion points of the blocks.
    how can it be done?

  7. #17
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    Quote Originally Posted by majou789377 View Post
    Let's assume two things:
    1- there is no blocks in the drawing at all
    2- there is no scaling text required
    how can we go from there into automating the process of grouping the selection based on point Id, and sorting the selection into separate layers, and then drawing the lines?
    Replacing the block object for a point object loses data. Granted, the surveyor's block does not have all of the data attached to the block, but the block (from the surveyor) does have three out of the four elements of data. Redefining the block can allow you to contain the data in one element instead of four. The last element, the ID, can be attached to the block with the code provided yesterday. You cannot attach the point ID to the point object, unless you use either XDATA or Dictionaries or some other method I cannot think of at the moment. Neither of the first two are easily displayable.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #18
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    Quote Originally Posted by majou789377 View Post
    how can it be done?
    Let's get the first portion complete before moving on to later steps.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  9. #19
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    1

    Default Re: writing a LISP to automate daily practice

    Again having worked for way to many years with survey data, loading a csv through a package like CIV3D or Stringer by Civil Survey Solutions. Will do everything for you, create line work, add blocks eg tree, layer correctly. This task has been taken on since the 80's. Your reinventing the wheel.

    A civil/survey package has a Library it uses matching the descriptions. They do so much more as well.

    Again post a sample CSV if you have an old one and can see what can be done. It may be an advantage for your surveyor to have this software removing your tasks all together. You can download trials.

  10. #20
    Member
    Join Date
    2020-04
    Posts
    11
    Login to Give a bone
    0

    Default Re: writing a LISP to automate daily practice

    Quote Originally Posted by BIG-AL View Post
    Again having worked for way to many years with survey data, loading a csv through a package like CIV3D or Stringer by Civil Survey Solutions. Will do everything for you, create line work, add blocks eg tree, layer correctly. This task has been taken on since the 80's. Your reinventing the wheel.

    A civil/survey package has a Library it uses matching the descriptions. They do so much more as well.

    Again post a sample CSV if you have an old one and can see what can be done. It may be an advantage for your surveyor to have this software removing your tasks all together. You can download trials.
    Thank you for your reply.
    I am aware of the CIV3D, however it will not serve me for my job except for this tiny part of the work.
    therefor I have Autocad and Autocad Map 3D. and I need to get around the task by using the current resources available.

    - - - Updated - - -

    Quote Originally Posted by Opie View Post
    Replacing the block object for a point object loses data. Granted, the surveyor's block does not have all of the data attached to the block, but the block (from the surveyor) does have three out of the four elements of data. Redefining the block can allow you to contain the data in one element instead of four. The last element, the ID, can be attached to the block with the code provided yesterday. You cannot attach the point ID to the point object, unless you use either XDATA or Dictionaries or some other method I cannot think of at the moment. Neither of the first two are easily displayable.
    ok that is more clear now, I understand.

    can you please explain more about the part of redefining the block?, it didn't seem to work for me

Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. daily occurrence --> ADT2005 "re-install"
    By markjnstne in forum CAD Management - General
    Replies: 2
    Last Post: 2004-08-06, 04:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •