Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

VBA Plotting

778 views
Skip to first unread message

Jacob Dinardi

unread,
Jul 24, 1999, 3:00:00 AM7/24/99
to
I developed a plotting interface, to simplify things around the office. The
only settings required are plot scale and dwg size. I made a plot preview
available also. Everything else hardcoded internally (plot origin, plotter,
ect.). The problem is I can only get an 8.5 x 11 inch area to plot. The
preview looks fine, and if I run the plot interface, make select the plot
scale, and dwg size, then CANCEL it, and open ACAD's plot dialog, all the
settings I have hardcoded and the scale and paper size are all reflected
there. If I then just press OK, it plots fine. I can't figure why it will
not work from the vba interface. Has anyone else experienced anything
similar? Anyone have any suggestions? I'd really appreciate it.

Thanks,
jake

Minkwitz Design Service

unread,
Jul 26, 1999, 3:00:00 AM7/26/99
to
Jake,
If you make changes in the plotter dialogue, then cancel out, those changes
shouldn't be reflected if you restart the plotter dialogue. Are you sure that
when you cancel out of your interface, that you are not plotting on "leftover"
settings from the last time? Try using AcadPlotConfiguration.GetWindowToPlot and
see if the window your grabbing is actually being reflected in acad's plotter
dialogue.
Although I haven't tried any of this yet, I've been planning to do the same
thing your doing, most probably for the same reasons. So this interests me.
Please keep me posted as to wether or not you are actually getting your settings
into acad's plot dialogue.

thanks,
-Josh

Jacob Dinardi

unread,
Jul 26, 1999, 3:00:00 AM7/26/99
to
Josh,
To respond to what you posted - Yes I'm sure my settings are being
reflected by Acad's plot dialog. The most apparent way to see it is open a
dwg. D-size for example, switch into Layout mode and make sure everything
looks correct (the border fits the layout ect.). Now I run the plot
interface and intentionally set the paper size to ANSI-A and preview the
plot (I have it set up to regen the drawing prior to the preview). You can
see that the border is way too small. Close the preview (still inside the
interface though) and now if you look at your drawing you can see the layout
space is too small as well. Cancel the plot interface and the layout remains
that way. Hence unless you provide code in the plotting interface to cancel
the settings you just made they remain, unlike Acad's plot dialog. So like I
said, you would think that it would work, but it doesn't. I hope someone can
tell me why I can only get a small area to plot from a setup that previews
correctly.

jake

Jacob Dinardi wrote in message <7nd6lr$ij...@adesknews2.autodesk.com>...

Denis Gagné

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to
Hi all,

I'm not sure to understand the question but it looks like someone is trying
to set the papersize with the GetPaperSize method instead of using the
CanonicalMediaName property. Maybe the help file could be more specific on
the possible values of this property?

Note that the only bug I'm aware of is that the GetPaperSize method does not
seem to consider the PaperUnits value and always returns millimeters (on our
systems it may depend of the Reg. Settings).

Maybe this piece of code will help you to fix your plotting routine:

'----------------------------------------
' This example sets the name of the
' media for the active layout to A3
' and retrieves the papersize
' DGagne 99-09-27
Sub SetPaperSize()
Dim PaperWidth As Double
Dim PaperHeight As Double
Dim MediaName As String

MediaName = "A3"

With ThisDrawing.ActiveLayout
.CanonicalMediaName = MediaName
.PaperUnits = acInches 'Try to set units to inches
.GetPaperSize PaperWidth, PaperHeight
End With

' Even if you want inches
' you'll get millimeters #@?&!

MsgBox "The media for the active layout is: " & _
MediaName & Chr(10) & "The papersize is " & _
CStr(PaperWidth) & "mm X " _
& CStr(PaperHeight) & "mm"

ThisDrawing.Regen acActiveViewport

End Sub
'----------------------------------------

Salutations,

Denis

Minkwitz Design Service

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to
Jake,
I'm far enough along in my plot dialogue now to exactly what your talking
about. I'm having the same problem. Nothing runs, except 8 1/2 X 11. I've tried
it a couple of ways. Both user defined sizes and standard. I'm assuming we are
both going about this the same way. Here is a sample of my code using a couple
of different attempts for comparison. If you figure out the problem, please post
and I'll do the same.
-Josh

Private Sub MyDevice()


Dim PaperWidth As Double
Dim PaperHeight As Double

With ThisDrawing
If PrinterBox.Text = "Laserjet" Then
.ActiveLayout.ConfigName = "HP Laserjet 5L PCL"
PaperWidth = 8.5
PaperHeight = 11
.ActiveLayout.GetPaperSize PaperWidth, PaperHeight
ElseIf PrinterBox.Text = "Cannon" Then
.ActiveLayout.ConfigName = "Canon Bubble-Jet BJC-4550"
PaperWidth = 8
PaperHeight = 6
.ActiveLayout.GetPaperSize PaperWidth, PaperHeight
ElseIf PrinterBox.Text = "Plotter" Then
.ActiveLayout.ConfigName = "DesignJet 600.pc3"
.ActiveLayout.GetPaperSize 35.5, 120#
End If
End With
End Sub

