PDA

View Full Version : setting pagesetups in autocad



ccastelein
08-01-2005, 02:24 PM
Does anyone have and info or code, in vba, on setting up PAGESETUPS in autocad... i looked and all i can find is setting the path of the file to bring in the setups.....but how do you set one if its already in the template file?

just wondering.
ccatelein:think:

Tommy
08-03-2005, 06:16 AM
Hi ccatelein,

Not sure what you want here, I have no clue on how to setup a page layout for plotting, but I can show you how to load linetypes, create layers etc. Let me know what you are looking for, and I'll try to find out ok?

ccastelein
08-05-2005, 06:29 AM
hey tommy,

well within autocad your able to setup pages (paperspace layout tabs). These layouts define the printer, size of paper, .ctb file to use, scale, etc... and then name it... That way if you publish a set of drawings you can use a PageSetup on all the sheets and it will print using the info defined in the PageSetup.

PageSetups have been available since Autocad 2000 at least. Im currently using ADT6 and trying to set an already defined PageSetup but unable to find anything in VBA about it. other than redefining the path to the PageSetup drawing you can import from.

any help?
ccastelein

Tommy
08-05-2005, 07:00 AM
I think you are looking for the AcadLayout class. It seems to have all the properties you are looking for. I have not worked with this before, as a matter of fact I just tried using the paperspace last weekend for the first time. I'll look at it this weekend and see what I can come up with. But from the documentation it looks like you can setup paperspace layouts anyway you would like, change papersize, plotter/printer, margins, etc. :)

MikeS
08-12-2005, 11:40 AM
Any luck with this? I need help with this too.

Tommy
08-12-2005, 02:08 PM
The only thing I have come up with is the plotter configurations. Seems kinda strange that you can specify everything else but you can't grab the page setup name, or set it, through code. I found some lisp routines that says it can do it, look for pagesetup.lsp that is as far as I have gotten.

Tommy
08-15-2005, 08:14 AM
Setting pagesetups, it is the plotter configuration. the example below will give the "pagesetup name". Sometimes it is just to simple LOL.

Sub pLOTcONFIG()
Dim P As AcadPlotConfiguration
Dim PL As AcadPlotConfigurations
Set PL = ThisDrawing.PlotConfigurations
For Each P In PL
MsgBox P.Name
Next
End Sub

ccastelein
08-15-2005, 05:32 PM
Thanks Tommy,
ill look at first thing tomorrow.

ccastelein

ccastelein
09-06-2005, 02:42 PM
ok tommy,

finally got to it... weeks later...as usual ive tried a bunch of things but cant get it to work:

Dim PGS As AcadPlotConfiguration
sheetname = "LargeDoc 30x42{24x36}": Set PGS = ThisDrawing.PlotConfigurations(sheetname)


cant quite seem to set a pre-defined pagelayout to the current layout tab.
any ideas?
:p

Tommy
09-06-2005, 02:50 PM
:) Yes I have it at home though. I will post in a couple of hours.
As a side note I was also looking into making a pagesetup if it doesn't exist, it sets the page size, plotter, ctb file, what to plot, scale. It is ment to setup a drawing when you first open it from scratch with the choices that you make. I'll be back soon just didn't want you to think I was not here :)

Tommy
09-06-2005, 04:02 PM
ccastelein,
The page setup name needs to exist. This program is using "Most".
This what works for me in 2000i:

Public CurPltCnfg As AcadPlotConfiguration
Public Function ChckFrPltCnfg(iName$) As Boolean
Dim Plt As AcadPlotConfiguration
For Each Plt In ThisDrawing.PlotConfigurations
If Plt.Name = iName Then
Set CurPltCnfg = Plt
ChckFrPltCnfg = True
Exit Function
End If
Next
End Function
'
Public Sub SetPltCnfg()
Dim Plt As AcadPlotConfiguration
For Each Plt In ThisDrawing.PlotConfigurations
If ChckFrPltCnfg("Most") Then '<-page setup name
MsgBox "Pages seup name has been set"
End If
Next
End Sub

