Several times now I have been asked for Previous/Next page numbers on the title block. This is something that Electrical cannot do out of the box. However with a little scripting and the Title Block Update utility its very possible. So in this post you will get to see two things. Automatic Previous/Next page numbers and tying scripts to attributes using the Title Block Update utility.
The Previous / Next Page Number Issue
Some companies use a page numbering system where each group of drawings has a set series of page numbers. For example, The first five pages are for "power" followed by five pages of "controls", ect. For this type of numbering it would be very nice to see what the previous or next page numbers are. And it would be even better if AutoCAD Electrical could do this automatically.
So how can we get AutoCAD Electrical to figure these out and map the values to attributes on in title block? This is where a script comes into play. AutoCAD Electrical allows us to embed an AutoLISP expression into the mapping file (.wdt) and link it to a title block attribute. The returned value from this expression gets inserted as a text value in the linked attribute.
AutoCAD Electrical has a global variable named GBL_wd_prj_ixlst that carries a series of lists of various data for the drawings defined in the active project. One of these lists is a list of SHEET number assignments for all the drawings in the project. This is what the LISP utility will access to find the "previous" and "next" drawing sheet number assignments.
Where is this information stored? In the project's temporary database stored in the user subdirectory. This series of lists is from the FILETIME table.
(See image to the right)
Listed below is the script and some notes about what each line is doing. I don't know who to give credit for this script. It's online on several websites as well as on the Autodesk User Forums.
Download the lisp file and copy it to a folder that is listed in your ACAD search path.
(defun c:nextsheet ( / ix sheet_lst x sheet)
; Return the WD_M block's SHEET attribute value
; of "next" dwg in project. This embedded in a
; global called GBL_wd_prj_ixlst. If global
; doesn't exist, make call to refresh it.
(if (not GBL_wd_prj_ixlst)
(setq GBL_wd_prj_ixlst (c:ace_proj_data nil)))
; GBL_wd_cip holds index of current drawing in
; the overall project drawing list.
(setq ix GBL_wd_cip) ; index
; If index not defined for current drawing, then
; trigger a refresh of the global.
(if (OR (not ix)(= ix 0))
(setq ix (c:wd_is_cur_dwg_in_proj))
(setq sheet "")
(if (> ix 0)
(progn ; current drawing is in the project,
; increment to next dwg in list
(setq ix (1+ ix)) ; increment index
; Get list of SHEET numbers assigned to
; all dwgs in the project dwg set.
(setq sheet_lst (nth 3 GBL_wd_prj_ixlst))
; Use index number to pull out the
; target drawing's SHEET value. This is
; done by first finding the index
; number is a list of index numbers
; (nth 1 GBL_wd_prj_ixlst), and then
; using the position in this list to
; pull SHEET number from a parallel list
; of sheet numbers in (nth 3 GBL_wd_prj_ixlst)
(if (setq x (member ix (nth 1 GBL_wd_prj_ixlst)))
; found relative position of next
; dwg's data in parallel lists
(setq sheet (nth (- (length (nth 1 GBL_wd_prj_ixlst))
(nth 3 GBL_wd_prj_ixlst)))
sheet ; return "" or next SHEET value
The Title Block
Setting Up The Title Block Mapping
Run through the Title Block Setup utility to modify your existing mapping. If you have yet to setup any mapping, see this post... Title Block Update - The Basics
From the mapping dialog choose User Defined
Inside the User-Defined dialog, create the mapping for the NEXT and PREV attributes. Be sure to press Update List after creating each one.
This is the expression for both...
(if (setq x (findfile "Titleblock Update.lsp"))(progn(load x)(C:prevsheet)) " ")
(if (setq x (findfile "Titleblock Update.lsp"))(progn(load x)(C:nextsheet)) " ")
The Test Run
So the .lsp file is in place and the mapping's have their expressions so give it a try.