Jump to content

Block Selection


stevesfr

Recommended Posts

The following code will select all blocks in a drawing.(I think !)

 

 
(defun C:BLKS ()
  (setvar "cmdecho" 0)
  (setq tes (tblnext "block" T))

 

How to modify the code to only select blocks not having attributes?

I think I can then write selection set to file or Excel.

Thanks in advance for clue.

Link to comment
Share on other sites

The code you posted will just get the Table Definition for the first block in the block table.

 

There is no need for the CMDECHO change - as no commands are being called through the command line.

 

To create a selection set, you can use the "ssget" function, with various selection methods and a filter list.

 

As for "writing the selection set to file or Excel", a selection set is a collection of entities - so are you thinking of writing the block name to file or Excel or something else?

 

Lee

Link to comment
Share on other sites

The code you posted will just get the Table Definition for the first block in the block table.

 

There is no need for the CMDECHO change - as no commands are being called through the command line.

 

To create a selection set, you can use the "ssget" function, with various selection methods and a filter list.

 

As for "writing the selection set to file or Excel", a selection set is a collection of entities - so are you thinking of writing the block name to file or Excel or something else?

 

Lee

 

ok here is part of the rest that I have so far....

 

 
(setq f nil f (open "file locaton to save goes here" "w"))
  (while (/= nil tes)
     (setq bname (cdr (assoc 2 tes)))
     (setq sa (ssget "x" (list (cons 0 "INSERT")(cons 2 bname))))
     (if (/= nil sa) (progn
        (setq found (itoa (sslength sa)))
        (setq txta (strcat (chr 34) (strcase bname) (chr 34) "," found))
        (write-line txta f)
     ))
     (setq tes (tblnext "block"))
  )
  (close f)

 

more to add here etc... I'm working on it

need clue how to omit blocks having attributes !!

I dont want them in the list

Link to comment
Share on other sites

As a hint,

 

Regarding Selection methods, check the documentation in the Visual LISP Editor Help file on ssget.

 

Regarding the filter list, it looks almost like the DXF data list of an entity (the list you get when you use entget), except the entries are matched using a method similar to wcmatch.

 

Hence:

 

(ssget "_X" (list (cons 0 "Circle") (cons 8 "*lay")))

 

Will automatically (_X) retrieve a selection set of all circles on layers with names that end in "lay".

 

The DXF for whether a block has attributes or not is group code 66.

 

Hopefully thats enough to get you started!

 

Lee

Link to comment
Share on other sites

As a hint,

 

Regarding Selection methods, check the documentation in the Visual LISP Editor Help file on ssget.

 

Regarding the filter list, it looks almost like the DXF data list of an entity (the list you get when you use entget), except the entries are matched using a method similar to wcmatch.

 

Hence:

 

(ssget "_X" (list (cons 0 "Circle") (cons 8 "*lay")))

 

Will automatically (_X) retrieve a selection set of all circles on layers with names that end in "lay".

 

The DXF for whether a block has attributes or not is group code 66.

 

Hopefully thats enough to get you started!

 

Lee

 

A big thank you Lee, I think I can take it from here.

Link to comment
Share on other sites

A good start Steve, nice one.

 

This will help with the DXF codes:

 

http://autodesk.com/techpubs/autocad/acad2000/dxf/

 

Another way to approach it, which may be easier for you:

 

(defun getblks (/ tdef lst)
 (while (setq tdef (tblnext "BLOCK" (not tdef))) ; Cycle through the Blocks
   (if (/= 2 (logand 2 (cdr (assoc 70 tdef)))) ; If it doesn't have attributes
     (setq lst (cons (cdr (assoc 2 tdef)) lst)))) ; Add its name to the list
 (reverse lst)) ; Return list

(foreach blk (getblks)
.... do stuff here...

)

Link to comment
Share on other sites

A good start Steve, nice one.

 

This will help with the DXF codes:

 

http://autodesk.com/techpubs/autocad/acad2000/dxf/

 

Another way to approach it, which may be easier for you:

 

(defun getblks (/ tdef lst)
 (while (setq tdef (tblnext "BLOCK" (not tdef))) ; Cycle through the Blocks
   (if (/= 2 (logand 2 (cdr (assoc 70 tdef)))) ; If it doesn't have attributes
     (setq lst (cons (cdr (assoc 2 tdef)) lst)))) ; Add its name to the list
 (reverse lst)) ; Return list

(foreach blk (getblks)
.... do stuff here...

)

 

Lee, thanks for the alternate path to explore !!

Link to comment
Share on other sites

Lee, thanks for the alternate path to explore !!

 

Thats ok,

 

Using the sub-function in that way means that you don't have to run the whole code on every block, only those that have attributes - hence a faster end result.

 

If you need any help on the rest of the code, let me know :)

 

Lee

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