Unable to set Paper Size through VBA

Unable to set Paper Size through VBA

zhuanqiang.tan
Participant Participant
1,465 Views
5 Replies
Message 1 of 6

Unable to set Paper Size through VBA

zhuanqiang.tan
Participant
Participant

Hi,

 

Please save me...

 

I'm trying to plot 60,000 dwgs to pdf, and when i use the default driver (DWG to PDF.pc3) and CanonicalMediaName to set the paper size to ANSI expand B (please see below) the plotter still defaulted to the ANSI full bleed paper size.

 

PtConfig.ConfigName = "DWG to PDF.pc3"

PtConfig.CanonicalMediaName = "ANSI_expand_B_(11.00_x_17.00_Inches)"

 

 

My internal AutoCAD expert showed me how to change the Plotter's default paper size, AND then in Options to "Use the plot device paper size". I rebooted AutoCAD and noted the settings DID change in AutoCAD, but somehow when i run the VBA code i'm still getting full bleed. Does anyone know why my options aren't taking effect? Thank you.

 

Plotter Paper Size default screenshot.PNG

Options - Use Plot Device Paper Size.PNG

 

 

0 Likes
1,466 Views
5 Replies
Replies (5)
Message 2 of 6

zhuanqiang.tan
Participant
Participant

Just an update for everyone. I was able to "workaround" this problem. Before i share the solution, i'd still appreciate anyone who can enlighten me on why i was not able to set the paper size via CanonicalMediaName. It's so annoying...

 

And here's the "workaround". i put quotes around "workaround" because what i ended up with is probably a better solution. i ended up saving a Page Setup with all the configurations i need, and then just having the code pick the setup. And voila, it works and i can leave work on time tonight.

 

Set PtConfigs = ACAD.ActiveDocument.PlotConfigurations

Set PtConfig = PtConfigs.Item("Winfab")

 

 

 

Page Setup solution.PNG

0 Likes
Message 3 of 6

Ed__Jobe
Mentor
Mentor

If you have that many drawings to process, I highly recommend that you get Bluebeam Revu for CAD. It has a bactch processing tool that can override page setups.

Ed


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.
How to post your code.

EESignature

0 Likes
Message 4 of 6

zhuanqiang.tan
Participant
Participant

Hi Ed, thanks for the feedback here. It's good to learn of a new tool. But do you by any chance know why i wasnt able to set up the paper size via VBA in the first place?

0 Likes
Message 5 of 6

Ed__Jobe
Mentor
Mentor

You didn't show your code, but did you apply the settings to ActiveLayout? I only see that you created a PlotConfig. I don't know if it was used to plot with.

Ed


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.
How to post your code.

EESignature

0 Likes
Message 6 of 6

parkovaya1JX4QX
Community Visitor
Community Visitor

This will work. The trick is that the names are not equivalent!

NewLayout.GetLocaleMediaName(mediaNames(x)) <> mediaNames(x)

In this example, instead of "A1" I have the name like "user000"

So to set CanonicalMediaName="A1" you first need to find it by comparison

 

    Dim NewLayout As AcadLayout
    Dim mediaNames As Variant
    
    Set NewLayout = ThisDrawing.Layouts("Layout1")
    
    With NewLayout
        .ConfigName = "Default Windows System Printer.pc3" 
        .RefreshPlotDeviceInfo
    End With
    
    ' List all the media names, and their localized version
    mediaNames = NewLayout.GetCanonicalMediaNames()
    
    For x = LBound(mediaNames) To UBound(mediaNames)
        'Debug.Print mediaNames(x)
        'Debug.Print NewLayout.GetLocaleMediaName(mediaNames(x))
        If NewLayout.GetLocaleMediaName(mediaNames(x)) = "A1" Then '!important
            MediaName = mediaNames(x)
            Exit For
        End if
    Next
    
    NewLayout.CanonicalMediaName = MediaName
0 Likes