hpimprint Posted July 22, 2021 Share Posted July 22, 2021 (edited) Lisp to change layer to nest objects inside block , putting them on block layer I have blocks in some layers. But lines inside every block can be on other different layers. I need a lisp to move all those "wrong layer" lines on the same layer of block they are inside. example with 4 blocks (see attached .DWG): 1st block on Layer "B1" but inside block lines are in Layer "C" 2nd block on Layer "B1" but inside block lines are in Layer "D" 3rd block on Layer "B2" but inside block lines are in Layer "E" 4th block on Layer "B2" but inside block lines are in Layer "F" what i need: 1st block and all lines inside block are in Layer "B1" 2nd block and all lines inside block are in Layer "B1" 3rd block and all lines inside block are in Layer "B2" 4th block and all lines inside block are in Layer "B2" (!!!) Warning: i need to do it on maaAAAaany blocks so i need a lisp that automatically change every block content without selecting every block by hand, one by one. can you help me? test2.zip Edited July 22, 2021 by hpimprint Quote Link to comment Share on other sites More sharing options...
tombu Posted July 22, 2021 Share Posted July 22, 2021 Your blocks are a mess but fixing them correctly is much simpler than how you've described. As long as all the objects that make up a block are drawn on layer 0 with their properties set to ByBlock all those default properties will be from the layer the block is on or moved to. You can even change any of those properties set as ByBlock with the Properties Palette. This lisp by Peter Jamtgaard will set all block objects to Layer 0 with Color, Linetype, Lineweight, and PlotStyleName properties to ByBlock. ; Written By: Peter Jamtgaard 12/20/2006 ;^P(or C:BlkByBlock (load "BlkByBlock.lsp"));BlkByBlock (defun C:BlkByBlock (/ colBlockReference ActDoc dprSelection objSelection strBlockName ) (if (setq dprSelection (entsel "\nSelect Block: ")) (progn (setq ActDoc (vla-get-ActiveDocument (vlax-get-Acad-Object)) dprSelection (car dprSelection) objSelection (vlax-ename->vla-object dprSelection) ) (vla-StartUndoMark ActDoc) (BlkByBlock objSelection) (entupd dprSelection) (vla-EndUndoMark ActDoc) ) ) (prin1) ) (defun BlkByBlock (objSelection / colBlockReference objBlock strBlockName ) (if (= (type objSelection) 'ENAME) (setq objSelection (vlax-ename->vla-object objSelection))) (if (wcmatch (strcase (vla-get-objectname objSelection)) "*BLOCK*") (progn (vlax-for objBlock (vla-item (vla-get-blocks ActDoc) (vla-get-name objSelection) ) (vla-put-Color objBlock 0) (vla-put-Layer objBlock "0") (vla-put-linetype objBlock "ByBlock") (vla-put-Lineweight objBlock -1) (vla-put-PlotStyleName objBlock "ByBlock") ) ) ) (prin1) ) (prin1) If you plot using a CTB instead of a STB you can put a semicolon (;) in front of the line (vla-put-PlotStyleName objBlock "ByBlock"). Quote Link to comment Share on other sites More sharing options...
hpimprint Posted July 22, 2021 Author Share Posted July 22, 2021 (edited) <<This lisp by Peter Jamtgaard will set all block objects to Layer 0>> thank you. but i can't move all blocks (and nested items) to the same layer (example: layer0). èrreason: every block has a layer name describing something and i can lose this information). I need every block to mantain its original layer. and all nested objects to adopt the layer of the block they own. more: if i want to hide only blocks on layer "B1"(i refer to attached .dwg), i disable layer B1 and two blocks will disappear with their nested contents. with your solution if i disable layer "0" all blocks will disappear and there will be no way to hide only blocks in layer "B1" including thei content. your solution works but ONLY if main block mantain original layer and ONLY nested objects change to "by block" and "layer 0". so: how can i change these 2 parameters only for things inside blocks (the nested things) leaving the blocks unchanged? here attached i changed by hand: now all nested are on layer0 and "by block". if you hide layer "B1" 2 blocks will disappear with their content. 1809750770_testnestedlayer0byblock.dwg Edited July 22, 2021 by hpimprint Quote Link to comment Share on other sites More sharing options...
tombu Posted July 22, 2021 Share Posted July 22, 2021 6 minutes ago, hpimprint said: <<This lisp by Peter Jamtgaard will set all block objects to Layer 0>> thank you. but i can't move all blocks (and nested items) to the same layer (example: layer0). èrreason: every block has a layer name describing something and i can lose this information). I need every block to maintain its original layer. and all nested objects to adopt the layer of the block they own. Moving the objects that make up a block doesn't change the layer the block is on it. It simply provides you with ultimate control over the blocks properties. Links that explain ByBlock: https://www.cad-notes.com/layer-0-bylayer-and-byblock/ https://govdesignhub.com/2019/02/05/more-autocad-layer-tips-and-tricks-for-maximum-productivity/#.YPleQOhKghQ Save a copy of your drawing and test it out. Each of the blocks will reflect the properties of any layer you put or move them to unless you set their properties to something else. As an example we use the same blocks for proposed and existing but the existing blocks are all shaded out with hidden linetype because of the layer they're inserted on. Quote Link to comment Share on other sites More sharing options...
hpimprint Posted July 22, 2021 Author Share Posted July 22, 2021 (edited) but as i see: i can't hide a block with its nested content unless the nested contents aren't on layer 0 (and "by block"?). changing nested contents to "by layer" don't let me to hide them together with the block that contains them. how can i move only all nested objects to "layer0" and "by block"? Edited July 22, 2021 by hpimprint Quote Link to comment Share on other sites More sharing options...
tombu Posted July 22, 2021 Share Posted July 22, 2021 AutoCAD Help - Block Object Properties Reference https://help.autodesk.com/view/ACD/2022/ENU/?guid=GUID-25E9F20C-D146-426C-8815-37DF48D2D33F Right now if you draw a line with all it's properties ByLayer it will have the properties of the layer it's on unless you change any of those properties like color or linetype. Your blocks can be set to behave the same way. If all the nested content of a block is set ByBlock it takes on the properties of the block. Freeze the layer the block is inserted on and it disappears same as the line would. Move it to a different layer and it will be the color, linetype, and lineweight of that layer same as the line would. Change the color of the block and it's that color. The only thing that works different is that turning of the block's layer doesn't make it disappear like the line would but freeze and VPfreeze work fine. Save a copy of your drawing and see if the lisp does what you need. If not reply back about what changes you need. Quote Link to comment Share on other sites More sharing options...
hpimprint Posted July 23, 2021 Author Share Posted July 23, 2021 ok, it works. thank you 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.