Message 1 of 5
Plotting - Code errors unless plot command run first.

Not applicable
11-18-2009
07:48 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am currently getting an error when setting the CurrentStyleSheet and/or PlotCentered unless I open and close the plot command.
I have compared this code to other examples but cannot see where I am going wtrong.
Thanks in advance.
Public Sub PlottingMain(ByVal sDevice As String, ByVal sPlotServer As String, ByVal sSize As String, ByVal sPlotFile As String, _
ByVal sCTBfile As String, ByVal iArea As Long, ByVal iRotation As Integer, _
Optional ByVal pW1 As VariantType = 0, Optional ByVal pW2 As VariantType = 0, _
Optional ByVal Preview As Integer = 0, Optional ByVal sScale As String = "FIT", _
Optional ByVal bCentre As Boolean = False, Optional ByVal bHide As Boolean = False, _
Optional ByVal lQty As Long = 1, Optional ByVal offX As Double = 0.0, Optional ByVal offY As Double = 0.0)
'plotting function
MsgBox("Plot Type:", MsgBoxStyle.Information, "DEP: PlottingMAIN")
Dim offset(0 To 1)
offset(0) = offX
offset(1) = offY
If Not sDevice Like "*.pc3" Then sDevice = sPlotServer & sDevice
Dim myDWG As ApplicationServices.Document
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'' Access the Preferences object
''Dim acPrefComObj As AcadPreferences = Application.Preferences
'Dim acPlotComObj As AcadPlot = AcadPlot
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Reference the Layout Manager
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
'' Get the current layout and output its name in the Command Line window
Dim acLayout As Layout
acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _
OpenMode.ForRead)
'' Get the PlotInfo from the layout
Dim acPlInfo As PlotInfo = New PlotInfo()
acPlInfo.Layout = acLayout.ObjectId
'' Get a copy of the plotsettings from the layout
Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
acPlSet.CopyFrom(acLayout)
'' Update the PlotSettings object
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
Debug.Print("PlottingMain Transaction - 01")
acPlSetVdr.SetPlotConfigurationName(acPlSet, sDevice, sSize)
'' Set the plot type
acPlSetVdr.SetPlotType(acPlSet, _
Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'' Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, True)
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)
acPlSetVdr.SetCurrentStyleSheet(acPlSet, sCTBfile)
acPlSetVdr.SetPlotCentered(acPlSet, bCentre)
Debug.Print("PlottingMain Transaction - 20")
'' Set the plot info as an override since it will
'' not be saved back to the layout
acPlInfo.OverrideSettings = acPlSet
'' Validate the plot info
Dim acPlInfoVldr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVldr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVldr.Validate(acPlInfo)
End Using
End Sub
I have compared this code to other examples but cannot see where I am going wtrong.
Thanks in advance.
Public Sub PlottingMain(ByVal sDevice As String, ByVal sPlotServer As String, ByVal sSize As String, ByVal sPlotFile As String, _
ByVal sCTBfile As String, ByVal iArea As Long, ByVal iRotation As Integer, _
Optional ByVal pW1 As VariantType = 0, Optional ByVal pW2 As VariantType = 0, _
Optional ByVal Preview As Integer = 0, Optional ByVal sScale As String = "FIT", _
Optional ByVal bCentre As Boolean = False, Optional ByVal bHide As Boolean = False, _
Optional ByVal lQty As Long = 1, Optional ByVal offX As Double = 0.0, Optional ByVal offY As Double = 0.0)
'plotting function
MsgBox("Plot Type:", MsgBoxStyle.Information, "DEP: PlottingMAIN")
Dim offset(0 To 1)
offset(0) = offX
offset(1) = offY
If Not sDevice Like "*.pc3" Then sDevice = sPlotServer & sDevice
Dim myDWG As ApplicationServices.Document
myDWG = ApplicationServices.Application.DocumentManager.MdiActiveDocument
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
Dim acCurDb As Database = acDoc.Database
'' Access the Preferences object
''Dim acPrefComObj As AcadPreferences = Application.Preferences
'Dim acPlotComObj As AcadPlot = AcadPlot
Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
'' Reference the Layout Manager
Dim acLayoutMgr As LayoutManager
acLayoutMgr = LayoutManager.Current
'' Get the current layout and output its name in the Command Line window
Dim acLayout As Layout
acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _
OpenMode.ForRead)
'' Get the PlotInfo from the layout
Dim acPlInfo As PlotInfo = New PlotInfo()
acPlInfo.Layout = acLayout.ObjectId
'' Get a copy of the plotsettings from the layout
Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)
acPlSet.CopyFrom(acLayout)
'' Update the PlotSettings object
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
Debug.Print("PlottingMain Transaction - 01")
acPlSetVdr.SetPlotConfigurationName(acPlSet, sDevice, sSize)
'' Set the plot type
acPlSetVdr.SetPlotType(acPlSet, _
Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'' Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, True)
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit)
acPlSetVdr.SetCurrentStyleSheet(acPlSet, sCTBfile)
acPlSetVdr.SetPlotCentered(acPlSet, bCentre)
Debug.Print("PlottingMain Transaction - 20")
'' Set the plot info as an override since it will
'' not be saved back to the layout
acPlInfo.OverrideSettings = acPlSet
'' Validate the plot info
Dim acPlInfoVldr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVldr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVldr.Validate(acPlInfo)
End Using
End Sub