AutoCAD/pagesetup in lisp
Expert: Bill DeShawn - 4/20/2010
QuestionQUESTION: Greetings,
I'm trying to find a way to set a single (current) layout tab to a predefined page setup brought in either by inserting a "template" drawing or through the use of -psetupin. I don't want user input. Can you help?
Bruce
ANSWER: Bruce:
Sure. I'll give it a try. Sounds like you might be a CAD mgr that is trying to design a way that everyone on your team will be able to just plot one way every time. Is that correct? Can you give me your version of AutoCAD. What discipline? Electronics? Architectural? Manufacturing? Civil?
Bill DeShawn
---------- FOLLOW-UP ----------
QUESTION: Greetings Bill,
Well, CAD Mgr of sorts - Manager of one me - the problem I have is that I have been blessed with going through 2000+ drawings for this project and they have a history that dates back 5-6 years and they are all over the place as far consistency is concerned. I had planned on using a script/lisp combo through scriptpro, but scince I have to go back into each drawing again anyway to correct the viewports (if any) and scaling, I plan on putting a cleanup lisp routine behind a button with a routine like: ^C^C(if (not cleaner) (load "cleaner"));cleaner.
Thank you for the help
ANSWER: I have some time to help you with this today. So, what is the name of the layout you want to use for this? Will it be Layout1? or do you have a different name to use each time? Will their be multiple layouts in your drawings? Are you going to be selecting your layout before starting the command or do you want to start the command from the model tab? Will you ever be using this command from model tab or only from a layout? What are the parameters? CTB or STB file name? PC3 file name? paper size? Scale?
Please get back to me and let me know.
Bill DeShawn
http://my.sterling.net/~bdeshawn
---------- FOLLOW-UP ----------
QUESTION: By default (initially) it will be named LAYOUT1. The lisp routine that I am trying to imbed this line of code will rename the tab later to a SHT # of # (numbers are user input) then using strcat I bring everything together and rename the tab.
There is usually only one layout tab (I say this cause I haven't been through the entire set yet) and is, so far, on the layout tab when entering the drawing. There will only be one layout tab in the drawing and it will have a page setup called 22x34 (with an actual size of 24x36) - screwy I know, but I need to plot the outer line of the title block and it is a full 22x34.
My current lisp routine makes sure I'm in tilemode 0 before going through my current method of assigning the page setup to the tab, which is:
(command "-PLOT" "N" TN1 PS1 "HPDJ-750C.pc3" "N" "Y" "N")
TN1 = Tab name, PS1 = Page setup name (22x34), and HPDJ-750C.pc3 is an fictious plotter generated to eliminate any size errors during the plot statement. I don't have a full size plotter available to me, so I have to make believe :)
Now, using the plot method of assigning the page setup works to a certain degree, but it will not update the display to reflect the new setup - I still have to go into "pagesetup" mode and set 22x34 as current, even though it says it is current.
Currently these are all using the monochrome CTB - I'll be changing that at a later date when I actually take full ownership of this drawings.
Answer;I changed TN1 to "Layout1" and set (with setq) PS1 to "Setup1", created a fake plotter like you did
;and ran it. It ran without error.
(defun c:bruce1 ()
(command "-PLOT" "N" "Layout1" PS1 "HPDJ-750C.pc3" "N" "Y" "N")
)
(defun c:bruce2 ()
;Is TN1 a global variable you already set in another routine?
;(setvar "ctab" TN1);not sure this is nec.
(command "-PLOT" "N" "Layout2" PS1 "HPDJ-750C.pc3" "N" "Y" "N")
)
(defun c:bruce3 ()
(command "-PLOT" "N" "Layout3" PS1 "HPDJ-750C.pc3" "N" "Y" "N")
)
(defun c:bruce4 ()
(command "-PLOT" "N" "Layout4" PS1 "HPDJ-750C.pc3" "N" "Y" "N")
)
of course these need to be edited to plot to the real plotter
and to proceed with the plot
so far, very basic. Load one file. Four plotted sheets are
at your disposal. Each function name corresponds with the layout name.
all sheets use the same page setup which includes the ctb file of your choice.
Now this method is OK, but if you want to automatically create the page setup, you can do that by creating the page setup in another file, keep it handy for importing, and user the _.-insert command to bring it into the drawing and then cancel before choosing an insertion point.
(first make sure there is not Setup1 page setup then run:
(command "_.-insert" "psup1" ^c) "Setup1" is to be in that drawing.
Of course you can also run -psetupin which will ask you if you want overwrite if the selected page setup already exists.
I think we're on the same page so far. How would you want this changed?
Bill DeShawn
http://my.sterling.net/~bdeshawn