Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LISP/Script to select block by name and move to a specific layer

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
2310 Views, 3 Replies

LISP/Script to select block by name and move to a specific layer

Hello all,

 

I'm new to AutoCAD LISP commands.  I've come to learn and understand the basics, but I'm still learning the LISP functions and more detailed abilities.  Which is why I'm hoping someone can assist me with the following:

 

Is there a way to script a LISP/Script so that the first operation is to select only my block "Callout_Revision" and move it to the "Revision_Tags" layer without requiring my team or myself manually fixing the issue?

 

I'll begin with describing the thought behind the question.  There is a process I have developed that is a great way to manage revision clouds on shop drawings.  The block that identifies the revision number is on layer "Revision_Tag" while the cloud(s) are on layer "Revision_[X]" where [X] is the revision number for that cloud.  So when the enxt set of revisions need to be made, I run a script to turn off the previous revision layer to eliminate the human error in forgetting to delete/turn off the layer manually.  I keep the previous revision marks on the drawings for documentation purposes.  Also, it creates the next "Revision_[Y]" layer to again reduce human error; I keep track of revision numbers in an EXCEL spreadsheet, so there is no "Revision_[X+1]" in the script.  Then, the team and myself can copy the block for the revision number and change the attribute (no risk of human error since it's on "Revision_Tags" already).

 

However, I fear that one day soon, I will or one of my team will accidentally put the block on the same layer as the clouds.  Which will obviously be an issue when I run the script I described above.  I've tried to experiment with all the various "select" commands, but they all require the user to pick the object via mouse input (manual user input).

 

 

Thanks for your time all and hope this is clear,

 

LFrost

3 REPLIES 3
Message 2 of 4
hmsilva
in reply to: Anonymous

Welcome to the Autodesk Discussion Community, LFrost!

 

If I understood correctly, and as a starting point...
To select only your "Callout_Revision" block (if not a Dynamic one and have attributes), and move to the "Revision_Tags" layer

 

(defun c:demo (/ cly ent i lay ss)
  (if (setq ss (ssget "_X" (list '(0 . "INSERT") '(2 . "Callout_Revision") '(66 . 1))))
    (progn
      (setq cly (getvar 'CLAYER))
      (command "_.layer" "_U" "Revision_Tags" "_T" "Revision_Tags" "_M" "Revision_Tags" "")
      (repeat (setq i (sslength sS))
        (setq ent (entget (ssname ss (setq i (1- i))))
              lay (cdr (assoc 8 ent))
        )
        (if (/= lay "Revision_Tags")
          (entmod (subst (cons 8 "Revision_Tags") (assoc 8 ent) ent))
        )
      )
      (setvar 'CLAYER cly)
    )
    (prompt "\n \"Callout_Revision\" block not found! ")
  )
  (princ)
)

 

Hope that helps

Henrique

EESignature

Message 3 of 4
Anonymous
in reply to: hmsilva

Thank you so much hmsilva.  Works exactly as I intended!  Appreciate the help.

Message 4 of 4
hmsilva
in reply to: Anonymous

You're welcome, LFrost
Glad I could help

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost