Author Topic: Block Attribute assitance needed  (Read 2022 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Block Attribute assitance needed
« on: September 14, 2005, 01:18:32 PM »

I need this to be able to find a certain attribute in the block and update that attribute with the new square footage from the modified lwpolyline.
Any ideas?

Code: [Select]
(defun print-area (pline reactor null_list / attributes square_feet_attribute square_feet block_reference)
  (setq block_reference (vlr-data reactor) block_reference (handent block_reference) block_reference
  (vlax-ename->vla-object block_reference)
  )
  (setq attributes (vla-getattributes block_reference) attributes (vlax-variant-value attributes) attributes
  (vlax-safearray->list attributes)
  )
(setq square_feet_attribute (cadr attributes))
(setq square_feet (strcat (rtos (/ (vla-get-area pline)144) 2 3 ) " Sq. Ft. "))
  (vla-put-textstring square_feet_attribute square_feet)
)
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Re: Block Attribute assitance needed
« Reply #1 on: September 14, 2005, 02:16:12 PM »
Hi Don,
Replace these lines:
Code: [Select]
(setq attributes (vla-getattributes block_reference) attributes (vlax-variant-value attributes) attributes
  (vlax-safearray->list attributes)
  )
(setq square_feet_attribute (cadr attributes))
(setq square_feet (strcat (rtos (/ (vla-get-area pline)144) 2 3 ) " Sq. Ft. "))
  (vla-put-textstring square_feet_attribute square_feet)
with these:
Code: [Select]
(setq attributes (vlax-invoke block_reference 'getattributes));;not necessary to change this, but it's easier to read, IMHO
(foreach att attributes
  (if (eq (vla-get-tagstring att) "SQFT");;<<<---change to value your attribute uses
    (progn
      (setq square_feet (strcat (rtos (/ (vla-get-area pline)144) 2 3 ) " Sq. Ft. "))
      (vla-put-textstring att square_feet)
      )
    )
  )
That should do it.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Block Attribute assitance needed
« Reply #2 on: September 14, 2005, 03:39:40 PM »

Thanks for the code, that did the trick. I'm still having some problems with my code. Could some of you guys test this out and let me know how I can refine this code. There still seems to be some minor bugs in it but it does work most of the time. Constructive criticism is always welcome.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023