I can't get it work:
;; Set Attribute Value - Lee Mac
;; Sets the value of the first attribute with the given tag found within the block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; val - [str] Attribute Value
;; Returns: [str] Attribute value if successful, else nil.
(defun LM:vl-setattributevalue ( blk tag val )
(setq tag (strcase tag))
(vl-some
'(lambda ( att )
(if (= tag (strcase (vla-get-tagstring att)))
(progn (vla-put-textstring att val) val)
)
)
(vlax-invoke blk 'getattributes)
)
)
;;----------------=={ Get Attribute Value }==-----------------;;
;; ;;
;; Returns the attribute value associated with the specified ;;
;; tag, within the supplied block, if present. ;;
;;------------------------------------------------------------;;
;; Author: Lee McDonnell, 2010 ;;
;; ;;
;; Copyright © 2010 by Lee McDonnell, All Rights Reserved. ;;
;; Contact: Lee Mac @ TheSwamp.org, CADTutor.net ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; block - VLA Block Reference Object ;;
;; tag - Attribute TagString ;;
;;------------------------------------------------------------;;
;; Returns: Attribute TextString, else nil ;;
;;------------------------------------------------------------;;
(defun LM:GetAttributeValue ( block tag )
;; © Lee Mac 2010
(vl-some
(function
(lambda ( attrib )
(if (eq tag (vla-get-Tagstring attrib))
(vla-get-TextString attrib)
)
)
)
(vlax-invoke block 'GetAttributes)
)
)
(defun c:Test (/ ent tagname)
(setq ss (ssget '((0 . "INSERT")(66 . 1))))
(repeat (setq i (sslength ss))
(setq blk (ssname ss (setq i (1- i))))
(setq kostenplaats
(LM:GetAttributeValue
(vlax-ename->vla-object ent) (strcase "KOSTENPLAATS")
)
)
)
(setq tagname "RUIMTESOORT")
(cond
( (= "1100" kostenplaats) (LM:vl-SetAttributeValue (vlax-ename->vla-object blk) tagname "Afdeling 1100") )
( (= "1200" kostenplaats) (LM:vl-SetAttributeValue (vlax-ename->vla-object blk) tagname "Afdeling 1200") )
( (= "1300" kostenplaats) (LM:vl-SetAttributeValue (vlax-ename->vla-object blk) tagname "Afdeling 1300") )
)
(princ)
)