Small Fish Posted March 24, 2010 Posted March 24, 2010 If I have a two set values that I want to pass to block how would I change two attributed values on the attributed title block? eg if I have a attributed title with scales below it that show tags of 'A1_scale' and 'A3_scale' and my scales are 1:20 and 1:10. After selecting the block, how would I pass the the 2 scales to the attributed block? thanks SF Quote
Lee Mac Posted March 24, 2010 Posted March 24, 2010 It depends on how you want to approach it, you could step through the attribute entities of the block using entnext, and modify each in turn, or step through the attribute objects using the GetAttributes method on the VLA Block Object. Lee Quote
Small Fish Posted March 24, 2010 Author Posted March 24, 2010 I guess the 'GetAttributes method' as the rest of the code I have already written is visual lisp Quote
Lee Mac Posted March 24, 2010 Posted March 24, 2010 If you have selected your block object, convert it to a VLA-Object, and you're then ready to get going. I would make sure it has attributes using the HasAttributes property, then using GetAttributes to get at them. I normally use something like: (vlax-invoke obj 'GetAttributes) As the list is more useful than the variant in most cases. When you have the list, perhaps do a dump of each object in the list and have fun exploring the props and methods. If you get stuck, yell. Lee Quote
Small Fish Posted March 25, 2010 Author Posted March 25, 2010 Lee thanks for pointing me in the right direction. I did not use : (vlax-invoke obj 'GetAttributes) What I have more or less works, however I will need to add Entsel to select a given attribute. At the moment all blocks called "Title_View_dyn" have the tag called "A1_scale" changed. When I add some more code and use 'entsel' how can I make it so that only the block the user selects is changed? I guess its about making a filter but i am not sure how to construct it? thanks SF (defun c:AmendTag ( / layout i atts tag doc bn tagname textstring) (vl-load-com) ;;variables for testing (setq bn "Title_View_dyn");block name (setq tagname "A1_SCALE" );name of tag (setq textstring "1:25");text string (setq doc(vla-get-ActiveDocument (vlax-get-acad-object))) (vlax-for layout (vla-get-layouts doc) (vlax-for i (vla-get-block layout) (if (and (= (vla-get-objectname i) "AcDbBlockReference") (= (strcase (vla-get-name i)) (strcase bn)) ) (if (and (= (vla-get-hasattributes i) :vlax-true) (safearray-value (setq atts (vlax-variant-value (vla-getattributes i)) );setq ) );and (foreach tag (vlax-safearray->list atts) (if (= (strcase tagname) (strcase (vla-get-tagstring tag))) (vla-put-TextString tag textstring) );if );foreach (vla-update i) );if );if ) ) );defun Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 Would you want the user to select a block and all blocks with that name are changed? Quote
Small Fish Posted March 25, 2010 Author Posted March 25, 2010 no- thats what happens at the moment (all blocks with that name change) I only want the block the user selects change. It might be tricky? Quote
BIGAL Posted March 25, 2010 Posted March 25, 2010 it should be easier when using entsel you can pick just 1 entity check its a block and then update it To quote the old lisp book (setq e (entsel "Please pick block to change:")) Quote
Small Fish Posted March 25, 2010 Author Posted March 25, 2010 >>>using entsel you can pick just 1 entity check its a block and then update it ....yeah I guess so - not sure if it will work- I will try it when I get a chance. Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 no- thats what happens at the moment (all blocks with that name change) I only want the block the user selects change. It might be tricky? Actually, there is no selection at the minute. Did you write your current code? Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 This should work: (defun c:AmendTag (/ bNme Tag Tex i ss ent) (vl-load-com) (setq bNme "Title_View_dyn" Tag "A1_SCALE" Tex "1:25") (if (setq i -1 ss (ssget "_:L" (list (cons 0 "INSERT") (cons 2 bNme) (cons 66 1)))) (while (setq ent (ssname ss (setq i (1+ i)))) (foreach att (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes) (if (eq (strcase (vla-get-TagString att)) (strcase Tag)) (vla-put-TextString att Tex))))) (princ)) Quote
Small Fish Posted March 25, 2010 Author Posted March 25, 2010 Thanks Lee - thats a bit more compact and it works well. There is just one more problem which I can't work out. At the moment only one tag is changed - "A1_SCALE" and it's changed to "1:25" However my block has two tags - one called "A1_SCALE" and the other is called "A3_SCALE" and there are two values that need to correspond to each tag eg "1:25(A1)" for the "A1_SCALE" tag "1:50(A3)" for the "A3_SCALE" tag How do I feed the two values into the two different tags? thanks if anyone can help cheers SF Quote
Small Fish Posted March 25, 2010 Author Posted March 25, 2010 Never mind - now I have it sussed! thanks... Part 1 is now finished (defun c:AmendTag2 (/ bNme Tag Tex i ss ent) (vl-load-com) (setq bNme "Title_View_dyn" Tag1 "A1_SCALE" Tag2 "A3_SCALE" Tex1 "1:25(A1)" Tex2 "1:50(A3)" ) (if (setq i -1 ss (ssget "_:L" (list (cons 0 "INSERT") (cons 2 bNme) (cons 66 1)));filter );setq (while (setq ent (ssname ss (setq i (1+ i)))) (foreach att (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes) (if (eq (strcase (vla-get-TagString att)) (strcase Tag1)) (vla-put-TextString att Tex1) );if (if (eq (strcase (vla-get-TagString att)) (strcase Tag2)) (vla-put-TextString att Tex2) );if );foreach );while );if (princ) );defun Quote
Lee Mac Posted March 25, 2010 Posted March 25, 2010 This is how I might approach it: (defun c:AmendTag (/ bNme TagLst i ss ent) (vl-load-com) (setq bNme "Title_View_dyn" TagLst '(("A1_SCALE" . "1:25 (A1)") ("A3_SCALE" . "1:50 (A3)"))) (if (setq i -1 ss (ssget "_:L" (list (cons 0 "INSERT") (cons 2 bNme) (cons 66 1)))) (while (setq ent (ssname ss (setq i (1+ i)))) (foreach att (vlax-invoke (vlax-ename->vla-object ent) 'GetAttributes) (if (setq ass (assoc (strcase (vla-get-TagString att)) TagLst)) (vla-put-TextString att (cdr ass)))))) (princ)) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.