Hi
As you asked......
@Anonymous wrote:
Hi All,
I am attempting to create a field that would calculated the sheet number from the order of the layout tabs. I was able to program a command that would accomplish the calculation, but am struggling to find a way to get it to apply the code to populate title block. The code below is what I was able to come up with to find the sheet number.
............................
From your post what I get...... You want to update the Sheet Number as the Order of Layout Tabs in Title Block.....
Now, while its a Title Block ....... there has an Attribute Tag for Sheet Number (which you want to update).......
If I am right try this.......(change the highlighted field in code)......
(defun C:tabnumber (/ layt_lst lay_list blk_name tag_name layoutname);;Put temp variables
(vl-load-com)
(setq blk_name "BLK_NAME" ;;Put Titel Block Name in place of "BLK_NAME" as per your drawing
tag_name "NO" ;;Put Att Tag Name of sheet number in place of "NO" as per your drawing its case sensitive
l -1
tab (getvar 'CTAB)
)
(vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
(if (> (vla-get-TabOrder layt) 0)
(setq layt_lst (cons (cons (vla-get-TabOrder layt) (vla-get-Name layt)) layt_lst))
)
)
(setq layt_lst (vl-sort layt_lst '(lambda (x y) (< (car x) (car y)))))
(foreach layt layt_lst
(setq layoutname (cons (cdr layt) layoutname))
)
(setq lay_list (reverse layoutname))
(repeat (length lay_list)
(setq lay_name (nth (setq l (+ l 1)) lay_list))
(setvar 'CTAB lay_name)
(setq ss (ssget "_A" (list '(0 . "INSERT")(cons 2 blk_name)(cons 410 lay_name))))
(repeat (setq NOS (sslength ss))
(vlax-for blk (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))
(if (= (vla-get-Name blk) blk_name)
(progn
(setq obj (vlax-ename->vla-object (ssname SS (setq NOS (- NOS 1)))))
(foreach att (vlax-invoke Obj 'GetAttributes)
(if (= (vla-get-Tagstring att) tag_name)
(progn
(vla-put-textstring att (+ 1 (vl-position lay_name lay_list)))
)
)
)
)
)
)
)
)
(setvar 'CTAB tab)
(princ)
)
Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....