Jacob Dinardi

unread,
Jul 27, 1999, 3:00:00 AM7/27/99
to
Yep sounds real familiar. I've tried in similar ways, what you have been
trying. Right now I'm setting just about every possible property through
code and still getting the same thing 8 1/2 x 11. I even tried changing the
plotter's default papersize to see if it would make a difference, and it
didn't. I'm also assuming it's not a plotter specific problem now that I've
seen your code ( I have been trying this on an HP Design jet). My best guess
is that it's a bug. I'll post my code when I get a chance, I'm home now and
don't have access to it. Good luck Josh! (and everyone else).

Cheers,
jake

Minkwitz Design Service wrote in message <379E2EF3...@xta.com>...

Minkwitz Design Service

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Thanks Denis,
I'm having a bit of trouble setting CanonicalMediaName to a user-defined
papersize, but I have now been able to preview different paper sizes. So I think
you put us on the right track. As per your problem with units, try Const
acenglish = 0 for standard and Const acmetric = 1 for metric. I haven't verified
it yet , but this should be how you set your drawing units. I believe paperunits
is probably for paperspace and may not be what your looking for. Please correct
me if I'm wrong.... I'll need to know for sure very soon.
-Josh

p.s.- there is also acPlotPaperUnits, which I haven't reviewed yet.


"Denis Gagné" wrote:

> Hi all,
>
> I'm not sure to understand the question but it looks like someone is trying
> to set the papersize with the GetPaperSize method instead of using the
> CanonicalMediaName property. Maybe the help file could be more specific on
> the possible values of this property?
>
> Note that the only bug I'm aware of is that the GetPaperSize method does not
> seem to consider the PaperUnits value and always returns millimeters (on our
> systems it may depend of the Reg. Settings).
>
> Maybe this piece of code will help you to fix your plotting routine:
>
> '----------------------------------------
> ' This example sets the name of the
> ' media for the active layout to A3
> ' and retrieves the papersize
> ' DGagne 99-09-27
> Sub SetPaperSize()

> Dim PaperWidth As Double
> Dim PaperHeight As Double

Denis Gagné

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
After a closer look, the return value unit being in mm is not a bug.

From AutoCAD help file:
All ActiveX Automation properties are represented in millimeters or radians,
regardless of the units settings.

Denis

Minkwitz Design Service

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Heres the latest...User-defined papersizes won't take. I error out with "invalid
input". I may be able to get around that by modifying an existing size...I
haven't tried yet. But no matter which papersize I select for the designjet
plotter it errors out with "invalid input". Does the printer have to be a
windows system printer..ie-no pc3 files?

Private Sub MyDevice()


Dim PaperWidth As Double
Dim PaperHeight As Double
Dim MediaName As String

With ThisDrawing.ActiveLayout


If PrinterBox.Text = "Laserjet" Then

.ConfigName = "HP Laserjet 5L PCL"
PaperWidth = 8.5
PaperHeight = 11

.GetPaperSize PaperWidth, PaperHeight
MediaName = "Letter"


ElseIf PrinterBox.Text = "Cannon" Then

.ConfigName = "Canon Bubble-Jet BJC-4550"

PaperWidth = 11
PaperHeight = 17
.GetPaperSize PaperWidth, PaperHeight
MediaName = "Legal"


ElseIf PrinterBox.Text = "Plotter" Then

.ConfigName = "DesignJet 600.pc3"
PaperWidth = 35.5
PaperHeight = 120
.GetPaperSize PaperWidth, PaperHeight
MediaName = "ANSI E"
End If
.CanonicalMediaName = MediaName
End With
End Sub

-Josh

Minkwitz Design Service

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Denis,
    Sorry about the confusion. the getpapersize was a leftover that I thought I had commented out but evidently didn't. The problem is as follows:

With ThisDrawing.ActiveLayout
    If PrinterBox.Text = "Laserjet" Then
        .ConfigName = "HP Laserjet 5L PCL"

        MediaName = "Letter"                            'this works

    ElseIf PrinterBox.Text = "Cannon" Then
        .ConfigName = "Canon Bubble-Jet BJC-4550"

        MediaName = "User-defined size"       'this does not, I can't set MediaName to a user-defined size

    ElseIf PrinterBox.Text = "Plotter" Then
        .ConfigName = "DesignJet 600.pc3"

        MediaName = "ANSI E"       'this does not work either, I can't set MediaName at all if ConfigName is a pc3 file instead of a windows printer

    End If
    .CanonicalMediaName = MediaName
End With
End Sub

If I run the code just as you see it, I get an "invalid input" error with either of the last two options. GetPaperSize is commented out in my code. Looking at your code, I'm assuming that you are able to set ConfigName to a pc3, which puts me at a loss as to what I'm doing wrong. I even tried changing the default paper size in my pc3. If you see the error of my ways, please let me know. If not, suggestions are welcome.

-Josh

"Denis Gagné" wrote:

Josh - I'm afraid you do not use the GetPaperSize
method the way it should be. You don't even need this method to set the
paper size but only to check what it is.

First set the Config (plotter device and paper)
then you can use the GetPaperSize method if needed

Here's a complete example that shows the sequence you should follow:

'----------------------------------------
' This example sets the name

' of the Config plotter to
' DWF Classic.pc3
' and the name of the

' media for the active layout to

' ANSI_B_(17.00_x_11.00_Inches)
' Then it checks the papersize in mm
' DGagne 99-09-28
Sub SetPaperSize()

Dim PaperWidth As Double
Dim PaperHeight As Double
Dim MediaName As String

MediaName = "ANSI_B_(17.00_x_11.00_Inches)"

With ThisDrawing.ActiveLayout
  .ConfigName = "DWF Classic.pc3"
  .CanonicalMediaName = MediaName

  .GetPaperSize PaperWidth, PaperHeight
End With

' Even if you specify inches
' you'll always get millimeters

MsgBox "The media for the active layout is: " & _
    MediaName & Chr(10) & "The papersize is " & _
    CStr(PaperWidth) & "mm X " _
    & CStr(PaperHeight) & "mm"

ThisDrawing.Regen acActiveViewport

End Sub
'----------------------------------------

Denis

Minkwitz Design Service a écrit dans le message
<379F3746...@xta.com>...

Denis Gagné

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to

Jacob Dinardi

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to

Lotsa stuff going on today. Denis - I have been using the
cannonicalmedianame prop to specify the papersize, and localemedianame to
display it in a combo box.

'
'TO DISPLAY SIZES IN A COMBO BOX
'
Size = myPlotConfig.GetCannonIcalMediaNames()
i = 0
For i = LBound(Size) to UBound(Size)
frmMain.cboSize.AddItem myPlotConfig.GetLocaleMediaName(Size(i))
Next i
'
'TO SET SIZES
'
myPlotConfig.CannonIcalMediaName = Size(frmMain.cboSize.ListIndex)

There may be a better way to do it this is how I figured it out though. It
works. Anyway check this out guys... In the past month of struggling with
this problem this is what I have figured out. There are 3 ways to plot
basicly.

1.Create a layout object.
2.Create a PlotConfiguration object
3.Use "ThisDrawing.blah.blah.blah"

Anyway you look at it, it's all about the same. I have just been trying to
plot from model space so far (mainly). Today by chance I was working on my
plot interface while I had a drawing open with some user-defined
configurations. Now when I went to plot my drawing later (using ACAD) I
wanted to add a new configuration for a small laserjet plotter, with a scale
to fit setting. Inside the add dialog box, there was my plot configuration
name from my interface, except it was attached to "Layout", not "Model". So
I got all excited and went back to work on my plotting interface. No matter
what I do though I cannot create the plot configuration attached to model
space. And to top that off, it still plots incorrectly in paperspace (layout
whatever) I believe this has something to do with it all. I found an
interesting help topic in the vba developers guide under plotting... "When
you plot from model space, the defaults that are used, IF THERE ARE NO
SETTINGS SPECIFIED, include plot to system printer, plot the current
display, scaled to fit, 0 rotation, and 0 origin. To modify the plot
settings change the LAYOUT OBJECT ASSOCIATED TO MODEL SPACE." I'm sick of
all this crap. Someone help!

jake

Jacob Dinardi

unread,
Jul 28, 1999, 3:00:00 AM7/28/99
to
Damnit I posted this message twice already to the wrong thread... sombody slap me
Minkwitz Design Service wrote in message <379F8140...@xta.com>...

kl...@my-deja.com

unread,
Aug 24, 1999, 3:00:00 AM8/24/99
to
I was having trouble plotting in AutoCAD 2000 when I came across your
conversation thread. I hope my code can help you out.

The trouble I was having had to do with the 'Invalid Input' error when
I tried to set any of the plot configuration parameters for the FIRST
TIME in a CAD session.

If I began a brand new AutoCAD session and tried to run my code, it
would crash with the 'Invalid Input' error. However, after I plotted
from the command line just once, my code would work just fine.

The missing piece? The .RefreshPlotDeviceInfo method had to be invoked
before any plot configuration information could be altered.

The code below plots a window based on a standard title block that I
use. gTitleInsPt and gTitleUpRightCorner are 2 global variables set
elsewhere that take into account the actual insert point and scale of
the title block. This eliminates entities outside of the title block,
yet maintains a known scale.

Sub PlotMyWindow()
Dim CurrPlot As AcadPlot, PlotConfig As AcadPlotConfiguration
Dim PltOrigin(1) As Double

'In millimeters
PltOrigin(0) = 0
PltOrigin(1) = 25

Set PlotConfig = ThisDrawing.ActiveLayout
With PlotConfig
.RefreshPlotDeviceInfo
.ConfigName = "HP LaserJet 4MV"
.CanonicalMediaName = "Tabloid"
.PlotRotation = ac90degrees
.PlotOrigin = PltOrigin
.PlotType = acWindow
.SetWindowToPlot gTitleInsPt, gTitleUpRightCorner
End With

Set CurrPlot = ThisDrawing.Plot
CurrPlot.DisplayPlotPreview acFullPreview
End Sub


Keith Lozier


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

0 new messages