Code Red > AutoLISP (Vanilla / Visual)
Attribute replacer
Shade:
I am trying to write a attribute value replacer, in visual lisp. The following is what I have come up with.
--- Code: ---(Defun ATTREPLACE (ENM ATT TXT)
(setq OBJ (VLAX-ENAME->VLA-OBJECT ENM)
ATT (VLA-GETATTRIBUTES OBJ)
VAR (VLAX-VARIANT-VALUE ATT)
CNT (vlax-safearray-get-dim VAR)
);
(while (>= CNT 0)
(setq ARG (VLAX-SAFEARRAY-GET-ELEMENT VAR CNT)
CNT (- CNT 1)
CHK (vlax-get-property ARG "TagString")
)
(if (= CHK ATT)
(setq CNT 0
VAL (vlax-put-property ARG "TextString" TXT)
)
);if
);while
);#ATTREPLACE
--- End code ---
The problemI am having, is I know a attribute exist in the block I pass to the lisp, but for some reason the lisp does not change the existing value to the new value.
The only reason I can figure out why is that the safety arrays dimension is 1 insetad of 6, which is the number of attributes I have in the block.
Why does (vlax-safearray-get-dim VAR) return 1 when there are 6 attributes in the block?
:realmad:
T.Willey:
To get a list of attributes within a block, it is easier to use (vlax-invoke Obj 'GetAttributes).
Tim
whdjr:
Short and Sweet!
I like it T. :-)
Jeff_M:
Shade, while Tim's solution is far easier to work with, I'll attempt to answer your question.
A single dimension array is one with 1 column and multiple rows for the data. So the call to (vlax-safearray-get-dim VAR) returns 1 because there is just 1 column. To access what you thought you were you need to use the (vlax-safearray-get-l-bound VAR 1)...this is the lower index starting number of dimension(column) 1...and (vlax-safearray-get-u-bound VAR 1)...this is the upper value of dimension(column) 1 so if the lbound is 0 and the ubound is 5 you have 6 elements in that array's dimension.
And that is why using Tim's method is easier :)
Jeff_M:
Written on the fly, not tested but should work....this does what you are looking for
--- Code: ---(defun attreplace (enm att txt / atts )
(setq obj (vlax-ename->vla-object enm)
atts (vlax-invoke obj 'getattributes)
);
(foreach x atts
(if (eq (vlax-get-property x "tagstring") att)
(vlax-put-property x "textstring" txt)
);if
);foreach
);#attreplace
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version