Jump to content

Is there a way to isolate Block base on the Block name?


Tripledot

Recommended Posts

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

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 

Link to comment
Share on other sites

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

 

to make clear, its concerning the layer of the block rather then name of the block.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 

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