Jump to content

Layer Lisp


jaylo23

Recommended Posts

Hello and good morning to all (and good afternoon to others). Did a search and could not find what i was looking for so i apologize if this has already been asked but here goes...Looking for a lisp that would prompt the user to select objects, after objects are selected the lisp would take the layers of the selected objects and add "_EX" to the end of the layer name and change the layer color to green. The problem i have is that i have a bunch of equipment xrefs that were modeled using layers such as "eq-bdy" and now need to be shown as existing in our models which is where the "_EX" comes in. Also would like the lisp to ignore entities that are on layer 0 and defpoints if possible. Again i apologize if this has already been discussed and if so please point me in the right direction. Thanks in advance to all.

Link to comment
Share on other sites

  • Replies 105
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    41

  • alanjt

    30

  • JeepMaster

    15

  • kalarpu

    11

I doubt you'll find a generic routine that will do exactly what you want. You'll have to find and then modify an existing custom Lisp routine or write a new one.

Link to comment
Share on other sites

Will this work for you? Just copy paste to test quickly:

 

 

(defun c:LM() ;modfy name as you like, LM is fast to type
   (command "laymcur" pause) ;set current layer by selecting object
   (command "layer" "m" (strcat(getvar "clayer") "_EX") "color" "green" " " " ")
   (princ)
)

Link to comment
Share on other sites

Will this work for you? Just copy paste to test quickly:

 

 

It seems to be kinda close to what im looking for. It doesnt put the entities on the newly created layers and gives me an error when exiting it. It also doesnt ignore layer 0 but i think i could just write in the lisp to freeze layer 0 and defpoints at the begining and thaw those layers afterwards. But this is alot better than anything i could come up with thanks.

Link to comment
Share on other sites

I had a go at it, but I don't think I have the knowledge in LISP to accomplish it.

 

I tried modifying it like this:

 

(defun c:sel (/ ent lay lay1)
   (setq ent (car entsel))
   (setq lay (cdr (assoc 8 (entget ent))))
   (setq lay1 (tblsearch "layer" lay))
   (setq lay1 (subst (cons 2 (strcat lay "_EX")) (assoc 2 lay1) lay1))
   (entmod lay1)
   (princ)
) ;_  end defun

 

But to no avail.

Link to comment
Share on other sites

Thanks anyways for your attempt Lee Mac. Anyone, Would it possible to create an table from the selected objects and maybe use the rename command to put "_EX" at the end of all the layers? Maybe im shooting in the dark!

Link to comment
Share on other sites

how about this:

wrote it real quick, tested it once.

