Change block entities from layer zero to current.

Change block entities from layer zero to current.

flyinfool1
Explorer Explorer
659 Views
8 Replies
Message 1 of 9

Change block entities from layer zero to current.

flyinfool1
Explorer
Explorer

I need help making a Lisp to look at all blocks and nested blocks for entities that are on layer "0" and change them to the layer that the block is inserted on.

I can see where this will get messy as the same block name can be inserted on several different layers. It would need to have that block duplicated into new block names (maybe by adding a suffix to the block name?) so that the contents can be on the layer it is inserted on.

 

Yes I know this is exactly backwards from the normal and customary practice of putting the contents of a block on layer "0".

I will need to do this to well over 10,000 drawings and each drawing typically has around 200 different blocks to look at, so this is not realistically possible to do manually.

 

 

0 Likes
660 Views
8 Replies
Replies (8)
Message 2 of 9

Moshe-A
Mentor
Mentor

@flyinfool1  hi,

 

The question is why would you want to to that???

a block contains objects on layer 0 at insert are moved (inherit) to the inserted layer. the only reason to to what you are asking is that the blocks are not inserted on the layer they should - am i right?

 

Moshe

 

 

0 Likes
Message 3 of 9

flyinfool1
Explorer
Explorer

Please don't shoot the messenger. I fully understand the purpose of layer "0". The owner of the company has decreed that this is the way he wants it done in his company. Years of many people trying to teach him the right way have failed, people have been let go for insisting things be done "right". He is the one that signs my check. This is not immoral, illegal or unsafe, so I will try to find a way to comply. 

0 Likes
Message 4 of 9

Kent1Cooper
Consultant
Consultant

@flyinfool1 wrote:

.... I can see where this will get messy as the same block name can be inserted on several different layers. It would need to have that block duplicated into new block names (maybe by adding a suffix to the block name?) so that the contents can be on the layer it is inserted on. ....


As to that, you may be able to use BlockDupNewName.lsp with its BDN command, >here<.  It does just that -- adds a hyphen-and-number suffix to the name to offer you as default, allowing you to further edit it if you want, and makes a new Block with the new name out of the pieces of the selected Block, incrementing the number part if another Insertion of the same source Block is selected.  That could possibly be automated over a drawing-full of Blocks, including changing the Layer of the Layer-0 pieces in each as it goes, but first see whether it does what you want to an individual Block.

Kent Cooper, AIA
Message 5 of 9

yael
Participant
Participant

@flyinfool1 ,

 


@flyinfool1 wrote:

Please don't shoot the messenger. I fully understand the purpose of layer "0". The owner of the company has decreed that this is the way he wants it done in his company. Years of many people trying to teach him the right way have failed, people have been let go for insisting things be done "right". He is the one that signs my check. This is not immoral, illegal or unsafe, so I will try to find a way to comply. 


to that explantion the boss wins 🤣

Message 6 of 9

paullimapa
Mentor
Mentor

I hope you don’t end up being the guy who also have to modify these drawings with blocks that may look the same but are all different. 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 9

flyinfool1
Explorer
Explorer

Yes I will be one of the guys that will have to work in the ensuing quagmire.

I do have a lisp that I use to convert all the entities in a block to the current layer, but it requires selecting each block one by one.

@Kent1Copper

I did some playing with the BDN command. It looks that will work to create the new block with a suffix. I am working on how to add my list from below into the BDN. I am very old school I don't get all of the newer VLA- commands.

(defun c:fb (/ block bname)
(setq block (ssget "_+.:E:S" '((0 . "INSERT")))) ;; select single entity, for multiple selection its too slow anyway
(setq currentlayer (getvar "clayer"))
(setq bname (cdr (assoc 2 (entget(ssname block 0))))) ;; index forgotten , 0 is the first
(command "-bedit" bname )
(command "change" "all" "" "p" "la" currentlayer "")
; (command "setbylayer" "all" "" "yes" "yes")
(command "_.bclose" "_save") ;; close the editor
(princ)
)

(vl-load-com)
(prompt "\nType FB to set all entities in a block to the current layer.")

I am not good enough with lisp to make this run on all of the blocks in a drawing instead of just one at a time, and it will not look into nested blocks.

0 Likes
Message 8 of 9

paullimapa
Mentor
Mentor

I feel for you man...but I can see it now...your boss will complain why it takes you hours to change one simple thing and unfortunately, you cannot tell him that it's his fault.


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 9 of 9

ronjonp
Mentor
Mentor

@flyinfool1 wrote:

Please don't shoot the messenger. I fully understand the purpose of layer "0". The owner of the company has decreed that this is the way he wants it done in his company. Years of many people trying to teach him the right way have failed, people have been let go for insisting things be done "right". He is the one that signs my check. This is not immoral, illegal or unsafe, so I will try to find a way to comply. 


Ouch! Sounds like your boss needs to hire a seasoned CAD Manager. Does he/she realize that this "standard" defeats the purpose of a block definition? A group of objects that can be defined and or changed in one place that is reflected throughout the drawing. You might as well as explode all the blocks. ( this is assuming you have the same block on many different layers ... not too logical but neither is this request) 😄

 

And you should probably post a sample drawing so the takers of the challenge have an idea of the complexity of the problem.

 

0 Likes