Message 1 of 5
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
We have a 3 level rev block, if the block is full I need to shift the values down 1 and clear out the top rev for the new rev details. I tried using Lee Mac's Get and Set attributes, but they are failing on me - it either doesn't like the block I'm sending it or the string. I'm trying to get specific attributes and assign them to different tags.
(defun c:UPREV (/ ent tag newList rev1 rev1Att)
(setq *error* xx:Error)
;;; Select title block to update
(setq ent (car (entsel "\nSelect Attributed Block: ")))
(setq newList (LM:vl-getattributevalues (vlax-ename->vla-object ent)))
(setq rev1Att "REV_NO.1")
(setq rev1 (LM:vl-getattributevalue ((vlax-ename->vla-object ent) rev1Att)))
;;; (setq rev2 (LM:vl-getattributevalue (blk "REV_NO.2")))
;;; (setq desc1 (LM:vl-getattributevalue (blk "DESCRIPTION_1")))
;;; (setq desc2 (LM:vl-getattributevalue (blk "DESCRIPTION_2")))
;;; (setq eco1 (LM:vl-getattributevalue (blk "ECO_1")))
;;; (setq eco2 (LM:vl-getattributevalue (blk "ECO_2")))
;;; (setq draw1 (LM:vl-getattributevalue (blk "DRAWN_BY_1")))
;;; (setq draw2 (LM:vl-getattributevalue (blk "DRAWN_BY_2")))
;;; (setq date1 (LM:vl-getattributevalue (blk "DATE_1")))
;;; (setq date2 (LM:vl-getattributevalue (blk "DATE_2")))
;;;
;;; (LM:vl-setattributevalue (blk "REV_NO.1" nil))
;;; (LM:vl-setattributevalue (blk "REV_NO.2" rev1))
;;; (LM:vl-setattributevalue (blk "REV_NO.3" rev2))
;;; (LM:vl-setattributevalue (blk "DESCRIPTION_1" nil))
;;; (LM:vl-setattributevalue (blk "DESCRIPTION_2" desc1))
;;; (LM:vl-setattributevalue (blk "DESCRIPTION_3" desc2))
;;; (LM:vl-setattributevalue (blk "ECO_1" nil))
;;; (LM:vl-setattributevalue (blk "ECO_2" eco1))
;;; (LM:vl-setattributevalue (blk "ECO_3" eco2))
;;; (LM:vl-setattributevalue (blk "DRAWN_BY_1" nil))
;;; (LM:vl-setattributevalue (blk "DRAWN_BY_2" draw1))
;;; (LM:vl-setattributevalue (blk "DRAWN_BY_3" draw2))
;;; (LM:vl-setattributevalue (blk "DATE_1" nil))
;;; (LM:vl-setattributevalue (blk "DATE_2" date1))
;;; (LM:vl-setattributevalue (blk "DATE_3" date2))
)
;; 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)) ; all uppercase
(vl-some '(lambda (att)
(if (= tag (strcase (vla-get-tagstring att)))
(vla-get-textstring att)
)
)
(vlax-invoke blk 'getattributes)
)
)
;; 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 Values - Lee Mac
;; Returns an association list of attributes present in the supplied block.
;; blk - [vla] VLA Block Reference Object
;; Returns: [lst] Association list of ((<tag> . <value>) ... )
(defun LM:vl-getattributevalues (blk)
(mapcar '(lambda (att)
(cons (vla-get-tagstring att) (vla-get-textstring att))
)
(vlax-invoke blk 'getattributes)
)
)
(defun xx:Error (st)
(if (not
(member st (list "Function cancelled" "quit / exit abort"))
)
(vl-bt)
)
(princ)
)
Solved! Go to Solution.