Author Topic: VBA Plotting ModelSpace..  (Read 7951 times)

0 Members and 1 Guest are viewing this topic.

hardwired

  • Guest
VBA Plotting ModelSpace..
« on: February 13, 2008, 09:59:15 AM »
Hi,


Latest program i'm trying to do is to plot modelspace titleblocks, when i try the code below to plot them, the program crashes out on the PlotToDevice line and says Method 'PlotToDevice' of object IAcadPlot failed'

Code: [Select]
Private Sub cmdPLOT_Click()
For Each entityX In selectset

entityX.GetBoundingBox MinExt, MaxExt ' Get bounding box of each schedule..

' Set variables of each window plot point..
MinWin(0) = MinExt(0): MinWin(1) = MinExt(1)
MaxWin(0) = MaxExt(0): MaxWin(1) = MaxExt(1)

' Plot set-up code..
ThisDrawing.ModelSpace.Layout.PlotType = acWindow
ThisDrawing.ModelSpace.Layout.UseStandardScale = True
ThisDrawing.ModelSpace.Layout.StandardScale = acScaleToFit
ThisDrawing.ModelSpace.Layout.PlotRotation = ac90degrees
ThisDrawing.ModelSpace.Layout.CanonicalMediaName = "A4"
ThisDrawing.ModelSpace.Layout.PlotWithPlotStyles = True
ThisDrawing.ModelSpace.Layout.CenterPlot = True
ThisDrawing.ModelSpace.Layout.PaperUnits = acMillimeters
' Check for Colour or Black 'n' White..
If ColourOPT.Value = True Then
    ThisDrawing.ModelSpace.Layout.StyleSheet = "AbiCAD Pens.ctb"
ElseIf bwOPT.Value = True Then
    ThisDrawing.ModelSpace.Layout.StyleSheet = "STANDARD BLACK + GREY.ctb"
End If
ThisDrawing.ModelSpace.Layout.GetWindowToPlot MinWin, MaxWin
ThisDrawing.Plot.NumberOfCopies = 1
ThisDrawing.ModelSpace.Layout.ConfigName = "Xerox 32.pc3"
ThisDrawing.Plot.PlotToDevice
   
    Next entityX

End Sub


......This is how the program works, well meant to:

The userform has three methods of selection set to pick the titleblocks (Pick, Window and All) - haven't coded for Pick or All but Window works fine. The selection set finds the borders of each TB (in a different layer) and finds the bounding box coords. Then should use these as the coords for the window plot..

The code above is something i threw together for the plotting, but as i said, it fails and all that prints out is a blank A4 sheet..

Can anyone check my code and see what could be wrong and / or shed some more light on the whole plotting issue with VBA..


Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM..
XP Pro SP2..
Sapphire X1950 512MB Dual-DVi Graphics Card..
AutoCAD 2008..

Bryco

  • Water Moccasin
  • Posts: 1882
Re: VBA Plotting ModelSpace..
« Reply #1 on: February 13, 2008, 10:43:29 AM »
Without really looking, does your code crash when you dont use this lineThisDrawing.ModelSpace.Layout.CanonicalMediaName = "A4"
(when you rotate the media changes name)

hardwired

  • Guest
Re: VBA Plotting ModelSpace..
« Reply #2 on: February 13, 2008, 11:35:08 AM »
Hi,

Yeah, i commented out the CanonicalMediaName line and it worked, but it printed it portrait on a landscape page. Then, I changed the PlotRotation line to 1, not Ac90Degrees and kept the CanonicalMediaName line in and it did the same - portrait on a landscape page..

Below is a small routine i did to check the modelspace plot settings of drawings and after running it, the CanonicalMediaName showed as A4 and the PlotRotation line showed as 1..


Code: [Select]
' Get the current plot settings for the drawing..
Sub GetPlotSettings()
   
    Dim PlotTypeX As String
    PlotTypeX = ThisDrawing.ModelSpace.Layout.PlotType
   
        MsgBox _
        "The Plotter for the active layout is: " & ThisDrawing.ModelSpace.Layout.ConfigName & vbCr & _
        "The PlotStyle for the active layout is: " & ThisDrawing.ModelSpace.Layout.StyleSheet & vbCr & _
        "The Media (paper size) for the active layout is: " & ThisDrawing.ModelSpace.Layout.CanonicalMediaName & vbCr & _
        vbCr & _
        "The Scale for the active layout is: " & ThisDrawing.ModelSpace.Layout.StandardScale & vbCr & _
        "The Units for the active layout is: " & ThisDrawing.ModelSpace.Layout.PaperUnits & vbCr & _
        "The Plot Type for the active layout is: " & PlotTypeX & vbCr & _
        "The Plot Rotation for the active layout is: " & ThisDrawing.ModelSpace.Layout.PlotRotation _
        , vbInformation, "Get Plot Settings: " & ThisDrawing.Name
End Sub


So, thanks for the reply and at least it didn't crash out this time, just need to sort out the orientation now..

Any ideas?

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM..
XP Pro SP2..
Sapphire X1950 512MB Dual-DVi Graphics Card..
AutoCAD 2008..

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: VBA Plotting ModelSpace..
« Reply #3 on: February 13, 2008, 11:53:51 AM »
what I do is do a manual plot and save changes to the layout, then at the top of your code, add
Code: [Select]
      Dim Layout As AcadLayout
      Set Layout = ThisDrawing.ActiveLayout
      Layout.RefreshPlotDeviceInfo
And if you step thru your code 1 line at a time, you can look and see what the settings are on the Layout, and make sure your code is using the correct verbage
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

hardwired

  • Guest
Re: VBA Plotting ModelSpace..
« Reply #4 on: February 15, 2008, 06:24:04 AM »
Hi,

I got it to work a bit, the plotting bit at least, but it will only plot the saved defined window (applied to layout), and not the selected selection window thing i had planned - what its meant to do is for each of the selected titleblocks, its meant to use the outer edge as the window coords and plot each one in turn but obviously my code is quite right yet?

Any ideas? (the full code is in my previous reply(ies))

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM..
XP Pro SP2..
Sapphire X1950 512MB Dual-DVi Graphics Card..
AutoCAD 2008..

Bryco

  • Water Moccasin
  • Posts: 1882
Re: VBA Plotting ModelSpace..
« Reply #5 on: February 15, 2008, 12:00:21 PM »
From help on centerplot
Quote
This property cannot be set to TRUE on a layout object whose PlotType property is set to acLayout.
Keep trying.