Jump to content
mugshot

Copy layer from block

Recommended Posts

mugshot

Hello guys...

 

Is there any lisp that i could copy the layer inside a block straight away? Like i dont have to go inside the block, copy then match prop... Or explode the object. The reason is at least skip some steps😀... I did ask in general but i was instructed to ask in this section.

 

Thanks in advance, cheers!

Share this post


Link to post
Share on other sites
dlanorh

Post an example block in ACAD2010 version. It's relatively easy to get an object inside a block using (nentsel), get its layer property then assiugn that to another object.

Share this post


Link to post
Share on other sites
Emmanuel Delay

Does this help? 

You get to select a subentity (with nentsel), it reads its layer, then sets that layer as current layer.

 

Do you also need the color and linetype ... ?

 


;; Select Layer Inside Block
(defun c:slib ( / lay)
  (setq lay (cdr (assoc 8 (entget (car (nentsel "\nSelect subentity: "))))))
  (setvar 'clayer lay)
  (princ)
)

Share this post


Link to post
Share on other sites
Lee Mac

If I've understood correctly, it sounds like the OP is describing NCOPY for all objects residing on a particular layer within a block.

Share this post


Link to post
Share on other sites
Jef!

If I've understood correctly, the OP want to matchprop only the layer of other objects using a block sub entity as the source....

(defun c:lnmp ( / ent source sel)
  (if (and (setq ent (car (nentsel "\nSelect subentity: ")))
        (setq source (cdr (assoc 8 (entget ent))))
      )
      (while (setq sel (ssget))
        (mapcar '(lambda (x)
            (vla-put-layer (vlax-ename->vla-object x) source)
                )
           (vl-remove-if 'listp (mapcar 'cadr (ssnamex sel)))
        )
      )
  )
  (princ)
)

 

Edited by Jef!

Share this post


Link to post
Share on other sites
Tharwat

@Jef! Your 'IF' function is useless in this case so try to select nothing to know why.

Share this post


Link to post
Share on other sites
Jef!

@Tharwat You are totally right on the if not doing its job. No riddles here :)

I was in a hurry so I just played it slacker on that one. Half question, half working half code (and half time wasted!). The final princ was also missing. I corrected it anyway. Now I'd bet a cold one on it that the next post will be "That is not what I need." Anyone? :D

 

Share this post


Link to post
Share on other sites
mugshot

Thanks guys for the effort.. greatly appreciated, as in a lot. This will save my time at work...😊

...and may i add, or alter, if it possible to copy the layer at the same time the color? What i saw is that it corresponds to the layer, but not the color, (say layer zero but has a color green) like that...🤔

Thanks again...

Share this post


Link to post
Share on other sites
eldon

I know that you want this done by lisp, but did you ever try inserting the block into your drawing and then erasing it? All the block layers appear in the drawing, complete with colour and linetype.

Share this post


Link to post
Share on other sites
Emmanuel Delay

I expanded it to layer, color, linetype, line weight

 


;; Select Layer Inside Block
(defun c:slib ( / ent lay col ltp lwght)
  (setq ent (entget (car (nentsel "\nSelect subentity: "))))
 
  (setq lay (cdr (assoc 8  ent)))  ;; layer
  (setq col (cdr (assoc 62 ent)))  ;; color
  (setq ltp (cdr (assoc 6  ent)))  ;; line type
  (setq lwght (cdr (assoc 370 ent)))  ;; line weight

  (setvar 'clayer lay)
  ;; note: color, linetype, line weight might not be set if the subentity was on "ByLayer"
  ;;           in that case we force it (and reset it) to "ByLayer"
  (if col
    (setvar 'cecolor (itoa col))
    (setvar 'cecolor "BYLAYER")
  )
  (if ltp
    (setvar 'celtype ltp)
    (setvar 'celtype "BYLAYER")
  )
  (if (= nil lwght)
    (setvar 'celweight -1)  ;; -1 = "ByLayer"
    (setvar 'celweight lwght)
  )
  (princ)
)

Share this post


Link to post
Share on other sites
mugshot
1 hour ago, eldon said:

I know that you want this done by lisp, but did you ever try inserting the block into your drawing and then erasing it? All the block layers appear in the drawing, complete with colour and linetype.

Yes sir. The thing is we used dynamic block... In extend are object, sort like that. Actually there are plenty of procedure, to which i want to skip those...maybe u can call me lazy bum..🤣🤣🤣.

Share this post


Link to post
Share on other sites
mugshot

@Emmanuel sir... Thanks for the lisp... Greatly appreciated... This will help me work fast...(office requirement😵)  and ill use this to my other project as well... This is a weird process but it help me a lot... Maybe to others as well.

 

Kind regards... Cheers🍻

  • Like 1

Share this post


Link to post
Share on other sites
mugshot

@Emmanuel sir, is the second lisp does force to make layer to be default, then thats stops?🤔 I think the first works fine, because from source/entity to object, the second was nice too but theres no application to object from source.😬😬😬

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×