ccastelein
09-16-2005, 03:05 PM
hhmmmm,
i must be pretty basic...im kinda looking for a very basic command...something like this:
dim CurPltCnfg as AcadPlotConfiguration
dim PageName as string

PageName = "ANYTHING HERE"
set CurPltCnfg = PageName

how come things cant be that easy...why does there always have to be FOR EACH ..NEXT stuff in vba...drives me crazy

in otherwords, im not haveing much success at this page setup thing...
ccastelein

Tommy
09-17-2005, 10:58 AM
LOL the problem is I think is the page setup name doesn't exist. So it will not work. The code you posted will work if it exist. For Each is basically a search on the items that are there, that way you don't have any errors that jump up out of nowhere. So if you do the for each and it wasn't there you would know to make it, or you could do error checking if an error occurs fix it either way. If you fell like messing with it I could post what I have for a pagesetup sub but it is real messy, not documented, I could go for days so I'll just say it isn't ready for someone to look at. but if you want to I will post. I'm just warnig you cause it gets real deep real fast :) I was suprised.

MikeS
09-19-2005, 05:23 AM
Sounds to me you may be trying to come up with a way to batch plot a set of drawings. I'll attach a routine I wrote, but it only plots the layout tab the drawing was saved in. Hope it helps.

ccastelein
09-19-2005, 11:32 AM
Well, i wish my above simple code worked but it doesnt...it tells me i have a type mismatch with pagename.. havent looked at the batchplot.zip file yet... but i will..to see if i can glean something from it...
ccastelein

Tommy
09-19-2005, 01:06 PM
This is what needs to be changed to make a "page setup"

ThisDrawing.ModelSpace.Layout.ConfigName = "Printer"
ThisDrawing.ModelSpace.Layout.CanonicalMediaName = "Legal"
ThisDrawing.ModelSpace.Layout.UseStandardScale = True
ThisDrawing.ModelSpace.Layout.StandardScale = acScaleToFit
ThisDrawing.ModelSpace.Layout.PlotRotation = ac90degrees
ThisDrawing.ModelSpace.Layout.PlotType = acExtents
ThisDrawing.ModelSpace.Layout.StyleSheet = "acad.ctb"



The zip file has more information for setting up a page/plotter configuration, still rather rough though.

The reason you are having a mismatch with pagename is it is not a plotter configuration, it is a string looks like it was supposed to be a name

Tommy
09-20-2005, 09:12 AM
I wish to apologize to any readers for the unacceptable language in the posted file. It has been deleted.

Thank You

ccastelein
09-20-2005, 02:35 PM
Tommy, i beleive i have found the answer ive been looking for and the reason why ive been so frustrated with PageSetups..
http://discussion.autodesk.com/thread.jspa?messageID=4793445

vba dosent expose the PreDefined PageSetups.... it lets you add them but you cant set them...( unless you care to prove me wrong..which i hope you can do)
looks like i can do it via Lisp...
ill let ya know how i do.
ccastelein

ccastelein
09-20-2005, 02:44 PM
heres the code to the lisp file, pretty simple: (may help you to get it in vba):
(defun CurrentPlotConfig (strLayout / layts layt pconfig )
;;; this function is used with vba.
;;; vba does not expose Page Setup Name. It is stored
;;; as the (1 . "name") of (100 . "AcDbPlotsettings") subgroup
;;; of the "ACAD_LAYOUT" named object dictionary.
(setq layts (dictsearch (namedobjdict) "acad_layout"))
(setq layt (dictsearch (cdar layts) strLayout))
(setq pconfig (cdr (assoc 1 layt)))

Tommy
09-20-2005, 02:54 PM
LOL on the 8-12 post I said something about lisp being able to do it. Thank you for posting this, I will be looking into it :thumb . The part I am not sure of is at one time while fumbling through this I did set the page name someway but all of a sudden it didn't work:dunno On another note have you looked at vlisp? You have advanced debugging, looks a lot like the old turbo c debugger works similar (at least it used to).

Once again thanks :)

