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

LayCur to multiple objects

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
jjorovi
509 Views, 10 Replies

LayCur to multiple objects

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?

10 REPLIES 10
Message 2 of 11
_Tharwat
in reply to: jjorovi

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

 

can you explain your needs in more details ?

Message 3 of 11
Kent1Cooper
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, AIA
Message 4 of 11
jjorovi
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.

Message 5 of 11
jjorovi
in reply to: Kent1Cooper

This is the tool.
Excellent.
Thanks Kent. Smiley Happy

Message 6 of 11
_Tharwat
in reply to: jjorovi

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

Message 7 of 11
jjorovi
in reply to: _Tharwat

Good question.
Block layers do not change! Smiley Indifferent

Message 8 of 11
Kent1Cooper
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! Smiley Indifferent

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, AIA
Message 9 of 11
_Tharwat
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

Message 10 of 11
jjorovi
in reply to: _Tharwat

It works fine.
Tested also with layers in nested blocks.
Thanks to collaborate Tharwat Smiley Happy

Message 11 of 11
_Tharwat
in reply to: jjorovi


@jjorovi wrote:

It works fine.
Tested also with layers in nested blocks.
Thanks to collaborate Tharwat Smiley Happy



I am happy to hear that Smiley Very Happy

 

Enjoy ..

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

Post to forums  

Autodesk Design & Make Report

”Boost