AUTO RENAMING PAGE NUMBER IN LAYOUTS

AUTO RENAMING PAGE NUMBER IN LAYOUTS

Shanky1999
Enthusiast Enthusiast
2,142 Views
12 Replies
Message 1 of 13

AUTO RENAMING PAGE NUMBER IN LAYOUTS

Shanky1999
Enthusiast
Enthusiast

Is there a lisp available to auto-rename the page numbers, they are in a block. I have tried various codes from the forum, but none seem to work. I just have to change the highlighted text. 5 OF 24.

Shankychorge_0-1674079173795.png

 

0 Likes
Accepted solutions (2)
2,143 Views
12 Replies
Replies (12)
Message 2 of 13

pendean
Community Legend
Community Legend
How would the LISP know it's a 5 not a 3 or 8 for example? What is the trigger?
0 Likes
Message 3 of 13

Shanky1999
Enthusiast
Enthusiast

It would take the layout page number and put it in the sheet# tag

0 Likes
Message 4 of 13

ВeekeeCZ
Consultant
Consultant

Perhaps THIS could help.

0 Likes
Message 5 of 13

pbejse
Mentor
Mentor

This is an odd name for a block  "TITLE_BLOCK_INFORMATION_NEW_OCT 19-2010" , if the name of the block varies from one drawing to another, best soluton to this is to use field values as posted by @ВeekeeCZ. That way it would not be dependent on the block name 

 

Of course you may still need to run a program whenever you add or delete a layout tab, could be at the middle or the end. [ startapp/reactors ]. and will that tbe always be "P##" ? also need to change the layout name in case  a new sheet is inserted in the middle.

 

What of the drawing #? should that be changing as per sheet number? M225184.04 P1

 

0 Likes
Message 6 of 13

Shanky1999
Enthusiast
Enthusiast

No there is no need to change the drawing name.

0 Likes
Message 7 of 13

Shanky1999
Enthusiast
Enthusiast

Block name does not vary from drawing to drawing.

0 Likes
Message 8 of 13

Shanky1999
Enthusiast
Enthusiast

Tried this already don't work.

0 Likes
Message 9 of 13

maratovich
Advisor
Advisor

num.PNG

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

pbejse
Mentor
Mentor

@Shanky1999 wrote:

-No there is no need to change the drawing name.

-Block name does not vary from drawing to drawing.


Here's a Q&D demo code for you to test.

