Lisp Calculated Sheet Numbering

Lisp Calculated Sheet Numbering

Anonymous
Not applicable
3,461 Views
7 Replies
Message 1 of 8

Lisp Calculated Sheet Numbering

Anonymous
Not applicable

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.

 

(defun C:tabnumber()

(setq acadObj (vlax-get-acad-object))
(setq doc (vla-get-ActiveDocument acadObj))
(setq tempLayout (vla-Item (vla-get-Layouts doc) (getvar "CTAB")))

(vla-get-taborder tempLayout)
)

Thanks for any help.

0 Likes
Accepted solutions (1)
3,462 Views
7 Replies
Replies (7)
Message 2 of 8

maratovich
Advisor
Advisor

How are your numbers created?
Is this text? Or do you use title blocks?
Can you attach the sample?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 3 of 8

Anonymous
Not applicable

It retrieves the tab name and then using the tab name (getvar “CTAB”) it gets the number the tab is on the bottom. I don’t have it in a title block or anything but if you put the code in autocad then run it it prints the number in the command bar. I just can’t figure a way to make a dynamic field that will display the number for each for each layout.

0 Likes
Message 4 of 8

dbhunia
Advisor
Advisor
Accepted solution

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....
0 Likes
Message 5 of 8

ronjonp
Mentor
Mentor

If you use sheet set manager for your plots the field %<\AcSm Sheet.Number \f "%tc1">% should work.

 

Although you still have to number them in sheet set manager.

0 Likes
Message 6 of 8

Anonymous
Not applicable

IT WORKED PERFECTLY!  Thank you so much!

0 Likes
Message 7 of 8

zania.davison
Community Visitor
Community Visitor

This is amazing, thank you. Is there a way to edit the code so that it will autofill the block with "C01, C02, C02" etc as opposed to "1,2,3" 

0 Likes
Message 8 of 8

Sea-Haven
Mentor
Mentor

Try this 

(defun C:tabnumber (/ layt_lst lay_list blk_name tag_name layname);;Put temp variables
(vl-load-com)
(setq blk_name "BLK_NAME"   ;;Put Title 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
      tab (getvar 'CTAB)
)
(vlax-for layt (vla-get-layouts (vla-get-ActiveDocument (vlax-get-acad-object)))
	(if (> (vla-get-TabOrder layt) 0)
	(progn
	  (setq lay_name (vla-get-name layt))
	  (setvar 'CTAB lay_name)
      (setq num (vla-get-TabOrder layt))
	  (if (< num 10) 
	    (setq strnum (strcat "C0" (rtos num 2 0)))
	    (setq strnum (strcat "C" (rtos num 2 0)))
	  )
      (setq ss (ssget "_X" (list '(0 . "INSERT")(cons 2 blk_name)(cons 410 lay_name))))
	  (setq obj (vlax-ename->vla-object (ssname ss 0)))
      (setq atts (vlax-invoke obj 'Getattributes))
        (foreach att atts
	    (if (= (vla-get-tagstring att) tag_name)
	     (vla-put-textstring att strnum)
	    )
	    )
    )
	)
)
(setvar 'ctab tab)
(princ)
)
(C:tabnumber)
0 Likes