PDA

View Full Version : Custom Field - Sheet 1 of 31, Sheet 2 of 31, etc



jeepinaround
2005-01-31, 07:24 PM
I have searched and searched for a topic on Customizing Fields. I want to make a custom field that is Sheet 1 of 31 and it populates with the sheet it is and how many sheets total for that set. Can anybody point me in the right direction?

Glenn Pope
2005-01-31, 07:38 PM
The easiest way of doing this is with using the sheet set manager. You would make 2 attributes; one for the page number and the other for the set number. "Sheet" & "of" would be just plan text. The attribute for page number will have a field linked to the page number property the the ssm gives. The set number will be a custom field that you would add to the ssm properties.

Check out these threads for working with the sheet set manager.

How do I get fields working with SSM? (http://forums.augi.com/showthread.php?t=4238)

Setting up a Sheet Set (http://forums.augi.com/showthread.php?t=4208)

envision.phil
2009-01-02, 01:43 AM
I have tackled this without sheet sets.
I figured that every sheet (layout) has a separate title block and that the number of title blocks = the number of sheets. (If this is not the case for you then this solution will not work).
I then used some lisp code that was suggested on the Autodesk discussion site
http://discussion.autodesk.com/forums/message.jspa?messageID=5902018
-----------------------------------------------------------------------------------------------------------------------
(defun C:THINGCOUNT ()
(setvar "cmdecho" 0)
(setq sa (ssget "x" (list (cons 0 "INSERT")(cons 2 "THING"))))
(setq thingcount (sslength sa))
(princ)
)
---------------------------------------------------------------------------------------------------------------------
###NOTE : REPLACE THE WORD "THING" WITH THE NAME OF YOUR TITLE BLOCK
---------------------------------------------------------------------------------------------------------------------
I added this code to the end of a LISP that I use regularly for other drawing parameters to be set up for plotting, but you could just run it on the default start-up lisp that runs when AutoCad opens. The advantage that I gained by adding it to a lisp that I had assigned to a button was that, using the CUI, I called up the function and added a regen as well (this will ensure that the field value updates whenever I push the button).

Finally just follow the instruction as explained on the link;
---------------------------------------------------------------------------------------------------------------------
now use the FIELD command (or right click over TEXT/MTEXT to insert FIELD behavior to it), use Category 'Other', Fieldname LispVariable and select thingcount (the routine var). the field will pull that count value.
--------------------------------------------------------------------------------------------------------------------

It's not perfect for everyone's scenarios, but it does work.

irneb
2009-01-19, 11:31 AM
Congrats on your 1st post ... and that being an answer instead of a question ... nice one. Your idea is good, I like the ease of use ... however ....

The problem here is that the LSP file needs to be loaded, otherwise there is no thingcountlisp variable to link to. So if someone else opens the DWG the field will display #####.

If you don't want to use Sheet Sets, place that sheet count into your Drawing Properties. You can create a custom property ... call it SheetCount ... or whatever takes your fancy. Then change you code to look something like this (changes marked in red):
(defun C:THINGCOUNT (/ sa thingcount doc si)
(setvar "cmdecho" 0)
(setq sa (ssget "x" (list (cons 0 "INSERT") (cons 2 "THING"))))
(setq thingcount (sslength sa))
(vl-load-com)
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object))) ;Get vla-object of current doc
(setq si (vla-get-SummaryInfo doc)) ;Get vla-object of summary info of doc
(if (vla-GetCustomByKey si "SheetCount")
(vla-SetCustomByKey si "SheetCount" (itoa thingcount))
(vla-AddCustomInfo si "SheetCount" (itoa thingcount))
)
(princ)
)Now there should be a SheetCount property under the Document category for fields. The nice thing here is you can open the DWG without needing to load & run your code every time since it's loading the sheet count from something that's saved inside the DWG itself ... not simply a volatile global variable.

danielbritt
2009-02-10, 04:59 PM
I added 2 attributes in my title block (ex: page XX of YY)

The XX variable is a field that AutoCAD provides (SheetNumber) and I created a sheet set custom field called total pages so I manually count the sheets and populate the total sheets field in the top level sheet set.

Capt. Computer Crasher
2009-03-03, 08:21 PM
Here is a link to a thread where a solution was derived to a single file with multiple layout tabs each containing a title block.

http://forums.augi.com/showthread.php?t=95873

eptownie1988
2018-06-14, 03:57 PM
irneb:

I am a little confused as to where the code is placed? I made a new Document Field called Total Sheets with a default value of #### but how do I associate the code you modified with the Total Sheets field?

Thank you

eptownie1988

rkmcswain
2018-06-14, 07:23 PM
I am a little confused as to where the code is placed?


The code can be in any .lsp file. It needs to be loaded in order for it to execute.
IOW - the lisp code populates the drawing property, which in turn is read by the field.

So the code can live anywhere, just make sure the function is loaded into memory before trying to call the "THINGCOUNT" function.

Tom Beauford
2018-06-14, 09:30 PM
Lee Mac has lisp for this as well: http://www.lee-mac.com/layoutfield.html