(defun c:demo ( / _padzero aDoc tblk SheetOf i tabName f attb data plen pstab)
(defun _padzero (n l)
	(while (< (strlen n) l)
  		(setq n (strcat "0" n))
	)
  n)		 
(setq aDoc (vla-get-ActiveDocument (vlax-get-acad-object))  
      SheetOf (strcat " OF " (itoa (length (layoutlist)))))
  		
(if (setq tblk (ssget "_X" '((2 . "TITLE_BLOCK_INFORMATION_*"))))
	  (progn
	    (repeat (setq i (sslength tblk))
	      (setq TabName
		     (Cdr (assoc 410 (entget (setq e (ssname tblk (setq i (1- i)))))
		       )
		     )
	      )
	      (setq pstab (Vla-item (vla-get-layouts aDoc) TabName))
	      (setq Data (cons (list (vla-get-taborder pstab)
				     pstab (vlax-ename->vla-object e)) data
			 )
	      )
	      (vlax-put	pstab 'Name (strcat TabName "_" (itoa (caar data)))
	      )
	    )
	    (setq data (vl-sort data '(lambda (a b) (< (car a) (car b)))))
	    (setq plen (strlen (itoa (length data))))

	    (while (setq a (Car data))
	      (vla-put-name (cadr a)
		(strcat "P" (_padzero (itoa (car a)) plen))
	      )
	      (vl-some
		'(lambda (at)
		   (if (eq (vla-get-tagstring at) "SHEET#")
		     (vla-put-textstring at (strcat (itoa (car a)) SheetOf))
		   )
		 )
		(vlax-invoke (last a) 'GetAttributes)
	      )
	      (setq data (cdr data))
	    )
	  )
  )(princ)
  )

HTH

 

 

0 Likes
Message 11 of 13

paullimapa
Mentor
Mentor
Accepted solution

here's a version of TABNUMBER.lsp that uses FIELDS. Check out your dwg attached after running TABNUMBER

 

; tabnumber function given block name & attribute tag name 
; will cycle through all layouts & input the following 2 fields onto the attribute tag value:
; first field is layout order # and second field is total # of layouts
; Since fields are used, these will automatically update when layouts are added or deleted
; as well as when layouts are moved to a different sequence order
; For example, when the matching block attribute tag name is found, it'll place the following:
; 3 OF 4 
; 3 is field equals 3rd order in layout sequence
; 4 is field equals total number of layout tabs
; Note: Fieldeval is set to 31 so a save, regen or plot will update the field value
; modified from:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-auto-page-number-layout-tabs/m-p/10199097#M413381
(defun c:tabnumber (/ _put _lay2fld a blk_name ctab e fld i n s tag_name tabnam)
  (vl-load-com)
  (alert"Running TabNumber")
  (setvar"fieldeval"31)
; _lay2fld returns a field value per current layout tab's order number
; modified from lay2fld
; https://forums.augi.com/showthread.php?170740-Getting-the-number-of-a-layout-tab
 (defun _lay2fld (/ doc lay ids id1 id2)
  ;;------------------------------------;;
  ;; Tharwat - Date: 03.Dec.2017	;;
  ;;------------------------------------;;
  (defun ids (obj doc / uty)
    (if (vlax-method-applicable-p
          (setq uty (vla-get-utility doc))
          'getobjectidstring
        )
      (vla-getobjectidstring uty obj :vlax-false)
      (itoa (vla-get-objectid obj))
    )
  )
       (setq doc (vla-get-activedocument (vlax-get-acad-object))
             lay (vla-get-layouts doc)
             id1 (ids (vla-item lay (getvar 'ctab)) doc)
             id2 (ids lay doc)
       )
       (strcat
           "%<\\AcObjProp Object(%<\\_ObjId " id1 ">%).TabOrder>%"
           " OF " "%<\\AcExpr %<\\AcObjProp Object(%<\\_ObjId " id2
           ">%).Count>%-1 >%"
       )
  )
  (defun _put (blk tag val)
    ; when find matching attribute tag name replace with field string value
    (vl-some
       '(lambda (x) (and (equal (vla-get-tagstring x) (strcase tag)) (vla-put-textstring x val)))
      (vlax-invoke blk 'getattributes) ; get all attributes returns as a list
    )
  )
  ;; Edit below to match with block name and attribute tag name
  (setq	blk_name "TITLE_BLOCK_INFORMATION_NEW_OCT 19-2010" ; "YOURTITLEBLOCKNAME"
        tag_name "SHEET#" ; "YOURATTRIBUTETAG"
        ctab (getvar"ctab") ; save current layout
  )
  (setq i (itoa (length (layoutlist))))
  (vlax-for l (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
    (setq a (cons (list (vla-get-name l) (vla-get-taborder l)) a))
  )
  (if (setq s (ssget "_A" (list '(0 . "INSERT") (cons 2 blk_name) '(66 . 1))))
    (foreach b (mapcar 'cadr (ssnamex s))
      (if (setq n (cadr (assoc (setq tabnam(cdr (assoc 410 (entget b)))) a)))
       (progn
        (setvar "ctab" tabnam) ; make block inserted on layout current
        (setq fld (_lay2fld))  ; get field value
        (_put (vlax-ename->vla-object b) tag_name fld)
       )
      )
    )
  ) ; if block found
  (if(equal (getvar"ctab") ctab) ; chk if current layout is original
   (command"_.Regen") ; regen to update fields
   (setvar"ctab"ctab) ; return to original layout
  ) ; if
  (alert"TabNumber Completed")
  (princ)
) ; defun tabnumber

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
Message 12 of 13

Shanky1999
Enthusiast
Enthusiast
Accepted solution

Thank you so much, It works as expected.

0 Likes
Message 13 of 13

paullimapa
Mentor
Mentor

You are welcome...glad to have helped...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes