TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: hendie on December 16, 2005, 04:00:43 AM
-
I'm looping through a selection set of blocks and creating a list from a number of Constant (& Invisible) attributes.
The problem I'm having is that I cannot filter by block name (a gazillion different blocks), the number of attributes differs with each block and some of the blocks don't have Constant atttributes at all.
I'm using
(vlax-safearray->list
(vlax-variant-value
(vla-getconstantattributes (vlax-ename->vla-object MyBlkent))
)
)
to get the constant attributes, but it throws a wobbly with vlax-safearray->list when it comes across a block without any constant attributes. I keep getting ; error: ActiveX Server returned an error: Invalid index
I've tried all sorts of combinations of vl-catch-all-whatever and I just can't seem to get round this one.
Basically I want the routine to skip over any blocks that do not contain Constant attributes... anyone have any pointers ?
-
Hi
Use the Invoke method (variable AttLst is a list in this case):
(repeat (sslength SelSet)
(setq CurObj (vlax-ename->vla-object (ssname SelSet SetCnt))
SetCnt (1+ SetCnt)
)
(if (setq AttLst (vlax-invoke CurObj 'GetConstantAttributes))
(DoYourStuff)
)
)
-
Or optionally ....
See if this helps
Just drop it into the VLIDE, select the lot and load the selection ... or just run it one procedure at a time.
(setq *TempEnt* (vlax-ename->vla-object (car (entsel))))
(setq Att (vlax-variant-value (vla-getattributes *TempEnt*))
Conatt (vlax-variant-value (vla-getconstantattributes *TempEnt*))
)
(setq AttributeReference (safearray-value Att))
(setq ConAttributeReference (safearray-value ConAtt))
so the trick this way is use safearray-value on the variable to test ..
but vlax-invoke as Jürg shows solves a lot of issues, not just with attributes.
-
thanks guys, excellent information.
That solved the problem ~ I ended up using Jürg's option but I'lll hold on to the rest as well,
thanks Kerry, and thanks Jürg
-
Hi hendie
Here are my two pence
Change by suit
Thank you
Fatty :-)
;; Get all attributes include constant attributes
(vl-load-com)
(defun get-all-atts (/ atts att_list const_atts const_list ent obj)
(and (setq ent (car (entsel "\nSelect block to make attributes list: ")))
(setq obj (vlax-ename->vla-object ent))
(if (and (vlax-property-available-p obj 'Hasattributes)
(eq :vlax-true (vla-get-hasattributes obj))
)
(progn
(setq atts (vlax-invoke obj 'Getattributes))
(foreach att atts
(setq att_list
(cons (cons (vla-get-tagstring att)
(vla-get-textstring att)
)
att_list
)
)
)
)
)
)
(cond ((vlax-method-applicable-p obj 'Getconstantattributes)
(setq const_atts (vlax-invoke obj 'Getconstantattributes))
(foreach att const_atts
(setq const_list
(cons (cons (strcat "*CONSTANT*: " (vla-get-tagstring att))
(vla-get-textstring att)
)
const_list
)
)
)
(setq att_list (append const_list att_list))
)
(T att_list)
)
)
;CaLL:(setq blk_info (get-all-atts))
-
BTW, that's my standard attribute read function:
;
; == Function MeGetAtts
; Reads all attribute values from an inserted block.
; Arguments [Type]:
; Obj = Insert object [VLA-OBJECT]
; Mde = Attribute mode [INT]
; 1 = Attributes only
; 2 = Constant attributes only
; 3 = Both
; Return [Type]:
; > Dotted pair list '(("Tag1" . "Val1")...) [LIST]
; Notes:
; - None
;
(defun MeGetAtts (Obj Mde)
(mapcar
'(lambda (Att) (cons (vla-get-TagString Att) (vla-get-TextString Att)))
(append
(if (= (logand Mde 1) 1) (vlax-invoke Obj 'GetAttributes))
(if (= (logand Mde 2) 2) (vlax-invoke Obj 'GetConstantAttributes))
)
)
)
-
BTW, that's my standard attribute read function:
Hi Juergen
Nice routine
You killed me
Thanks again
Fatty
-
Hi Fatty, nice to see you here at TheSwamp... :-)
You killed me
I hope not... :-D
-
I hope not... :-D
Thanks Juergen
Have a nice weekend
Fatty :-)