VBA Plotting Page Setups

Discussion in 'AutoCAD' started by Peterg, Dec 6, 2004.

  1. Peterg

    Peterg Guest

    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
     
    Peterg, Dec 6, 2004
    #1
  2. Peterg

    Jorge Lopez Guest

    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
     
    Jorge Lopez, Dec 6, 2004
    #2
  3. Peterg

    Peterg Guest

    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
     
    Peterg, Dec 7, 2004
    #3
  4. Peterg

    Peterg Guest

    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
     
    Peterg, Dec 7, 2004
    #4
  5. Peterg

    Peterg Guest

    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
     
    Peterg, Dec 7, 2004
    #5
  6. 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)
    
    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



    problems using your code or mine.
    sizes, orientations, plotters, ect.
    work great, but when it comes across a Page Setup that changes paper size I
    get "Method 'DisplayPlotPreview' of Object 'IAcadPlot' failed".
    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.
    correctly. They stay the same as the Activelayout that the drawing was
    opened with.
    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.
     
    James Belshan, Dec 7, 2004
    #6
  7. Peterg

    hwalker Guest

    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 , and I'll see what I can do.
     
    hwalker, Dec 8, 2004
    #7
  8. Peterg

    Peterg Guest

    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
     
    Peterg, Dec 10, 2004
    #8
  9. Peterg

    Peterg Guest

    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
     
    Peterg, Feb 2, 2005
    #9
  10. Peterg

    Kerbo1969 Guest

    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
     
    Kerbo1969, Feb 3, 2005
    #10
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.