Get Block definition attributes

Get Block definition attributes

DonatasAzaravicius
Advocate Advocate
3,942 Views
7 Replies
Message 1 of 8

Get Block definition attributes

DonatasAzaravicius
Advocate
Advocate

Hi,

I made function to get all block attributes.

(defun C:PrintAttr ( / )
  (setq blockName (car (entsel)))
  (setq blockName (entnext blockName))
  (while (not (eq (cdr (assoc 0 (setq dxf (entget blockName)))) "SEQEND"))
    (print (cdr (assoc 2 dxf)))
    (setq blockName (entnext blockName))
  )
  (princ)
)

For it to work you need to select block, but I need to get attributes of block definition and not block object. Here are no inserted block in drawing. How could I get attributes from block definition if it is defined in drawing but not inserted in drawing.

0 Likes
Accepted solutions (1)
3,943 Views
7 Replies
Replies (7)
Message 2 of 8

pbejse
Mentor
Mentor

@DonatasAzaravicius wrote:

 How could I get attributes from block definition if it is defined in drawing but not inserted in drawing.


If you extract the values from a block definition, all you get are the default string value, is that what you want?

0 Likes
Message 3 of 8

DonatasAzaravicius
Advocate
Advocate
Accepted solution

Yes I want only text strings to show user all attributes of block definition.

 

By try and fail I was able to modify my function

(defun C:PrintAttrDef (blName / blockName dxf)
  (setq blockName (tblobjname "block" blName))
  (setq blockName (entnext blockName))
  (while (not (= blockName nil))
    (setq dxf (entget blockName))
    (if (= (cdr (assoc 0 dxf)) "ATTDEF")
      (print (cdr (assoc 2 dxf)))
    )
    (setq blockName (entnext blockName))
  )
  (princ)
)

Looks like it works as I want.

0 Likes
Message 4 of 8

pbejse
Mentor
Mentor

@DonatasAzaravicius wrote:

Yes I want only text strings to show user all attributes of block definition.

 

....Looks like it works as I want.


Good for you. I would've coded it the same way using tblobjname, one thing though, you may want to run it thru (tblnext "BLOCK" ...). that way, the code will still show the values without supplying the block names.

 

(while
  (setq a (tblnext "BLOCK" (null a)))
   (if (= (cdr (assoc 70 a)) 2)
     (progn
       (setq ent (tblobjname "BLOCK" (cdr (assoc 2 a))))
       (print (cdr (assoc 2 a)))
       (While
	 (setq ent (entnext ent))
	  (if (= "ATTDEF" (cdr (assoc 0 (setq enx (entget ent)))))
	    (princ
	      (strcat "\n" (cdr (assoc 2 enx)) "|" (cdr (assoc 1 enx)))
	    )
	  )
       )
     )
   )
)

HTH

0 Likes
Message 5 of 8

DonatasAzaravicius
Advocate
Advocate

I had read about (null item) function, but never found use for it. Your use of it are interesting. Will need to remember.

 

To give move specific about what I want to do.

I try to create lisp to insert block (one block) from csv file to drawing. csv file will be like this:

blName; x; y; z; attr1; attr2; ...

And I want to create GUI using openDCL.

After user selects csv file it will be displayed in OpenDCL Grid. And as columns header will be used attributes from block definition. So user will know if his csv file is right (delimiter). In csv file not all attributes will be needed. If block have five attributes but csv file have only two. Last tree attributes will be empty. If csv have more attributes others will be discarded.

 

Now I am using Tony Hotchkiss lisp CADALYST 11/06 AutoLISP Solutions  INSBLK3.LSP

But you need to specify all attributes in csv file for it to work. And if you selected wrong delimiter it is hard to understand.

I may create export function too.

 

So, here are a lot of work to do. And I need to know attributes of specific block.

0 Likes
Message 6 of 8

pbejse
Mentor
Mentor

@DonatasAzaravicius wrote:

 

 ...So, here are a lot of work to do. And I need to know attributes of specific block...


Are you looking for help in writing the code? and using specifically openDCL.

 

 

 

0 Likes
Message 7 of 8

DonatasAzaravicius
Advocate
Advocate

No, I don't look for help in writing the code, unless I am  stuck (like this time).

I tried DCL, but it was hard to use and limited. Found OpenDCL and I liked it. It has OpenDCL Studio to visually create GUI.

0 Likes
Message 8 of 8

DonatasAzaravicius
Advocate
Advocate

Here are my lisp code and GUI

Block Import

0 Likes