(defun c:layex ( / ssobjlist ss_obj ss_obj_list obj )
;;;;;SUBROUTINES;;;;;
(defun ssobjlist (sset / zaehler objlist) 
 (setq zaehler (1- (sslength sset)))
 (while (>= zaehler 0)
   (if (< zaehler (1- (sslength sset)))
     (setq objlist (cons (ssname sset zaehler) objlist))
     (setq objlist (list (ssname sset zaehler)))
   ) ;Ende if
   (setq zaehler (1- zaehler))
 ) ;Ende While
 objlist
) ;Ende defun

;;;;;MAIN ROUTINE;;;;;
(setq ss_obj (ssget "_:L" '((-4 . "<not")(8 . "0,Defpoints")(-4 . "not>"))))
(if ss_obj
 (progn
  (command "_.undo" "_begin")
  (setq ss_obj_list (ssobjlist ss_obj))
  (foreach obj ss_obj_list
   (setq obj_lay (cdr (assoc 8 (entget obj))))
   (if (not (wcmatch obj_lay "*_EX"))
    (progn
     (command "_.rename" "_la" obj_lay (strcat obj_lay "_EX"))
     (command "_.layer" "_co" 3 (strcat obj_lay "_EX") "")
     (princ (strcat "\nLayer \"" obj_lay "\" rename to: \"" obj_lay "_EX\""))
    );progn
   );if
  );foreach
  (command "_.undo" "_end")
 );progn
 (princ "\nNothing selected, try again")
);if
(princ)
);defun

Link to comment
Share on other sites

That worked great Alan!!!! Many thanks to you and am extremely grateful (so our my CAD operators when they find out about this one). You have made my work month soooooo much better! I gotta about 1000 equipment blocks to use this on! Again, thank you sir!

Link to comment
Share on other sites

By the way, one question:

 

what is the purpose of the "undo" "begin" and "undo" "end"?

 

to combine all the changes into 1 undo mark. if it wasn't there and you decided to undo after selecting 10 items, you would have to undo twice for each item. this way it can be undone with just one "u"

Link to comment
Share on other sites

Ahhh, that makes sense. Thanks.

 

Oh, and sorry to bother you further, but I am not sure of this line:

 

(ssget "_:L" '((-4 . "<not")(8 . "0,Defpoints")(-4 . "not>"))))

 

I understand you are retrieving a selection set that you later convert into a list using your subroutine, but after looking into the ACAD help, I do not see an ssget "_:L" and I don't understand how the (-4 . "

 

Also, Just out of interest, is there a way to modify tblsearch entities and update them the way one would with normal DXF tables retrieved via entsel? i.e., is there a way of accomplishing a change of layer name without going into (command "_rename")?

Link to comment
Share on other sites

ssget "_:L" >>> rejects locked layers

 

(-4 . ">> think of this as an open parenthesis which needs a closing of (-4 . "not>")

Also, Just out of interest, is there a way to modify tblsearch entities and update them the way one would with normal DXF tables retrieved via entsel? i.e., is there a way of accomplishing a change of layer name without going into (command "_rename")?

 

lee try (tblnext "LAYER"), i think you know the next steps.....:-)

Link to comment
Share on other sites

Thanks for your help Wizman, those explanations are pretty good. (so the (-4 . "

 

 

As for this:

 

lee try (tblnext "LAYER"), i think you know the next steps.....:-)

 

in an earlier post, I tried this:

 

(defun c:sel (/ ent lay lay1)
   (setq ent (car entsel))
   (setq lay (cdr (assoc 8 (entget ent))))
   (setq lay1 (tblsearch "layer" lay))
   (setq lay1 (subst (cons 2 (strcat lay "_EX")) (assoc 2 lay1) lay1))
   (entmod lay1)
   (princ)
) ;_  end defun

It altered the table entry, but didn't change the layer name.. not sure why?

 

Thanks again for all your help. :)

Link to comment
Share on other sites

Lee, i should have said TBLOBJNAME, sorry for confusing:

 

(defun c:sel (/ ent lay lay1)
   (setq ent (car (entsel)))
   (setq lay (cdr (assoc 8 (entget ent))))
   (setq lay1 (tblsearch "layer" lay))
   (setq lay1 (subst (cons 2 (strcat lay "_ex"))
	      (assoc 2 (entget (tblobjname "layer" lay)))
	      (entget (tblobjname "layer" lay))
       ) ;_ end_subst
   ) ;_ end_setq
   (entmod lay1)
   (princ)
) ;_ end_defun

Link to comment
Share on other sites

Superb Wizman, works a treat.

 

I always like to break the LISP down to the tbl definitions, instead of just using the in built ACAD commands, like rename. I suppose it means more typing, but I understand the LISP better that way.

 

tblobjname - yet another tool at my disposal - many thanks :)

Link to comment
Share on other sites

  • 8 months later...

Hi

If I want to add _EX only when I select standard layer which is 14 characters (example "A-_1234----_E-"),how to do? And if less than or excess 14 please pop up note (Your layer "----" is not a standard layer format), how to?

Thanks a lot!

 

Kalarpu:roll:

Link to comment
Share on other sites

Blimey, this is an old thread... brings back some memories - I've come a long way since then!

 

Try this:

 

(defun c:lay (/ ent Nme)
 (vl-load-com)
 (while (setq ent (car (entsel "\nSelect Object on Layer: ")))
   (setq Nme (cdr (assoc 8 (entget ent))))
   (if (= 14 (strlen Nme))
     (vla-put-Name
       (vla-item
         (vla-get-Layers
           (vla-get-ActiveDocument
             (vlax-get-acad-object))) Nme)
       (strcat Nme "_EX"))
     (princ (strcat "\n<< Layer: " Nme " is not Standard Format >>"))))
 (princ))
   

Link to comment
Share on other sites

Hi

If I want to add _EX only when I select standard layer which is 14 characters (example "A-_1234----_E-"),how to do? And if less than or excess 14 please pop up note (Your layer "----" is not a standard layer format), how to?

Thanks a lot!

 

Kalarpu:roll:

(and (= (strlen "LAYERNAME") 14)
    (wcmatch "LAYERNAME" "[AECMV ]-*")
    )

 

 

this would make sure the layername is 14 characters long and has a prefix of "A-", "E-", "C-", "M-" or "V-" (couldn't remember all of them).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...