VBA Plotting Page Setups

VBA Plotting Page Setups

Anonymous
Not applicable
4,095 Views
9 Replies
Message 1 of 10

VBA Plotting Page Setups

Anonymous
Not applicable
Ok, here is what I am trying to do. Using AutoCAD Mech. 2005

User opens up a drawing, a listbox pops-up and lists all the Page Setups within that drawing. The user can then select which Page Setup he wants to Preview or Plot.

Everything I have read tells me to use the following code(Showed Print Preview code only):

Dim PlotConfigurations As AcadPlotConfigurations
Dim Plot As AcadPlot
Dim Activelayout As AcadLayout

Set PlotConfigurations = ThisDrawing.PlotConfigurations
Set Plot = ThisDrawing.Plot
Set Activelayout = ThisDrawing.Activelayout
Activelayout.CopyFrom PlotConfigurations.Item(lstName.Value) 'lstname.value is the user selected Page Setup

Activelayout.RefreshPlotDeviceInfo
ThisDrawing.Regen acAllViewports
Plot.DisplayPlotPreview acFullPreview


This code 'usually' works for the first Plot Preview that you do, or the first PlotToDevice. If I try and Preview or Plot the next user selected Page Setup, it defaults to 8-1/2 x 11, Landscape. Even if the Page Setup is a DSIZE paper, different Printer, ect. If I print it, it will go to the printer defined in the Page Setup, but the paper size and orientation will be wrong.

These Page Setups work fine when using the AutoCAD native PLOT window.

It is like the copyfrom command is not resetting all the variables.

Any help would be greatly appreciated. I have been banging my head for a week now trying different things.

Peter
0 Likes
4,096 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable
Use different variable names from the default property names on ThisDrawing. It is really confusing to see: Set Activelayout = Activelayout Activelayout.CopyFrom PlotConfigurations.Item(lstName.Value) 'lstname.value is the user selected Page Setup I can't even tell from that if ThisDrawing.ActiveLayout or your ActiveLayout variable is being used without running the code. In this case they are both the same thing but ThisDrawing.ActiveLayout always returns the current layout object in AutoCAD while your variable could be referring to a different layout (if it changed after setting the variable). I'm not entirely sure what you are trying to do but here is your code modified to plot preview all the page setups: Sub test() Dim oPlotConfig As AcadPlotConfiguration For Each oPlotConfig In ThisDrawing.PlotConfigurations ThisDrawing.Activelayout.CopyFrom oPlotConfig Activelayout.RefreshPlotDeviceInfo ThisDrawing.Regen acAllViewports ThisDrawing.Plot.DisplayPlotPreview acFullPreview Next End Sub Hope this helps. - Jorge "Peterg" wrote in message news:16109497.1102373023785.JavaMail.jive@jiveforum2.autodesk.com... > Ok, here is what I am trying to do. Using AutoCAD Mech. 2005 > > User opens up a drawing, a listbox pops-up and lists all the Page Setups > within that drawing. The user can then select which Page Setup he wants > to Preview or Plot. > > Everything I have read tells me to use the following code(Showed Print > Preview code only): > > Dim PlotConfigurations As AcadPlotConfigurations > Dim Plot As AcadPlot > Dim Activelayout As AcadLayout > > Set PlotConfigurations = ThisDrawing.PlotConfigurations > Set Plot = ThisDrawing.Plot > Set Activelayout = ThisDrawing.Activelayout > Activelayout.CopyFrom PlotConfigurations.Item(lstName.Value) > 'lstname.value is the user selected Page Setup > > Activelayout.RefreshPlotDeviceInfo > ThisDrawing.Regen acAllViewports > Plot.DisplayPlotPreview acFullPreview > > > This code 'usually' works for the first Plot Preview that you do, or the > first PlotToDevice. If I try and Preview or Plot the next user selected > Page Setup, it defaults to 8-1/2 x 11, Landscape. Even if the Page Setup > is a DSIZE paper, different Printer, ect. If I print it, it will go to > the printer defined in the Page Setup, but the paper size and orientation > will be wrong. > > These Page Setups work fine when using the AutoCAD native PLOT window. > > It is like the copyfrom command is not resetting all the variables. > > Any help would be greatly appreciated. I have been banging my head for a > week now trying different things. > > Peter
0 Likes
Message 3 of 10

Anonymous
Not applicable
Hi Jorge, thx for the code cleanup, but I am still having the exact same problems using your code or mine.

This method works fine when you have similiar Page Setups, ie. Same paper size and orientation.

I have drawings with totally different Page setups, ie. different paper sizes, orientations, plotters, ect.

So, I step through your code on a sample drawing, the first 4 Page setups work great, but when it comes across a Page Setup that changes paper size I get "Method 'DisplayPlotPreview' of Object 'IAcadPlot' failed".

So, I tested it on a different drawing, again works fine while dealing with similiar Page setups until it get a Page Setup that switches plotter (different .pc3 file). It does not switch orientation and stays with the 8-1/2 x 11" paper size.

