Code Red > AutoLISP (Vanilla / Visual)
How to write attribute functions?
(1/1)
dubb:
I am trying to learn how to manipulate attributes. They are a bit weird for me to grasp. I am also looking for some tutorials. I think I am having trouble identifying the entity handles.
My block attribute has a single tag and attribute text set to invisible.
--- Code: ---(entget(car(entsel)))
--- End code ---
--- Code: ---(entget(car(nentsel)))
--- End code ---
If the text was not set as invisible I could see the the dotted pair (1 . "attribute-info")
http://www.lee-mac.com/attributefunctions.html
Thanks for the info Lee Mac
So while looking into how they can be manipulated, how do I test this?
--- Code: ---Command: (test "pole-j" "pole-no")
; error: no function definition: TEST
--- End code ---
--- Code: ---;; Get Attribute Value - Lee Mac
;; Returns the value held by the specified tag within the supplied block, if present.
;; blk - [ent] Block (Insert) Entity Name
;; tag - [str] Attribute TagString
;; Returns: [str] Attribute value, else nil if tag is not found.
(defun c:test ( blk tag / enx )
(if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk)))))))
(if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
(cdr (assoc 1 enx))
(c:test blk tag)
)
)
)
--- End code ---
ronjonp:
You need to take the C: off of the test function and remove (c:test blk tag) then feed it:
--- Code - Auto/Visual Lisp: ---(defun test (blk tag / enx) (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))) (if (= (strcase tag) (strcase (cdr (assoc 2 enx)))) (cdr (assoc 1 enx)) ) ));; (test (car (entsel)) "pole-no")
*EDIT .. after looking at Lee's original function, you need the recursive call:
--- Code - Auto/Visual Lisp: ---;; Get Attribute Value - Lee Mac;; Returns the value held by the specified tag within the supplied block, if present.;; blk - [ent] Block (Insert) Entity Name;; tag - [str] Attribute TagString;; Returns: [str] Attribute value, else nil if tag is not found. (defun LM:getattributevalue ( blk tag / enx ) (if (= "ATTRIB" (cdr (assoc 0 (setq enx (entget (setq blk (entnext blk))))))) (if (= (strcase tag) (strcase (cdr (assoc 2 enx)))) (cdr (assoc 1 enx)) (LM:getattributevalue blk tag) ) ));; (LM:getattributevalue (car (entsel)) "pole-no")
dubb:
Awesome Thanks Ron!
BIGAL:
If you look into VL Lisp you can get at object properties 'Attributes being one of them, the advantage I see is that you work more in property names rather than using dxf codes.
--- Code: ---(foreach att (vlax-invoke (vlax-ename->vla-object (car (entsel "pick an attributed block"))) 'getattributes)
(Princ (strcat "\ntagname is " (strcase (vla-get-tagstring att))))
)
--- End code ---
Navigation
[0] Message Index
Go to full version