I'm making a program to set the print settings of the layouts in a drawing, but an error happens when you finish the program:
<CommandMethod("fazteste")>
Public Sub teste()
Dim wdb As Database = HostApplicationServices.WorkingDatabase
Dim file As String = "D:\desenho.dwg"
Dim db As New Database(False, True)
db.ReadDwgFile(file, System.IO.FileShare.None, False, Nothing)
HostApplicationServices.WorkingDatabase = db
Dim acLayoutMgr As LayoutManager = LayoutManager.Current
With db.TransactionManager.StartTransaction
Dim layoutDict As DBDictionary = db.LayoutDictionaryId.GetObject(OpenMode.ForRead)
''em todos os layouts exceto o Model, faça:
For Each id As DictionaryEntry In layoutDict
Dim acLayout As Layout = id.Value.GetObject(OpenMode.ForRead)
If acLayout.LayoutName = "Model" Then Continue For
Try
Dim curr As String = acLayoutMgr.CurrentLayout
acLayoutMgr.CurrentLayout = acLayout.LayoutName
'' 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(False)
acPlSet.CopyFrom(acLayout)
'' Update the PlotSettings object
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current
'' Set the plot type
acPlSetVdr.SetPlotWindowArea(acPlSet, New Extents2d(0, 0, 840, 594))
acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window)
'' Set the plot scale
acPlSetVdr.SetUseStandardScale(acPlSet, True)
acPlSetVdr.RefreshLists(acPlSet)
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.StdScale1To1)
acPlSetVdr.RefreshLists(acPlSet)
acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters)
acPlSetVdr.RefreshLists(acPlSet)
acPlSetVdr.SetPlotRotation(acPlSet, PlotRotation.Degrees000)
acPlSetVdr.RefreshLists(acPlSet)
acPlSetVdr.SetCurrentStyleSheet(acPlSet, "penas.ctb")
acPlSetVdr.RefreshLists(acPlSet)
'' Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, True)
acPlSetVdr.RefreshLists(acPlSet)
'' Set the plot device to use
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DesignJet 755CM C3198B.pc3", "ISO_expand_A1_(594.00_x_841.00_MM)")
acPlSetVdr.RefreshLists(acPlSet)
'' Validate the plot info
Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVdr.Validate(acPlInfo)
acLayout.CopyFrom(acPlSet)
acLayoutMgr.CurrentLayout = curr
Catch
ED.WriteMessage(vbLf & Err.Description)
End Try
Next
.Commit()
End With
acLayoutMgr.Dispose()
db.SaveAs(file, True, DwgVersion.Current, db.SecurityParameters)
db.Dispose()
MsgBox("ok")
HostApplicationServices.WorkingDatabase = wdb
End Sub
the program comes to making changes, but causes a fatal error and closes autocad
What is missing?
the drawing, the printer and paper size there and the program comes to show the message "ok" at the end