;;o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o
;; Change Attribut of Block
;;o~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~o
(defun attblkchange (enm blk tag newval)
(if (and (= (dxf-code 0 enm) "INSERT") (= (dxf-code 2 enm) blk))
(progn
(while (= "ATTRIB" (dxf-code 0 (setq enm (entnext (dxf-code -1 enm)))))
(setq elst (entget enm))
(cond ( (= (dxf-code 2 enm) tag)
(entmod (subst (cons 1 newval) (assoc 1 elst) elst))
(entupd enm)
)
);end cond
);end while
);end progn
);end if
)
(setq doc (vla-get-activedocument (vlax-get-acad-object))) ; open Autocda database
(vlax-for lay (vla-get-Layouts doc) ; get the layouts from the database
(setq plotabs (cons (vla-get-name lay) plotabs)) ; make a list of the layout names
)
(setq x 0)
(repeat (length plotabs) ; step through the list looking at each layout
(setq tabname (nth x plotabs)) ; get the 1st layout tab
(if (/= tabname "Model") ; skip if "modelspace"
(progn
(setvar "ctab" tabname) ; set to current layout tab
; get all blocks "X" "insert"
; filter on the 2 "Block name"
; extra filter on the 410 "layout" name only
(setq ss1 (ssget "x" (list (cons 0 "INSERT") (cons 2 bname)(cons 410 tabname))))
.... do your thing with the blocks that have been selected for this layout tab only.
(setq x (+ x 1)) ; increase x so get next layout
) ; repeat
(setq newtext1 "YOURTEXT") ;set argument to the text string you'd like to change the attribute to
(setq ss (ssget "_X" '((0 . "INSERT")))) ;gather selection set of inserted objects
(setq i -1) ;set a counter
(if ss ;if a selection set exists
(while (setq ent (ssname ss (setq i (1+ i)))) ;iterate through selection set, gathering info
(if (and (setq obj (vlax-ename->vla-object ent)) ;gather selection set entity names
(= (vla-get-objectname obj) "AcDbBlockReference") ;entity is a block
(= (vla-get-hasattributes obj) :vlax-true) ;block contains attributes
) ;end and
(progn ;if the above is true, do some things to that block entity
(setq attributes (vlax-invoke obj 'getattributes)) ;gather the block attributes
(foreach att attributes ;iterate through the block attributes
(if (or (= "YOURATTNAME1" (vla-get-tagstring att)) ;if the attribute matches the name you want
(= "YOURATTNAME2" (vla-get-tagstring att)) ;or if the attribute matches the other name you want
) ;end or
(progn ;if above is true do some things
(vla-put-textstring att newtext1) ;populate the attribute with the new text string
(vla-update att) ;update the attribute with new string
) ;end progn
) ;end if
) ;end foreach
) ;end progn
) ;end if
) ;end while
) ;end if
(defun LM:setattributevalue ( blk tag val / end enx )
(while
(and
(null end)
(setq blk (entnext blk))
(= "ATTRIB" (cdr (assoc 0 (setq enx (entget blk)))))
)
(if (= (strcase tag) (strcase (cdr (assoc 2 enx))))
(if (entmod (subst (cons 1 val) (assoc 1 (reverse enx)) enx))
(progn
(entupd blk)
(setq end val)
)
)
)
)
)
;;;my approach
(if (/= (getvar "ctab") "Model")
(progn
(LM:setattributevalue (ssname (ssget "X" '((410 . "02"))) 0) "PLANNO" "2113AL Standard")
(LM:setattributevalue (ssname (ssget "X" '((410 . "03"))) 0) "PLANNO" "2113AL Standard")
(LM:setattributevalue (ssname (ssget "X" '((410 . "04"))) 0) "PLANNO" "2113AL Standard")
(LM:setattributevalue (ssname (ssget "X" '((410 . "05"))) 0) "PLANNO" "2113AL Standard")
(LM:setattributevalue (ssname (ssget "X" '((410 . "06"))) 0) "PLANNO" "2113AL Standard")
(LM:setattributevalue (ssname (ssget "X" '((410 . "07"))) 0) "PLANNO" "2113AL Standard")
))
[code/]
(if (setq s (ssget "_x" '((0 . "insert")(2 . "DRHortonTBA") (66 . 1) (410 . "~model"))))
(foreach b (mapcar 'cadr (ssnamex s)) (lm:setattributevalue b "SHTNO" (getvar "ctab")))
)
(if (setq s (ssget "_x" '((0 . "insert")(2 . "DRHortonTBA") (66 . 1) (410 . "~model"))))
(foreach b (mapcar 'cadr (ssnamex s)) (lm:setattributevalue b "DATE" (ARCH:C_DATE-ISSUE (getvar "tdupdate"))))
)
(if (setq s (ssget "_x" '((0 . "insert")(2 . "DRHortonTBA") (66 . 1) (410 . "~model"))))
(foreach b (mapcar 'cadr (ssnamex s)) (lm:setattributevalue b "DRHNO" "2113AL V1 R0"))
)
(if (setq s (ssget "_x" '((0 . "insert")(2 . "DRHortonTBA") (66 . 1) (410 . "~model"))))
(foreach b (mapcar 'cadr (ssnamex s)) (lm:setattributevalue b "BPSNO" (substr (getvar "dwgprefix") 13 (- (strlen (getvar "dwgprefix")) 13))))
)
(if (setq s (ssget "_x" '((0 . "insert")(2 . "DRHortonTBA") (66 . 1) (410 . "~model"))))
(foreach b (mapcar 'cadr (ssnamex s)) (lm:setattributevalue b "PLANNO" "2113AL Standard"))
)
[code/]
Thanks for assisting in my absence Ron :)Anytime Lee 😁
...
("DATE" . "%<\\AcVar Date \\f \"MMMM d, yyyy\">%")
Need help with fields to update attributeYou have to esc the \ and " like so: "%<\\AcVar Date \\f \"M/d/yyyy\">%"
This field works:
("SHTNO" . "%<\\AcVar ctab>%")
This field does not work:
("DATE" . "%<\\AcVar date>%")
Or this:
("DATE" . "%<\\AcVar Date \f "MMMM d, yyyy">%")
Forgot to mention, that I tried that also.
The field will not update with the current date.
No, only a regen
Thanks
UPDATEFIELD is the way to go...and now I know and will start using fields.
Thanks guys
(setq arch#sern (substr (getvar "dwgprefix") 13 (- (strlen (getvar "dwgprefix")) 13)))
(if (/= (ssget "x" '((0 . "insert")(2 . "sc-96"))) nil)(setq arch#scms "Scale = 1/8\" = 1'- 0\""))
(setq l
(list
'("SHTNO" . "%<\\AcVar ctab>%")
'("DRHNO" . "2113AL V1 R0")
'("PLANNO" . "2113AL Standard")
'("DATE" . "%<\\AcVar Date \\f \"MMMM d, yyyy\">%")
'("SCALE" . "%<\\AcVar.17.0 Lisp.arch#scms \\f \"%tc3\">%")
'("BPSNO" . "%<\\AcVar.17.0 Lisp.arch#sern \\f \"%tc3\">%")
)
)
[code/]