ccastelein
10-31-2005, 03:46 PM
Ok tommy, im back, (long time!)
heres what ive found out...
I got acad to set the Pagesetup via lisp...called from vba. (i pass an argument [the pagesetup name] to the lisp)
UNFORTUNATELY, after setting it to the papersetup i want that has the paper size i want, it wont "regen" to update the piece of paper in paperspace... pagesetup says its set but graphically it hasnt... the only way i can get it to do it is to actually enter the pagesetup command and set it and close... then graphically it updates... :( oh well.

Heres my vba code: (all two lines of it!!)

Dim PageSetup As String
PageSetup = """LargeDoc 24x36{24x36}""": ThisDrawing.SendCommand "(psetup " & PageSetup & ") "


Heres the Lisp code:
ALL CREDITS OF THE LISP HAVE REMAINED.

; Jason Piercey . May 16th, 2003
; assign a pagesetup to a layout
; [layout] - string, layout name
; [setup] - string, pagesetup to assign
; return: T or nil
; modified by chris castelein 10-31-05
; to pass paper size as an argument.
; original prompt code left in and remarked out.
(defun putPagesetup (layout setup / layouts plots)
(defun item-p (collection item)
(if
(not
(vl-catch-all-error-p
(vl-catch-all-apply
'(lambda () (setq item (vla-item collection item))))))
item
)
)
(and
(or *acad* (setq *acad* (vlax-get-acad-object)))
(or *doc* (setq *doc* (vla-get-activedocument *acad*)))
(setq layouts (vla-get-layouts *doc*))
(setq plots (vla-get-plotconfigurations *doc*))
(setq layout (item-p layouts layout))
(setq setup (item-p plots setup))
(not (vla-copyfrom layout setup))
)
)
(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)

; Return: list of all pagesetups defined in the current drawing or nil
(defun getPagesetups ()
(massoc 3 (dictsearch (namedobjdict) "Acad_PlotSettings"))
)
; Jason Piercey . May 19th, 2003
; assign pagesetup to layout(s)
; LIMITED testing
; written for Shawn McDonald
(defun psetup (page / lst res)
(setq lst (mapcar 'strcase (getPagesetups)))
(while (not page)
;(setq page (strcase (getstring T "\nspecify pagesetup to apply: ")))
(if (or (= "" page) (not (member page lst)))
(progn (princ "\npagesetup not found") (setq page nil))
)
)
(initget "All Current")
;(if(not(setq res (getkword "\n[All/Current]apply pagesestup to which layout(s) <all>: ")))
;(setq res "All")
(setq res "Current")
;)
(if (= "All" res)
(foreach x (vl-remove "Model" (layoutlist)) (putPagesetup x page))
(putPagesetup (getvar "ctab") page)
)
(princ "\nFinished")
(princ)
)



Hope this helps you and somebody else!
I already have my next question for ya tommy.. so look for my next post soon ;)
ccastelein

zenwest
11-01-2005, 03:45 PM
This will create a page setup in autocad 2000-2002, and send the plot
with the config

Dim acadapp As Object
Dim AutoCAD As Object
Dim activedocument As Object
Dim Thisdrawing As AcadDocument 'as Object
Dim plotsObj As AcadPlotConfigurations
Dim plotObj As AcadPlotConfiguration
'On Error Resume Next

Set acadapp = GetObject(, "autocad.application")
Set Thisdrawing = acadapp.activedocument
'this is a "short"cut, to making autoCAD save a plotconfig (page setup) in 2000 2002
'You don't have to send the plot to make it add your settings, but I did to be sure it
'fully refreshed and stayed in the drawing.
'the confusion is the naming in autocad, a page set up is a "plotconfiguration"
'saved (added) under the name prop of the object but in acad,
'the config property is just the device, and no page setup exists as an
'object named that (2000)

'This is the object method for sending multiple windows to
'a plot configuration plot, the plotconfig looks for the view created
' as you redefine and delete the view, from views creating from rectang bounding boxes
'you can the send multiple areas of the same view name
Apptivate 'extended appactivate function
'Set plotObj = Thisdrawing.PlotConfigurations.plotconfiguration
'On Error Resume Next
'Creates a page setup (plotconfiguration), while it is ordering the
'drawing.layout to plot to a device of the same settings, mirrored by the plotconfig
'creation
' doubled these set properties, because I had certain things that
'were not behaving properly until I did this
Thisdrawing.PlotConfigurations.Add "TESTPC2", True
Thisdrawing.ActiveLayout.ConfigName = "\\WLB-TUC3\HP (file://\WLB-TUC3HP) Color LaserJet 8550"
Thisdrawing.PlotConfigurations.Item("TESTPC2").ConfigName = "\\WLB-TUC3\HP (file://\WLB-TUC3HP) Color LaserJet 8550"
Thisdrawing.ActiveLayout.StyleSheet = "HP1050annex-half.ctb"
Thisdrawing.PlotConfigurations.Item("TESTPC2").StyleSheet = "HP1050annex-half.ctb"
Thisdrawing.ActiveLayout.CanonicalMediaName = "Letter"
Thisdrawing.PlotConfigurations.Item("TESTPC2").CanonicalMediaName = "Letter"
Thisdrawing.ActiveLayout.StandardScale = acScaleToFit
Thisdrawing.PlotConfigurations.Item("TESTPC2").StandardScale = acScaleToFit
Thisdrawing.ActiveLayout.CenterPlot = True
Thisdrawing.PlotConfigurations.Item("TESTPC2").CenterPlot = True
Thisdrawing.ActiveLayout.ViewToPlot = "XPLOT"
''Thisdrawing.PlotConfigurations.Item("TESTPC2").ViewToPlot = "XPLOT"
Thisdrawing.ActiveLayout.PlotType = acView
'Thisdrawing.PlotConfigurations.Item("TESTPC2").PlotType = acView
'Thisdrawing.ActiveLayout.
Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo
Thisdrawing.PlotConfigurations.Item("TESTPC2").ViewToPlot = "XPLOT"
Thisdrawing.PlotConfigurations.Item("TESTPC2").PlotType = acView
Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo
Thisdrawing.PlotConfigurations.Item("TESTPC2").RefreshPlotDeviceInfo
'Thisdrawing.ActiveLayout.s
'Thisdrawing.PlotConfigurations.Add "TESTPC2", True
Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo
Thisdrawing.Plot.PlotToDevice "\\WLB-TUC3\HP (file://\WLB-TUC3HP) Color LaserJet 8550" '"TESTPC2"
Thisdrawing.ActiveLayout.RefreshPlotDeviceInfo
'Thisdrawing.Plot
'THIS CREATES THE PAGE SETUP- THEN RUN SEND COMMAND TO SEND THIS
'LIKE, PICK RECTANG, CREATE VIEW, CREATE PAGE SETUP (PLOTCONFIG) WHICH REFS THE VIEW,
'SEND PLOT WITH SENDKEYS, DELETE VIEW, REPEAT.
'Thisdrawing.Plot.DisplayPlotPreview acFullPreview
'Thisdrawing.PlotConfigurations.Item("K").

ccastelein
11-01-2005, 05:27 PM
Hello zenwest,

Lotsa code there... let me clarify the problem...
I dont need to create a pagesetup...the file has all the pagesetups it needs.
and i dont need to send a plot...

all i want to do is set a layout tab to use a pre-defined pagesetup.
it seems VBA wont allow you to do that. Though lisp will ...to an extent.
im able to set a tab to use the pagesetup i want but it wont refresh the on screen graphics paper size after i set it. the Pagesetup dialog box says it is useing the correct pagesetup but it doesnt "show" it.

you would think it would be something as simple as:
thisdrawing.activelayout.plotconfiguration = "pagesetupnamehere" :dunno
but no.

heres the scenario:
open new drawing...go to paper space...insert titleblock of 24x36 size...
set paperspace tab (or layout) to use pre-defined pagesetup...

thats it.
let me know if you think it can do something that simple.
ccastelein

zenwest
11-01-2005, 08:54 PM
I will try to do it in vba next, but here is the non detailed -plot command version of sendcommand, maybe this will work as on my drawing, where it refreshed the predefined pages





Private Sub Command3_Click()
Dim AutoCAD As AcadApplication
Dim Thisdrawing As AcadDocument 'as Object
Set acadapp = GetObject(, "autocad.application")
Set Thisdrawing = acadapp.activedocument

Thisdrawing.SendCommand "-PLOT" & vbCr & _
"N" & vbCr & _
vbCr & _
"2436" & vbCr _
& vbCr _
& "No" & vbCr _
& "yes" & vbCr _
& "no" & vbCr _

'command text: -PLOT
'Thisdrawing.SendCommand "-PLOT" & vbCr & _
'"N" & vbCr & _ ='Detailed plot configuration? [Yes/No] <No>:
'vbCr & _ ='Enter a layout name or [?] <Layout1>:
'"2436" & vbCr _ ='Enter a page setup name <811>: 2436
' & vbCr _ ='Enter an output device name or [?] <HP 1050C LDD3.pc3>:
'& "No" & vbCr _ ='Write the plot to a file [Yes/No] <N>:
'& "yes" & vbCr _ ='Save changes to layout [Yes/No]? <N> y
'& "no" & vbCr _' ='Proceed with plot [Yes/No] <Y>: n

End Sub

Tommy
11-02-2005, 07:37 AM
ccastelein,
I think your problem is you are working in "Model" you may need to be in "Layout" for the plot configurations/page setups. Its just a guess. The only reason I am saying anything is because I could set it in Model but when I created it it was in layoust and I haven't revisited so just a view point :)

ccastelein
11-02-2005, 12:14 PM
Zenwest,
Yeah, ive seen the posts for using the -plot command...not really interested in that. my posted solution works for the most part.. just disappointed it wont refresh.

Tommy,
no im in paper space alright... i think im going to have to wait for autodesk to enable what i want to do in VBA for their future releases of Acad. gives them something to do, and tease us with new "features" and improvements.
im just disappointed they came so close and didnt finish it.

but now im going to post a new question for ya.. so look for a new thread.
im going to post it with out doing any research into it yet... maybe you guys know the answer and save me some time.:whip :p
ccastelein

HardEng
11-03-2006, 03:26 PM
This will Import a Page setup.

Private Sub CommandButton1_Click()
Me.Hide
ThisDrawing.SendCommand "filedia" & vbCr & "0" & vbCr
ThisDrawing.SendCommand "-psetupin" & vbCr & "C:\YourPath\Your.dwg" & vbCr & "DWF_36X24_48" & vbCr 'enter the correct path, dwg name, and 'page setup to import
ThisDrawing.SendCommand "filedia" & vbCr & "1" And vbCr
End Sub

10west
11-03-2006, 10:03 PM
...What I was doing, I found out, that If you insert a paperspace block, into paperspace (won't work in model), the block inserts with the page setups into pspace. But for some reason, they would be off, until you opened and previewed in a plot, for me anyways. So it kind of defeated part of the purpose for a batch plot, but anyways...
I have seen that command pass by the command line on plots, or something. But I learn something new about cad every hour, that I should know already. Thanks, that command! I have to read all the sysvars and commands. I haven't tried it, but It looks like it will work. The page setup is so powerful and convenient, too bad it's not well supported in VB, but there is always a way. Thanks,

lsddotms

lucas
11-04-2006, 08:21 AM
If you already have one paperspace layout set up the way you want it, why not just copy it?

HardEng
11-04-2006, 12:54 PM
update after more testing...

Private Sub CommandButton1_Click()
Me.Hide
ThisDrawing.SendCommand "filedia" & vbCr & "0" & vbCr
ThisDrawing.SendCommand "-psetupin" & vbCr & "C:\YourPath\Your.dwg" & vbCr & "DWF_36X24_48" & vbCr & "Yes" & vbcr 'enter the correct path, 'dwg name, and 'page setup to import.
ThisDrawing.SendCommand "filedia" & vbCr & "1" & vbCr
End Sub