• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Visual LISP, AutoLISP and General Customization

    Reply
    Active Contributor
    Posts: 49
    Registered: ‎06-15-2012
    Accepted Solution

    LayCur to multiple objects

    171 Views, 10 Replies
    09-18-2012 11:18 AM

    Hi all!
    Is there any way to use the command "LAYCUR" to change all objects that are in the same layer?
    With a lisp, maybe?

    Please use plain text.
    Valued Mentor
    _Tharwat
    Posts: 468
    Registered: ‎07-02-2010

    Re: LayCur to multiple objects

    09-18-2012 11:56 AM in reply to: jjorovi

    Your question is not clear enough , or at least to me .

     

    can you explain your needs in more details ?

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,163
    Registered: ‎09-13-2004

    Re: LayCur to multiple objects

    09-18-2012 12:12 PM in reply to: jjorovi

    jjorovi wrote:

    ....Is there any way to use the command "LAYCUR" to change all objects that are in the same layer?....


    Here's one way to do the equivalent [without using LAYCUR itself]:

     

    (defun C:LAYMRGC (/ lay clay layss edata); = LAYer MeRGe into Current layer
      (setq
        lay (cdr (assoc 8 (entget (car (entsel "\nSelect object on Layer to Merge into Current Layer: ")))))
        clay (getvar 'clayer)
        layss (ssget "_X" (list (cons 8 lay)))
      ); setq
      (repeat (sslength layss)
        (setq edata (entget (ssname layss 0)))
        (entmod (subst (cons 8 clay) (assoc 8 edata) edata))
        (ssdel (ssname layss 0) layss)
      ); repeat
    ); defun

     

    If you don't need that "same layer" to remain in the drawing afterwards, you can just use LAYMRG to merge it into the current layer, but that would require you to either pick something on the current Layer for the Layer to Merge into, or use the Type-it option and type in the name of the current Layer.

     

    It could also be set up to ask the User to enter a Layer name instead select something [which would mean you could do it even with nothing on that Layer visible], and no doubt in some other variants.

     

    And to be more exactly like LAYMRG except for the built-in current-Layer part, it could be made to purge the other Layer, which the above doesn't do.  But that wouldn't work anyway if there are, for example, things on that Layer that are parts of Block definitions -- LAYMRG would take care of those, too.

     

    Another approach would be to use Qselect to find everything on a Layer, and when it has made its selection and has it highlighted/gripped, type LAYCUR.  But I don't think that would change things in all spaces/tabs, as the above would.

    Kent Cooper
    Please use plain text.
    Active Contributor
    Posts: 49
    Registered: ‎06-15-2012

    Re: LayCur to multiple objects

    09-18-2012 12:16 PM in reply to: _Tharwat

    If I have multiple objects on a specific layer and I want pass it to the current layer, use the command "laycur", but I want all objects belonging to that layer, change to the current layer.
    More simple. Change objects to one layer to the other very quickly.

    Thanks to response, Tharwat.

    Please use plain text.
    Active Contributor
    Posts: 49
    Registered: ‎06-15-2012

    Re: LayCur to multiple objects

    09-18-2012 12:22 PM in reply to: Kent1Cooper

    This is the tool.
    Excellent.
    Thanks Kent. :smileyhappy:

    Please use plain text.
    Valued Mentor
    _Tharwat
    Posts: 468
    Registered: ‎07-02-2010

    Re: LayCur to multiple objects

    09-18-2012 12:24 PM in reply to: jjorovi

    What's if one of these selected objects' layers is existed in a block ?

    Please use plain text.
    Active Contributor
    Posts: 49
    Registered: ‎06-15-2012

    Re: LayCur to multiple objects

    09-18-2012 12:32 PM in reply to: _Tharwat

    Good question.
    Block layers do not change! :smileyindifferent:

    Please use plain text.
    *Expert Elite*
    Kent1Cooper
    Posts: 4,163
    Registered: ‎09-13-2004

    Re: LayCur to multiple objects

    09-18-2012 12:48 PM in reply to: jjorovi

    _Tharwat wrote:

    What's if one of these selected objects' layers is existed in a block ?

     

    jjorovi wrote:
    Good question.
    Block layers do not change! :smileyindifferent:

    That's where LAYMRG does the most good [see the comments in my earlier post].  If you wanted to do that programmatically, I guess it would be possible, but it would require opening up every Block definition in the table, stepping through all the elements in each one, and changing the Layer of anything on the selected Layer.
     

    Unfortunately, LAYMRG isn't a native AutoCAD Command, so you can't use it in a (command) function and feed in answers to its prompts.  There may be some equivalent way to make use of it, but I don't know how [maybe a Search of the Discussion Group would find something...].

    Kent Cooper
    Please use plain text.
    Valued Mentor
    _Tharwat
    Posts: 468
    Registered: ‎07-02-2010

    Re: LayCur to multiple objects

    09-18-2012 01:22 PM in reply to: jjorovi

    Try this please , and let me know your opinion .

     

    (defun c:Test (/ ss cl i e lys lst sel in sel ent l)
      (vl-load-com)
      ;;; 		Tharwat 19. September. 2012  		;;;
      ;;; 	This routine would change the layer of		;;;
      ;;;	 the selected objects to the current layer	;;;
      ;;; 		including all blocks 			;;;
      (if (not acdoc)
        (setq acdoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (if (setq ss (ssget "_:L"))
        (progn
          (repeat (setq i (sslength ss))
            (setq e (entget (ssname ss (setq i (1- i)))))
            (if (not (member (cdr (assoc 8 e)) lst))
              (setq lst (cons (cdr (assoc 8 e)) lst))
            )
          )
          (foreach x lst (setq l (cons (strcat x ",") l)))
          (setq lys (apply 'strcat l))
          (setq cl (getvar 'clayer))
          (if (setq
                sel (ssget "_x"
                           (list (cons 8 (vl-string-right-trim "," lys)))
                    )
              )
            (repeat (setq in (sslength sel))
              (setq ent (entget (ssname sel (setq in (1- in)))))
              (entmod (subst (cons 8 cl) (assoc 8 ent) ent))
            )
          )
          (vlax-for block (vla-get-blocks
                            acdoc
                          )
            (if (and (eq :vlax-false (vla-get-isXref block))
                     (eq :vlax-false (vla-get-islayout block))
                )
              (vlax-for entity block
                (if (member (vla-get-layer entity) lst)
                  (vla-put-layer entity cl)
                )
              )
            )
          )
        )
      )
      (vla-regen acdoc AcAllviewports)
      (princ)
    )

     

    Tharwat

    Please use plain text.
    Active Contributor
    Posts: 49
    Registered: ‎06-15-2012

    Re: LayCur to multiple objects

    09-19-2012 07:44 AM in reply to: _Tharwat

    It works fine.
    Tested also with layers in nested blocks.
    Thanks to collaborate Tharwat :smileyhappy:

    Please use plain text.