Insert block on current layer

Insert block on current layer

David_Prontnicki
Collaborator Collaborator
1,266 Views
9 Replies
Message 1 of 10

Insert block on current layer

David_Prontnicki
Collaborator
Collaborator

Hi,

I have the lisp below to insert a symbol, what I cant figure out is how to get the block to insert on whatever the current layer is. Currently it comes in on the layer of the block. I would like to leave all blocks on layer 0 (Zero) in their respective drawings, and have them insert in working drawing on whatever the current layer is set to.

 

(defun c:symbolsevergreens ()
  (command "insert" "PATH/Evergreens.dwg" (getpoint "\nSelect insertion point: ")
    "1" "1" "0" ) (command "explode" "last")
  (princ)
)

Any help would be greatly appreciated. 

0 Likes
Accepted solutions (1)
1,267 Views
9 Replies
Replies (9)
Message 2 of 10

ВeekeeCZ
Consultant
Consultant
Accepted solution

@David_Prontnicki wrote:

Hi,

I have the lisp below to insert a symbol, what I cant figure out is how to get the block to insert on whatever the current layer is. Currently it comes in on the layer of the block. I would like to leave all blocks on layer 0 (Zero) in their respective drawings, and have them insert in working drawing on whatever the current layer is set to.

 

(defun c:symbolsevergreens ()
  (command "insert" "PATH/Evergreens.dwg" (getpoint "\nSelect insertion point: ") "1" "1" "0" ) 
  (command "_.chprop" "_L" "" "_Layer" (getvar 'clayer) "") 
  (command "explode" "last")
  (command "_.chprop" "_P" "" "_Layer" (getvar 'clayer) "") 
  (princ)
)

Any help would be greatly appreciated. 


 Probably the blue one.

0 Likes
Message 3 of 10

David_Prontnicki
Collaborator
Collaborator

Thank you BeeKeeCZ,

 

I was close, I had tried that but my syntax was off. Was using "LAST" instead of "_L". 

Also I had to change the order of operations. I had to move the change prop AFTER the EXPLODE. Not exactly sure why but I think it has to do with the explode. they explode to layer 0 so...

 

Edit: I just saw that you said prob blue one. It's been one of those days. 🙂 Any benefit to using _P vs. _L?

 

(defun c:symbolsevergreens ()
  (command "insert" "PATH/Evergreens.dwg" (getpoint "\nSelect insertion point: ") "1" "1" "0" ) 
(command "explode" "last")
(command "_.chprop" "_L" "" "_Layer" (getvar 'clayer) "")
  (princ)
)

This seems to work. Do you see anything wrong with this, any potential issues?

0 Likes
Message 4 of 10

ВeekeeCZ
Consultant
Consultant

Yes, I found it too - and edited.

I didn't know how many objects you have within the file. Change the letter if you have more than one object inside, from _L (or your Last) to _P as previous.

 

Also your first line could be changed to:

(command "insert" "PATH/Evergreens.dwg" PAUSE 1 1 0)
0 Likes
Message 5 of 10

David_Prontnicki
Collaborator
Collaborator

So if I'm understanding you correctly if my "Evergreen.dwg" drawing file that I am inserting only has one (1) item use "_L". If it has multiple items use "_P".

 

So I am inserting a single dynamic block, the evergreen.dwg has one dynamic block in it so i will be using "_L", correct?

 

Thank you!

0 Likes
Message 6 of 10

Kent1Cooper
Consultant
Consultant

@David_Prontnicki wrote:

So if I'm understanding you correctly if my "Evergreen.dwg" drawing file that I am inserting only has one (1) item use "_L". If it has multiple items use "_P".

 

So I am inserting a single dynamic block, the evergreen.dwg has one dynamic block in it so i will be using "_L", correct?

 

Thank you!


 

I would use P in any case.  Whenever you EXPLODE something, the resulting pieces, however many there are, become the Previous selection set, so P would cover any possible number of pieces in whatever is EXPLODEd, and you wouldn't have to re-write the routine if you changed the contents of the Inserted drawing to more than one thing.

Kent Cooper, AIA
0 Likes
Message 7 of 10

ВeekeeCZ
Consultant
Consultant

First of all, you should export your dynblock using the WBLOCK command. That way you won't have a block within a file, that inserted is a block within a block which has to be exploded. If you use wblock, that way is would be just a geometry inside a file. That inserted will be just a block without a need be exploded.

0 Likes
Message 8 of 10

David_Prontnicki
Collaborator
Collaborator

That makes a lot of sense. Thank you!

0 Likes
Message 9 of 10

David_Prontnicki
Collaborator
Collaborator

That also makes a lot of sense. Thank you!

0 Likes
Message 10 of 10

ВeekeeCZ
Consultant
Consultant

@David_Prontnicki wrote:

That also makes a lot of sense. Thank you!


 

...but if you redefine your block/file, then you find that "_P" is not working for your Layer change. You will need to get "_L" back 😉

0 Likes