feargt Posted October 10, 2012 Posted October 10, 2012 Hi, Can anyone assist me with the following issue. I have a dynamic block with multiple visibility states. (Vis1 to Vis5 for example) In each visibilty I habe two unique attributes. So in Vis1 has two attibute tags called Length1 & Width1 ........Vis2 has two attibute tags called Length2 & Width2 ...... I want to get the value of the attributes in the current visibility state and save them as variables Var1 and Var2. The only joy in searching was what I found on Lee Mac's website but I have not been able to make any progress with his code. (see below) Thanks for any help on this Get Attribute Value Select all ;;----------------=={ Get Attribute Value }==-----------------;; ;; ;; ;; Returns the attribute value associated with the specified ;; ;; tag, within the supplied block, if present. ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2010 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; block - VLA Block Reference Object ;; ;; tag - Attribute TagString ;; ;;------------------------------------------------------------;; ;; Returns: Attribute TextString, else nil ;; ;;------------------------------------------------------------;; (defun LM:vl-GetAttributeValue ( block tag ) (setq tag (strcase tag)) (vl-some (function (lambda ( attrib ) (if (eq tag (strcase (vla-get-Tagstring attrib))) (vla-get-TextString attrib) ) ) ) (vlax-invoke block 'GetAttributes) ) ) (defun c:test ( / ss ) (if (setq ss (ssget "_+.:E:S" '((0 . "INSERT") (66 . 1)))) (princ (LM:vl-GetAttributeValue (vlax-ename->vla-object (ssname ss 0)) (getstring "\nSpecify Tag String: ") ) ) ) (princ) ) (vl-load-com) ;;----------------=={ Get Visibility State }==----------------;; ;; ;; ;; Returns the value of the Visibility Parameter of a ;; ;; Dynamic Block (if present) ;; ;;------------------------------------------------------------;; ;; Author: Lee Mac, Copyright © 2011 - [url="http://www.lee-mac.com"]www.lee-mac.com[/url] ;; ;;------------------------------------------------------------;; ;; Arguments: ;; ;; block - VLA (Dynamic) Block Reference Object ;; ;;------------------------------------------------------------;; ;; Returns: Value of Visibility Parameter, else nil ;; ;;------------------------------------------------------------;; (defun LM:GetVisibilityState ( block ) ( (lambda ( name ) (vl-some (function (lambda ( prop ) (if (eq name (vla-get-propertyname prop)) (vlax-get prop 'value) ) ) ) (vlax-invoke block 'getdynamicblockproperties) ) ) (LM:GetVisibilityParameterName block) ) ) Quote
pBe Posted October 11, 2012 Posted October 11, 2012 Since the tags are different for each visibility you can retrieve the attributes like you normally do and use the tag names to identify which textstring value you want assigned to the variables Var1 and Var2. Quote
feargt Posted October 11, 2012 Author Posted October 11, 2012 Hi, Thanks. Ideally I could find the attribute values for tags containing part of the tag name i.e. length and width within the current visibility state. for actual visibilty state (setq var 1 (get attribute value for tag containing string "length") (setq var 2 (get attribute value for tag containing string "width") But I do not know how to do this or if this is possible. Quote
pBe Posted October 11, 2012 Posted October 11, 2012 Hi, Thanks. Ideally I could find the attribute values for tags containing part of the tag name i.e. length and width within the current visibility state. But I do not know how to do this or if this is possible. It is possible Its easy. Since you are the author of your own Dynamic Block AND as i mentioned before you have a particular suffix for tags at every visibility , what you can do is determine the current visibility and with the use of a list you can target specific tags. (setq lst '(("Vis1" . ("LENGTH1" "WIDTH1"))("Vis2" . ("LENGTH2" "WIDTH2"))("Vis3" . ("LENGTH3" "WIDTH3")))) With Lee Mac's sub LM:GETVISIBILITYSTATE/LM:GetVisibilityParameterName you can easily determine the current state: Say the current visibility name is "Vis2" (setq targetTags (assoc "Vis2" lst)) If you don't mind posting your Block, I could point you in the right direction. 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.