Select block from 1st attribute value; turn value of 2nd attribute into variable

Select block from 1st attribute value; turn value of 2nd attribute into variable

Anonymous
Not applicable
846 Views
4 Replies
Message 1 of 5

Select block from 1st attribute value; turn value of 2nd attribute into variable

Anonymous
Not applicable

Hello,

  I have been searching through the forums, and while I am finding bits and pieces, I can't seem to find exactly what I am looking for.  

  Here is what I would like to do with LISP:

    I have attached a small sample drawing containing a few blocks.  I will typically have several instances of this block titled "A-FLOOR-CALLOUT-DOOR" in a drawing.  The block contains two attributes: one titled "DOOR" and the other titled "NOTE."  Each block should have a unique number for the "DOOR" attribute value, starting at 1 (I figured I would write in a safeguard in the routine just in case there were two blocks with the same "DOOR" number, so the user can exit, adjust the number, and re-run the routine).  The LISP will then find the block based on the "DOOR" value, starting with number 1, and then it would take the value of its second attribute "NOTE", and turn that into a variable.  The idea is that I can use that variable elsewhere in the drawings (for example, a door schedule).  

  I put together some code - see below.  The routine counts the number of block "A-FLOOR-CALLOUT-DOOR" in the drawings, and then repeats that number to times, searching for "DOOR" 1, 2, 3, and so on.  This part is working, but I am stuck on how to obtain the value of the "NOTE" attribute and turn into a variable, as noted in the code.  Any help on this example would be greatly appreciated.  If anyone has a different approach to achieve this, I am all ears!

Thanks!

Marty

 

;code start

(defun C:GatherAttributes ( )


; variables
(setq BLOCK1 "A-FLOOR-CALLOUT-DOOR")
(setq ATTTAG1 "DOOR")
(setq ATTTAG2 "NOTE")
(setq ATTVAL 0)


; set-up
(vl-load-com)

;count blocks
(setq BNAME2 (cons 2 BLOCK1))
(setq BNAME1 (ssget "x" (list BNAME2)))
(setq NUMB (sslength BNAME1))

 

; gather attributes
(setq *mspace* (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
)

(repeat NUMB
(setq ATTVAL (+ ATTVAL 1))
(setq ATTVAL1 (itoa ATTVAL))

(vlax-for item *mspace*
(if (and (= (vla-get-objectname item)"AcDbBlockReference") (= (strcase (vla-get-name item)) BLOCK1)
)
(mapcar '(lambda (a)
(if (and (= (vla-get-TagString a) ATTTAG1) (= (vla-get-TextString a) ATTVAL1) )

 

;;;;how to get the second attribute value?

 

)
)
(vlax-safearray->list
(variant-value
(vla-GetAttributes item)
)
)
)
)
)

);end repeat

 

;end
(Prompt "") (terpri)
(Prompt "---") (terpri)
(Prompt "Routine is complete!") (terpri)
(princ)
)

;code end

 

0 Likes
Accepted solutions (1)
847 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
0 Likes
Message 3 of 5

dbroad
Mentor
Mentor
Accepted solution

I don't want to discourage your AutoLISP developement but I know LISP quite well and have never bothered with this kind of program.  Why, you might ask?  Because the built-in dataextraction command does such a nice job with creating schedules based on blocks and their attributes.  It also can automatically update once set up.  It can help  you spot duplicate door numbers.  Once you do it, you can use the dxe file as a template for the next job.

 

As for your code, you might need to use activex methods instead of ssget methods to catch nested block references.  Something like

(vlax-for block (vla-get-blocks (vla-get-activedocument(vlax-get-acad-object)))

  (vlax-for object block

    ;;if object is the block reference you are looking for, then 

    ;;get its attributes and do stuff

))

 

Such a program will get objects in all the layouts, assuming that your door tags might be in one of the paper space blocks.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 4 of 5

Anonymous
Not applicable

I have not really gotten into DATAEXTRACTION, but after looking into it, it looks like it will do what I need.  Thank you for the advice.  

0 Likes
Message 5 of 5

dbroad
Mentor
Mentor

You're welcome. Hope it works well for you.

Architect, Registered NC, VA, SC, & GA.
0 Likes