一些更正:
- ;Trying to obtain effective blockname, a attribute name and its attribute value
- ;I am going to use "foreach" function, and different conditions, based on that attribute value
- (defun c:test ( / i o s MyBlockName MyAttributeName1 MyAttributeName2 )
- (setq MyBlockName (getstring T "\nType the name of the Block to look for:"))
- (setq MyAttributeName1 (getstring T "\nType the name of the Attribute1 to look for:"))
- (setq MyAttributeName2 (getstring T "\nType the name of the Attribute2 to look for:"))
- (if (setq s (ssget "_X" (list '(0 . "INSERT") '(66 . 1) (cons 2 (strcat "`*U*," MyBlockName)))))
- (repeat (setq i (sslength s))
- (setq o (vlax-ename->vla-object (ssname s (setq i (1- i)))))
- (if (and (vlax-property-available-p o 'effectivename)
- (= (strcase MyBlockName) (strcase (vla-get-effectivename o) t))
- )
- (progn
- (princ (strcat "\nFound " MyBlockName " block "" (vla-get-handle o) ""."))
- (if (setq MyAttributeValue1 (LM:vl-getattributevalue o MyAttributeName1))
- (progn
- (princ (strcat "\nFound the block named " MyBlockName " !"))
- (princ (strcat "\nFound the attribute named " MyAttributeName1 " !"))
- (princ (strcat "\nThe value of that attribute is " MyAttributeValue1 " !"))
- );progn
- (princ (strcat "\n"" MyAttributeName1 "" attribute not found in "" MyBlockName "" block."))
- );if
- (if (setq MyAttributeValue2 (LM:vl-getattributevalue o MyAttributeName2))
- (progn
- (princ (strcat "\nFound the block named " MyBlockName " !"))
- (princ (strcat "\nFound the attribute named " MyAttributeName2 " !"))
- (princ (strcat "\nThe value of that attribute is " MyAttributeValue2 " !"))
- );progn
- (princ (strcat "\n"" MyAttributeName2 "" attribute not found in "" MyBlockName "" block."))
- );if
- )
- )
- )
- (princ (strcat "\nNo attributed " MyBlockName " blocks found in the drawing."))
- )
- (princ)
- )
- (vl-load-com) (princ)
- ;; Get Attribute Value - Lee Mac
- ;; Returns the value held by the specified tag within the supplied block, if present.
- ;; blk - [vla] VLA Block Reference Object
- ;; tag - [str] Attribute TagString
- ;; Returns: [str] Attribute value, else nil if tag is not found.
- (defun LM:vl-getattributevalue ( blk tag )
- (setq tag (strcase tag))
- (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
- (vlax-invoke blk 'getattributes)
- )
- )
|