Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello, I have a routine developed that updates the attributes of my title block in numerical order, but I would like to optimize it to work by numbering the attributes in the order in which the tabs are arranged. It should also allow updating the names if I add a new tab in the middle or move one to a different position. My title block has two numbers: the current page number and the next page number. When it reaches the final page, it should display "--" for the next page number.
I am attaching a DWG as an example.
Thanks!
(defun sort-layout-names (layoutList)
"Sorts layout names in numerical and alphabetical order."
(vl-sort
layoutList
(function (lambda (a b)
(< (atoi a) (atoi b))
)
)
)
)
(defun c:UpdateBlockAttributesByLayout ( / layoutList layoutName currentLayout nextLayout blkName blkEnt attData attEnt attVal doc layouts)
(setq blkName "ROTULO") ; Block name
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ; Get the active document
(setq layouts (vla-get-Layouts doc)) ; Get the collection of layouts
(setq layoutList '()) ; Initialize the list of layouts
; Get the list of layout names
(vlax-for layout layouts
(setq layoutName (vla-get-Name layout))
(if (/= layoutName "Model") ; Exclude the model workspace
(setq layoutList (cons layoutName layoutList)))
)
; Sort the list of layout names numerically and alphabetically
(setq layoutList (sort-layout-names layoutList))
; Iterate over each layout and update the block attributes
(foreach layoutName layoutList
(setvar "ctab" layoutName) ; Switch to the current layout
; Find the block in the current layout
(setq blkEnt (ssget "X" (list (cons 0 "INSERT") (cons 2 blkName) (cons 410 layoutName))))
(if blkEnt
(progn
(setq attData (vlax-invoke (vlax-ename->vla-object (ssname blkEnt 0)) 'getattributes))
(foreach attEnt attData
(setq attVal (vla-get-tagstring attEnt))
(cond
((equal attVal "ATT1") ; Update the attribute "ATT1" with the current layout name
(vla-put-textstring attEnt layoutName))
((equal attVal "ATT2") ; Update the attribute "ATT2" with the name of the next layout or "--" if it is the last one
(setq nextLayout (cadr (member layoutName layoutList)))
(if nextLayout
(vla-put-textstring attEnt nextLayout)
(vla-put-textstring attEnt "--"))))
)
)
)
)
(princ "\nAll attributes updated successfully.")
(princ)
)
Solved! Go to Solution.