.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Set Current" PlotSettings/Page Setup

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
762 Views, 2 Replies

"Set Current" PlotSettings/Page Setup

Well, I've been following posts on related subjects since I am new to this. Found many postings helpful as you can see below. However, When I try to Create a pagesetup and set it current I am unable to set the newly created Page Setup as current. When I examine the item it works fine, I am able to set it current. If anyone is familiar with this and can provide input I would be extremely greatful.

Public Sub SetPlotSettings()
Dim Doc As Document = Application.DocumentManager.MdiActiveDocument
Dim DocLock As DocumentLock = Doc.LockDocument
Try
Dim oAcadDB As Autodesk.AutoCAD.DatabaseServices.Database = Application.DocumentManager.MdiActiveDocument.Database
Dim oAcadTransactionManager As Autodesk.AutoCAD.DatabaseServices.TransactionManager = oAcadDB.TransactionManager
Dim oAcadTransaction As Transaction = oAcadTransactionManager.StartTransaction()
Dim oPlotSettingsObjectID As ObjectId = oAcadDB.PlotSettingsDictionaryId
Dim oPlotSettingsDBDictionary As Autodesk.AutoCAD.DatabaseServices.DBDictionary = CType(oAcadTransaction.GetObject(oPlotSettingsObjectID, OpenMode.ForWrite, False, False), DBDictionary)
Dim oDictionaryEntry As DictionaryEntry
Dim BoolPlotSettingsExist As Boolean
Dim StrPlotSettings As String = "TEST Pagesetup"
Dim oPlotSettings As New Autodesk.AutoCAD.DatabaseServices.PlotSettings(False)
Dim oPlotSettingsValidator As Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator = Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.Current
Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig(Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices(10).DeviceName)
Dim oPlotConfig As Autodesk.AutoCAD.PlottingServices.PlotConfig = Autodesk.AutoCAD.PlottingServices.PlotConfigManager.CurrentConfig
Dim oPlotInfo As Autodesk.AutoCAD.PlottingServices.PlotInfo = New Autodesk.AutoCAD.PlottingServices.PlotInfo()
Dim oLayoutManager As Autodesk.AutoCAD.DatabaseServices.LayoutManager = Autodesk.AutoCAD.DatabaseServices.LayoutManager.Current
Dim oLayout As Autodesk.AutoCAD.DatabaseServices.Layout = oLayoutManager.GetLayoutId(oLayoutManager.CurrentLayout).GetObject(OpenMode.ForRead, False, False)
'Application.ShowAlertDialog(oLayout.PlotSettingsName)
For Each oDictionaryEntry In oPlotSettingsDBDictionary
If oDictionaryEntry.Key = StrPlotSettings Then
BoolPlotSettingsExist = True
oPlotSettingsObjectID = oDictionaryEntry.Value
Exit For
End If
Next
If BoolPlotSettingsExist = True Then
oPlotSettings = CType(oAcadTransaction.GetObject(oPlotSettingsObjectID, OpenMode.ForWrite, False, False), PlotSettings)
Else
oPlotSettings = New PlotSettings(False) ' False Paperspace, True ModelSpace
oPlotSettings.PlotSettingsName = StrPlotSettings
oPlotSettings.DrawViewportsFirst = False
oPlotSettings.PlotHidden = False
oPlotSettings.PlotPlotStyles = True
oPlotSettings.PlotViewportBorders = False
oPlotSettings.PrintLineweights = True
oPlotSettings.ScaleLineweights = True
oPlotSettings.ShadePlot = PlotSettingsShadePlotType.AsDisplayed
oPlotSettings.ShowPlotStyles = True
oPlotSettings.AddToPlotSettingsDictionary(oAcadDB)
oAcadTransactionManager.AddNewlyCreatedDBObject(oPlotSettings, True)
For Each oDictionaryEntry In oPlotSettingsDBDictionary ' Adding the PlotSetting to the dictionary modifies the Object ID.
' This operation resets the PlotSetting object
If oDictionaryEntry.Key = StrPlotSettings Then
oPlotSettingsObjectID = oDictionaryEntry.Value
Exit For
End If
Next
oPlotSettings = CType(oAcadTransaction.GetObject(oPlotSettingsObjectID, OpenMode.ForWrite, False, False), PlotSettings)

End If
With oPlotSettingsValidator
.RefreshLists(oPlotSettings)
.SetPlotConfigurationName(oPlotSettings, Autodesk.AutoCAD.PlottingServices.PlotConfigManager.Devices(10).DeviceName, oPlotConfig.CanonicalMediaNames(10).ToString)
'.SetClosestMediaName(oPlotSettings, 8, 11, PlotPaperUnit.Inches, True)
.SetDefaultPlotConfig(oPlotSettings)
.SetStdScale(oPlotSettings, 1)
.SetUseStandardScale(oPlotSettings, True)
.SetStdScaleType(oPlotSettings, StdScaleType.StdScale1To1)
.SetPlotRotation(oPlotSettings, PlotRotation.Degrees000)
.SetPlotPaperUnits(oPlotSettings, PlotPaperUnit.Inches)
'Dim oWindow As New Autodesk.AutoCAD.DatabaseServices.Extents2d(oBlockRef.Position.X, oBlockRef.Position.Y,oBlockRef.Position.X + 34.0, oBlockRef.Position.Y + 22.0)
'.SetPlotWindowArea(oPlotSettings, oWindow)
'.SetPlotOrigin(oPlotSettings, New Autodesk.AutoCAD.Geometry.Point2d(0, 0))
.SetPlotType(oPlotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
Dim oCusScale As New Autodesk.AutoCAD.DatabaseServices.CustomScale(1.0, 1.0)
.SetCustomPrintScale(oPlotSettings, oCusScale)
.SetPlotCentered(oPlotSettings, True)
.SetZoomToPaperOnUpdate(oPlotSettings, True)
'.SetCanonicalMediaName(oPlotSettings, oPlotConfig.CanonicalMediaNames(10).ToString)
.SetCurrentStyleSheet(oPlotSettings, "ACCO_Std_1-4.ctb")
.RefreshLists(oPlotSettings)
oAcadTransaction.Commit()
oCusScale = Nothing
End With
oAcadDB = Nothing
oAcadTransactionManager = Nothing
oAcadTransaction = Nothing
oPlotSettingsObjectID = Nothing
oPlotSettingsDBDictionary = Nothing
oDictionaryEntry = Nothing
StrPlotSettings = Nothing
oPlotSettings = Nothing
oPlotSettingsValidator = Nothing
oPlotConfig = Nothing
oPlotInfo = Nothing
DocLock.Dispose()
'Doc = Nothing
'Doc.Dispose()
Catch ex As Exception
Application.ShowAlertDialog(ex.Data)
Finally
End Try
End Sub
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

I've got the same Problem. I'm trying to set the new Page Setup as the used Pagesetup of the current Layout. But don't know how.

Has anybody an idea?

Thanks!!
Message 3 of 3
Anonymous
in reply to: Anonymous

Have you tried using the copyfrom method for the current layout? That is, lo.copyfrom (ps) where ps is the plotsettings you just created.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost