Monday, January 14, 2013

AutoCAD Electrical's Title Block Update - Previous / Next Sheet Numbers

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

imageSome 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.

The LISP

Click here to download Title Block Update.lsp

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. image

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))
                (length x))
                   (nth 3 GBL_wd_prj_ixlst)))       
      )
  ) )
   
  sheet  ; return "" or next SHEET value
)

The Title Block

Really all that's needed are two additional attributes for the "Previous" and "Next" page numbers. Below is an image of my updated title block.
image

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
image

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)) " ")

image

The Test Run

So the .lsp file is in place and the mapping's have their expressions so give it a try.

NOTE: When running the Title Block Update utility be sure to uncheck the Resequence sheet values box! If this is left checked ALL sheets will be automatically renumbered.
image

17 comments:

  1. I've copied the lsp file to the ACADE Support folder for my install, and added the user defined data for the NEXT attribute, but i still get nothing. Is the PREV attribute needed even if it isn't being used?

    ReplyDelete
    Replies
    1. Probably should've included the commandline:

      Interpreting as AutoLisp: (IF (SETQ X (FINDFILE "TITLEBLOCK UPDATE.LSP"))PROGN(LOAD X)(C:NEXTSHEET)) " ")
      Error: syntax error

      Delete
    2. got it. what's listed is missing a ( before the PROGN. should show as

      (IF (SETQ X (FINDFILE "TITLEBLOCK UPDATE.LSP"))(PROGN(LOAD X)(C:NEXTSHEET)) " ")

      then it works.

      Delete
  2. Robby,
    You are right! I did this while writing the blog post. I don't see how this happened.
    I have updated the text with the missing ('s.

    Thank you so much for posting the bug and then the fix!

    ReplyDelete
  3. I have followed this tutorial and I cannot get the next sheet to update. PLEASE HELP!!

    ReplyDelete
  4. You should be able to find my e-mail from the profile link above. Send me some step by step screen shots showing your workflow and I'll look it over.

    ReplyDelete
  5. Thanks for sharing,, im not notice the update..

    AutoCAD Tutorial

    ReplyDelete
  6. With havin so much written content do you ever run into any problems
    of plagorism or copyright violation? My blog has a
    lot of unique content I've either authored myself
    or outsourced but it seems a lot of it is popping
    it up all over the internet without my authorization.
    Do you know any methods to help reduce content from being stolen?
    I'd truly appreciate it.

    Have a look at my web blog; website template for a school; ,

    ReplyDelete
    Replies
    1. Your blog address was deleted as spam. Maybe repost it in a slightly different format to keep the spam filters from killing it. Or ask Mufasu how he posts his…
      That said… plagiarism is a hard topic. A lot of my scripts come from someone at Autodesk or from Nate Holt’s old blog. I’m not that great at LISP. I try to always give credit where its due and point to websites for answers if they’re out there instead of creating a new post. Unfortunately ACADE is a fairly scarce topic online right now.

      If someone is charging money for something you created, you may have legal cause but at what cost? Sigh… people don’t understand how big a deal this violation is until they have personally spent hours on a project only to see someone else take credit for it.

      Delete
  7. To be clear, when running the Title Block Update, you should be updating just the NEXT & PREV mappings, right?

    (I mean you could do other fields, but for this to work you MUST update those two.)

    ReplyDelete
  8. This is mixed in with all of the other attribute mappings. This NEXT/PREV thing is not something that needs to be run alone.

    ReplyDelete
    Replies
    1. Yeah. Just figured that out. (No place to check them.)

      It isn't working yet, but hopefully I'll figure out what i messed up tomorrow. Thanks for your help!

      Delete
  9. I need your help..

    I want to create A3 size title block with my company logo and name. Which can be same like as saved in templet of title block in autocad. Which can automatic update it sheet number, source destination arrow, component tag, and wire numbers project wide.

    please give me steps.

    ReplyDelete
    Replies
    1. The titleblock is simply a normal AutoCAD block. To get the sheet number to update you need to read this post... http://myacade.blogspot.com/2013/01/autocad-electrical-title-block-update.html
      The rest should automatically work if your using AutoCAD Electrical. Do you need the S/D arrows, component tags, and wire numbers to be tied to the drawing's sheet number?

      Delete
  10. Thanks! This was helpful for a LISP routine I was making that figures out the latest rev letter and date to populate the Titleblock and assist with the information gathering for the Drawing List Report.

    ReplyDelete
  11. It looks like it is running the code correctly but not seeing a sheet number to change it. Here is what the command line feedback says:
    "Using title block attribute mapping file C:\Users\tlane\Documents\AcadE
    2012\AeData\proj\MISC NFPA\MISC NFPA.wdt...
    Interpreting as AutoLisp: (IF (SETQ X (FINDFILE "TITLEBLOCK
    UPDATE.LSP"))(PROGN(LOAD X)(C:PREVSHEET)) " ")")
    PREVSHEET (no change)
    Interpreting as AutoLisp: (IF (SETQ X (FINDFILE "TITLEBLOCK
    UPDATE.LSP"))(PROGN(LOAD X)(C:NEXTSHEET)) " ")
    NEXTSHEET (no change)"

    Any ideas? Is there any way to pull up the project data to see what it has in there?

    ReplyDelete
    Replies
    1. If I put a value manually into the prevsheet or next sheet the command will overwrite it with nothing. I did go into the project database in ms access and it had the correct information in the table.

      Delete

Note: Only a member of this blog may post a comment.