Some how the variables for paper size and orientaion are not being set correctly. They stay the same as the Activelayout that the drawing was opened with.

I hope that is not too confusing of an explanation.

I guess I could try an invoke the PLOT window and use it to plot off my Page setups, but I had a hard time with the Endcommand or Endplot. It would work ok if I was plotting off one Page setup, but tended to screw up if I plotted multiple Page Setups.

Peter
0 Likes
Message 4 of 10

Anonymous
Not applicable
FYI - I sent my code to a Autodesk tech. It works fine on his AutoCAD 2005 (non-Mech) setup.

So, he is trying to determine if this is an AcadM 2005 problem.

Will keep you posted.

Peter
0 Likes
Message 5 of 10

Anonymous
Not applicable
Well, I am now back to square1.

The AutoDesk Tech said my code worked fine on his ACADM 2005.

The exact same code does not work fine on my ACADM 2005.

I am running Acad SP1.1 with Windows 2000. I even tried it on an XP machine here, same thing, does not work.

If anyone has created a Custom VBA Plotting program that will print off 'Page Setups' involving different printers, paper sizes, ect. Please reply to this message.

Peter
0 Likes
Message 6 of 10

Anonymous
Not applicable
Peter, Here's the only workaround I found for similar problems.... What I found when changing the plot area in my code was that I had to open and close the PageSetup dialog in order for the print area to change on screen (and in the plot). I did a hack like: [code] .CenterPlot = true 'the settings you're changing SendKeys "{ENTER}" ThisDrawing.SendCommand ("pagesetup" & vbCr) [/code] Occasionally the ENTER key doesn't get sent to the dialog and the dialog is left hanging open (if I hit a key between starting my code and when it gets to this point), but my work is all in-house so it's no big deal. We just hit ENTER to close the dialog box and the macro continues on. One way to tell if this will help you is to stop your code just after you make your changes, and then manually open and close the pagesetup dialog box. If the print area adjusts itself, then this snippet will help you. HTH, James "Peterg" wrote in message news:15250666.1102428222788.JavaMail.jive@jiveforum2.autodesk.com... > Hi Jorge, thx for the code cleanup, but I am still having the exact same problems using your code or mine. > > This method works fine when you have similiar Page Setups, ie. Same paper size and orientation. > > I have drawings with totally different Page setups, ie. different paper sizes, orientations, plotters, ect. > > So, I step through your code on a sample drawing, the first 4 Page setups work great, but when it comes across a Page Setup that changes paper size I get "Method 'DisplayPlotPreview' of Object 'IAcadPlot' failed". > > So, I tested it on a different drawing, again works fine while dealing with similiar Page setups until it get a Page Setup that switches plotter (different .pc3 file). It does not switch orientation and stays with the 8-1/2 x 11" paper size. > > Some how the variables for paper size and orientaion are not being set correctly. They stay the same as the Activelayout that the drawing was opened with. > > I hope that is not too confusing of an explanation. > > I guess I could try an invoke the PLOT window and use it to plot off my Page setups, but I had a hard time with the Endcommand or Endplot. It would work ok if I was plotting off one Page setup, but tended to screw up if I plotted multiple Page Setups. > > Peter
0 Likes
Message 7 of 10

h_s_walker
Mentor
Mentor
I've written a program that does exactly what you want BUT it only works in AutoCAD LT, its called Multiplot and you can find it at www.caddepot.com on page 4 of the AutoCAD LT sub directory. It uses dynamic data exchange so if you want me to see if I can change it to work on your system send me a screenshot with your program running to hswalker@hotmail.com, and I'll see what I can do.

Howard Walker
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Left Handed and Proud

0 Likes
Message 8 of 10

Anonymous
Not applicable
Update:

I have been dealing with an AutoDesk Reseller Tech, so far no luck with the bugs in the copyfrom cmd.

But, I have been able to use the built-in PLOT successfully as a work-around.

Thanks for all your help and suggestions. I will keep you up to date if I find any solution.

btw - I am using ACADM in the Inventor Series 9 suite.

Peter
0 Likes
Message 9 of 10

Anonymous
Not applicable
Update:

I still have not found a solution to the copyfrom bug. The Autodesk reseller confirmed and submitted the bug to Autodesk.

Has anyone else come across this problem? If so, please let me know if you have found a solution.

Thanks

Peter
0 Likes
Message 10 of 10

Anonymous
Not applicable
Peter,
I don't see any reason why your code wouldn't work. So I am throwing this out there simply as something else to try. I don't have Mechanical to try it myself. Note the only real difference is the ".Add" statement.

Dim objLayout As AcadLayout
Dim PlotConfig As AcadPlotConfiguration
Set PlotConfig = ThisDrawing.PlotConfigurations.Add(PSetup)

Set objLayout = ThisDrawing.ActiveLayout
objLayout.CopyFrom PlotConfig

Robert
0 Likes