Jump to content

Copy layer from block


mugshot

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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!
Link to comment
Share on other sites

@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

 

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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..🤣🤣🤣.

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

@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.😬😬😬

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...