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

Add New Pagesetup (VB.NET)

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
1679 Views, 3 Replies

Add New Pagesetup (VB.NET)

How do I add a new Pagesetup in VB.NET?

 

I know I need the PlotSettings class

and I add it to the Drawing database. 

 

Can someone get me started with the code and/or correct objecst? 

 

Thanks, 

3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: Anonymous

This is copying one from another drawing but shows basic idea.

You add it to PlotSettingsDictionary

 

Database.PlotSettingsDictionaryId----to get DictionaryID 

 

You can add to dictionary using the-----PlotSettings.AddToPlotSettingsDictionary

 

 

 Public Const PLOTSETTINGSFILE As String = "C:\Users\Jeff\Desktop\PlotDrawing.dwg"
        <CommandMethod("AddPlotSetting")> _
        Public Sub AddPlotSetting()
            Dim CurrentDatabase As Database = HostApplicationServices.WorkingDatabase
            Dim SourceDatabase As New Database(False, True)
            SourceDatabase.ReadDwgFile(PLOTSETTINGSFILE, FileOpenMode.OpenForReadAndAllShare, True, "")
            Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction
                Using sourceTransaction As Transaction = SourceDatabase.TransactionManager.StartTransaction
                    Dim sourcePlotDic As DBDictionary = SourceDatabase.PlotSettingsDictionaryId.GetObject(OpenMode.ForRead)
                    Dim objID As ObjectId
                    If sourcePlotDic.Contains("HCS PDF") Then
                        objID = sourcePlotDic.GetAt("HCS PDF")
                        Dim pl As PlotSettings = objID.GetObject(OpenMode.ForRead)
                        Dim cpl As New PlotSettings(False)
                        cpl.CopyFrom(pl)
                        cpl.AddToPlotSettingsDictionary(CurrentDatabase)
                        Dim bt As BlockTable = CurrentDatabase.BlockTableId.GetObject(OpenMode.ForRead)
                        Dim btr As BlockTableRecord = bt(BlockTableRecord.PaperSpace).GetObject(OpenMode.ForRead)
                        Dim lytobjID As ObjectId = btr.LayoutId.GetObject(OpenMode.ForRead).ObjectId
                        Dim lytps As PlotSettings = lytobjID.GetObject(OpenMode.ForWrite)
                        lytps.CopyFrom(cpl)
                    End If
                    currentTransaction.Commit()
                End Using
            End Using
        End Sub

 

Message 3 of 4
Anonymous
in reply to: Anonymous

For Plot offsets do I need to use the .SetPlotOrigin and use math to calculate the desired origin point for the lower left hand corner of the paper? 

 

Oh and does the PlotSettingsValidator.SetClosestMediaName Method

... work better than the SetCanonicalMediaName....? (This is probably obvious.... but just checking)

 

Cause I'm thinking it would since I'm querying and excel spreadsheet with all our plot settings and then importing them into the pagesetup function. 

 

I think this would probably help as our CanonicalMediaNames vary from printer to printer.

And we several different users using various printers... So less variables just need paper size 11x17, 8.5x11, etc...

 

 

Message 4 of 4
Anonymous
in reply to: Anonymous

Here's what I've got so far...

 

<CommandMethod("AddPlotSetting")> _
    Public Sub AddPlotSetting(ByVal strPageSetupName As String, _
                                     ByVal strconfigname As String, _
                                        ByVal strpaperdisplayname As String, _
                                        ByVal strdrivercanonicalmedianame As String, _
                                        ByVal dblpaperwidth As String, _
                                        ByVal dblpaperheight As String, _
                                        ByVal isplotstyles As Boolean, _
                                        ByVal strctbfilename As String, _
                                        ByVal intPlotRotation As PlotRotation, _
                                        ByVal intplottype As Integer, _
                                        ByVal intstandardscale As Integer, _
                                        ByVal isplotcentered As Boolean, _
                                        ByVal dblxoffset As Double, _
                                        ByVal dblyoffset As Double, _
                                        ByVal ismodelorlayout As Boolean, _
                                        Optional ByVal iscurrentsetup As Boolean = False)
        Dim s_PlotSettingsFile As String = "c:\acad.dwg"
        Dim s_MediaName As String = "11 x 17"
        Dim s_PlotDeviceName As String = "\\rdops1\RDO0071"
        Dim s_StyleSheetName As String = "Monochrome.ctb"


        Dim CurrentDatabase As Database = HostApplicationServices.WorkingDatabase
        Dim SourceDatabase As New Database(False, True)
        SourceDatabase.ReadDwgFile(s_PlotSettingsFile, FileOpenMode.OpenForReadAndAllShare, True, "")
        Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction
            Using sourceTransaction As Transaction = SourceDatabase.TransactionManager.StartTransaction
                'Dim sourcePlotDic As DBDictionary = SourceDatabase.PlotSettingsDictionaryId.GetObject(OpenMode.ForRead)
                'Dim objID As ObjectId

                'If sourcePlotDic.Contains("HCS PDF") Then
                '    objID = sourcePlotDic.GetAt("HCS PDF")

                '' Reference the Layout Manager
                Dim acLayoutMgr As LayoutManager
                acLayoutMgr = LayoutManager.Current
                '' Get the current layout
                Dim acLayout As Layout
                acLayout = currentTransaction.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), _
                                                   OpenMode.ForRead)

                Dim pl As PlotSettings = New PlotSettings(acLayout.ModelType)

                'Test Code Here
                'Dim acPlSet As PlotSettings = New PlotSettings(acLayout.ModelType)

                'Dim cpl As New PlotSettings(False)
                'cpl.CopyFrom(pl)

                'Update the Plot Settings Object
                'Create PlotSettingsValidator
                Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current

                'Set the PageSetup Name
                psv.SetPlotViewName(pl, strPageSetupName)

                'Set Plot Type
                psv.SetPlotType(pl, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)

                'set plot scale
                psv.SetUseStandardScale(pl, True)
                psv.SetStdScaleType(pl, StdScaleType.ScaleToFit)
                psv.SetStdScale(pl, 0.0)

                'Center the plot
                psv.SetPlotCentered(pl, True)

                'Rotation
                psv.SetPlotRotation(pl, PlotRotation.Degrees000)


                'Set Media Size
                psv.SetCanonicalMediaName(pl, s_MediaName)
                psv.SetCurrentStyleSheet(pl, s_StyleSheetName)

                '' Set the plot device to use
                psv.SetPlotConfigurationName(pl, s_PlotDeviceName, s_MediaName)

                'Make Default PageSetup Yes/No?
                psv.SetDefaultPlotConfig(pl)

                'Add to Plot Settings to Drawing Database
                pl.AddToPlotSettingsDictionary(CurrentDatabase)


                'Dim bt As BlockTable = CurrentDatabase.BlockTableId.GetObject(OpenMode.ForRead)
                'Dim btr As BlockTableRecord = bt(BlockTableRecord.PaperSpace).GetObject(OpenMode.ForRead)
                'Dim lytobjID As ObjectId = btr.LayoutId.GetObject(OpenMode.ForRead).ObjectId
                'Dim lytps As PlotSettings = lytobjID.GetObject(OpenMode.ForWrite)
                'lytps.CopyFrom(cpl)
                'End If

                currentTransaction.Commit()
            End Using
        End Using
    End Sub

 

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