Tripledot Posted February 26, 2016 Share Posted February 26, 2016 (edited) Scenario: ext'g drawings contains many blocks. Most blocks is under some layer names other then layer 0, some are by design, some are just mistakes Question: Is there a way to isolate those blocks base on their block layer? Example: Layer 1 has Block A which contains layer 10, 11 & 12 Layer 2 has Block B which contains layer 20, 21 & 22 Layer 3 has Block C which contains layer 30, 31 & 32 How to isolate Layer 2 such that Block B which contains layer 20, 21 & 22 will be isolated as well? Reason: I need to delete a particular layer but i do not know if it assign to a Block, since isolating that layer, will not yield anything on the screen. If i use LAYDEL, any blocks under that layer will get without me knowing it I cannot change all blocks to layer 0 since it is not my drawing. Edited February 26, 2016 by Tripledot Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 26, 2016 Share Posted February 26, 2016 This is pretty rough but a starting point (setq doc (vla-get-activedocument (vlax-get-acad-object))) ; open database (setq allblocks (vla-get-blocks doc)) (vlax-for block allblocks (setq blkname (vla-get-name block)) (if (not (wcmatch (strcase blkname t) "*_space*")) (vlax-for* *ent block (setq layname (vla-get-layer ent)) (if (= layname "12")(alert (strcat blkname " Block has layer 12 " ))) ) ;_ end of vlax-for ) ;_ end of if ) ;_ end of vlax-for Quote Link to comment Share on other sites More sharing options...
Tripledot Posted February 26, 2016 Author Share Posted February 26, 2016 This is pretty rough but a starting point (setq doc (vla-get-activedocument (vlax-get-acad-object))) ; open database (setq allblocks (vla-get-blocks doc)) (vlax-for block allblocks (setq blkname (vla-get-name block)) (if (not (wcmatch (strcase blkname t) "*_space*")) (vlax-for* *ent block (setq layname (vla-get-layer ent)) (if (= layname "12")(alert (strcat blkname " Block has layer 12 " ))) ) ;_ end of vlax-for ) ;_ end of if ) ;_ end of vlax-for thanks. not familair with lsp other then applying it to dwg. to make clear, its concerning the layer of the block rather then name of the block. Quote Link to comment Share on other sites More sharing options...
Tripledot Posted February 26, 2016 Author Share Posted February 26, 2016 I come across a lisp by Lee McDonnell. It does inform through a message that there are *how many* blocks in that particular layer. Unfortunately, it does not indicate which block it is. And there is no way of knowing when dealing with hundreds of blocks/nested blocks ; Get All on Layer by Lee McDonnell ; Args:- layer (string) (defun get_all_on_layer (layer / ss eLst blks att aBlst ents eBlst) (if (tblsearch "LAYER" layer) (progn (setq eBlst (strcat "Entities within Blocks on Layer " layer ": \n\n")) (foreach x (blk_list) (setq ents (entnext (tblobjname "BLOCK" x))) (while ents (if (eq layer (cdr (assoc 8 (entget ents)))) (setq eBlst (strcat eBlst (cdr (assoc 0 (entget ents))) " Within Block: " x "\n"))) (setq ents (entnext ents)))) (alert eBlst)) (princ "\n<!> Layer Not Found in Drawing <!>")) (princ)) (defun blk_list (/ bLst) (vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) (setq bLst (cons (vla-get-name blk) bLst))) (setq bLst (vl-remove-if (function (lambda (x) (or (wcmatch x "*PAPER*") (wcmatch x "*MODEL*")))) bLst)) bLst) (defun c:GL () (get_all_on_layer (getstring "\nSpecify Layer: ")) (princ)) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted February 26, 2016 Share Posted February 26, 2016 Version 2 give it a (setq doc (vla-get-activedocument (vlax-get-acad-object))) ; open database (setq allblocks (vla-get-blocks doc)) (vlax-for block allblocks (setq blkname (vla-get-name block)) (if (not (wcmatch (strcase blkname t) "*_space*")) (vlax-for ent block (setq layname (vla-get-layer ent)) (cond ((= layname "10")(vla-put-layer ent "new layer")) ((= layname "12")(vla-put-layer ent "new layer")) ; repeat as required ) ) ;_ end of vlax-for ) ;_ end of if ) ;_ end of vlax-for Quote Link to comment Share on other sites More sharing options...
RobDraw Posted February 26, 2016 Share Posted February 26, 2016 QSelect or filter will get you there. You can filter out blocks and then filter by layer. This will get you a selection set of all the blocks on that layer. You can run list to find out the block names and how many of each. Quote Link to comment Share on other sites More sharing options...
Tripledot Posted February 26, 2016 Author Share Posted February 26, 2016 am i to put in the layer name highlighted in red? Example: Out of 100 over layering names, I need to isolate layer name "DISCREPANCIES" I did that but nothing happen. Version 2 give it a (setq doc (vla-get-activedocument (vlax-get-acad-object))) ; open database (setq allblocks (vla-get-blocks doc)) (vlax-for block allblocks (setq blkname (vla-get-name block)) (if (not (wcmatch (strcase blkname t) "*_space*")) (vlax-for ent block (setq layname (vla-get-layer ent)) (cond ((= layname "[b][color=red]DISCREPANCIES[/color][/b]")(vla-put-layer ent "[color=red][b]DISCREPANCIES[/b][/color]")) ((= layname "[color=red][b]DISCREPANCIES[/b][/color]")(vla-put-layer ent "[color=red][b]DISCREPANCIES[/b][/color]")) ; repeat as required ) ) ;_ end of vlax-for ) ;_ end of if ) ;_ end of vlax-for 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.