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

Add Plot Config Not saving to current Dwg

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
VB_Autocad_guy
2149 Views, 7 Replies

Add Plot Config Not saving to current Dwg

The Pagesetup isn't showing up in the Pagesetup dialog. 

But when I close the drawing and open it up it's visible. 

What am I missing here? Still new with this transaction concept... 

 

  <CommandMethod("aps")> _
Public Sub AddPlotSetting()
       

        'TODO: Finish Cleaning Print Function


        Dim s_PlotSettingsFile As String = "c:\test.dwg
        Dim s_PageSetupName As String = "catdog"
        Dim s_MediaName As String = "11 x 17"
        Dim s_PlotDeviceName As String = "\\rdops1\RDO0071"
        Dim s_StyleSheetName As String = "Monochrome.ctb"
        Dim d_PaperHeight As Double = 11
        Dim d_PaperWidth As Double = 17
        Dim is_PlotStyles As Boolean = True
        Dim int_PlotRotation As PlotRotation = PlotRotation.Degrees000
        Dim int_PlotType As Autodesk.AutoCAD.DatabaseServices.PlotType = Autodesk.AutoCAD.DatabaseServices.PlotType.Extents
        Dim int_StandardScale As Integer = StdScaleType.ScaleToFit
        Dim is_PlotCentered As Boolean = True

        Dim myPoint As New Autodesk.AutoCAD.Geometry.Point2d(2, 4)

        Dim CurrentDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database
      
        Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction
       
            'TODO: Confirm New Print Object is Created 
            'Create PlotSetting
            Dim pl As PlotSettings = New PlotSettings(True)


            'Set the PageSetup Name
            pl.PlotSettingsName = s_PageSetupName

            'Create PlotSettingsValidator
            Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current

            '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)
            psv.SetPlotOrigin(pl, myPoint)

            'Set Media Size
            psv.SetCanonicalMediaName(pl, "Letter")
            'psv.SetClosestMediaName(pl, d_PaperWidth, d_PaperHeight, PlotPaperUnit.Inches, True)

            'TODO: Validate StyleSheetName
            psv.SetCurrentStyleSheet(pl, s_StyleSheetName)

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

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

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

            currentTransaction.Commit()
        End Using


    End Sub

 

7 REPLIES 7
Message 2 of 8

Let me Clarify... The pagesetup does indeed add but it doesn't show up in the pagesetup window. 

When I switch viewports then type pagesetup the pagesetup shows up after I see this message

"Restoring cached viewports"

But it only works when it Restores cached viewports....

How do I refresh the Autocad viewport in .NET? I tried Regen not luck there. 

 

Message 3 of 8

Try coping “PlotSettings” from current plot setting and then try to modify its values as you require. Please refer below code

 

<CommandMethod("aps_test")> _
        Public Sub AddPlotSetting_test()
            Dim CurrentDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database

            Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction
                Dim pl As PlotSettings = New PlotSettings(True)
                Dim layoutId As ObjectId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout)
                Dim activeLyt As Layout = currentTransaction.GetObject(layoutId, OpenMode.ForRead)
                pl.CopyFrom(activeLyt)

                pl.PlotSettingsName = "Test"

                'set other setting

                Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
                psv.RefreshLists(pl)

                pl.AddToPlotSettingsDictionary(CurrentDatabase)

                currentTransaction.Commit()
            End Using
        End Sub

 

Virupaksha Aithal

Autodesk Developer Network



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 4 of 8

I get mixed results from this code. 

One-time it worked. On another drawing it errors out. 

On a new drawing it doesn't work sometimes. 

On my latest try... it just doesn't show it exists to the user GUI. 

 

I used your code exactly as shown. 

 

Line 122 is:

 pl.CopyFrom(activeLyt)

 

Maybe I should ask more about how the Plotsettings objects are structured in the drawing.

 

When I add a new plot setting should I use this method... maybe?

lytobjid being the LayoutObjectID from Modelspace

-Dim pl As PlotSettings = lytobjID.GetObject(OpenMode.ForWrite)

 

or use 


-or pl.copyfrom(CurrentLayout)?

Does this copy from an existing layout that already exists... does this assume that a pagesetup already exists? 


 

 

I get this error:

Autodesk.AutoCAD.Runtime.Exception was unhandled by user code
  Message="eWrongObjectType"
  Source="acdbmgd"
  StackTrace:
       at Autodesk.AutoCAD.Runtime.RXObject.CopyFrom(RXObject source)
       at ClassAutocad2011.clsPlotting.AddPlotSetting_test() in C:\Visual Studio Projects\ClassAutocad2011\ClassAutocad2011\Autocad Main\Autocad Library\Classes\clsPlotting.vb:line 122
       at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorker(MethodInfo mi, Object commandObject, Boolean bLispFunction)
       at Autodesk.AutoCAD.Runtime.CommandClass.InvokeWorkerWithExceptionFilter(MethodInfo mi, Object commandObject, Boolean bLispFunction)
       at Autodesk.AutoCAD.Runtime.PerDocumentCommandClass.Invoke(MethodInfo mi, Boolean bLispFunction)
       at Autodesk.AutoCAD.Runtime.CommandClass.CommandThunk.Invoke()
  InnerException: 

 I ran this code: 

 <CommandMethod("aps_test")> _
        Public Sub AddPlotSetting_test()
        Dim CurrentDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database

        Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction
            Dim pl As PlotSettings = New PlotSettings(True)
            Dim layoutId As ObjectId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout)
            Dim activeLyt As Layout = currentTransaction.GetObject(layoutId, OpenMode.ForRead)
            pl.CopyFrom(activeLyt)

            pl.PlotSettingsName = "Test"

            'set other setting

            Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
            psv.RefreshLists(pl)

            pl.AddToPlotSettingsDictionary(CurrentDatabase)

            currentTransaction.Commit()
        End Using
    End Sub

 

 

 

Message 5 of 8

I tested the code provided in my previous response. Code works fine consistently. I am testing against AutoCAD 2012.

 

Steps followed at my end:

Start AutoCAD 2012

Netload the .net application.

Issue command “aps_test”

Issue command “pagesetup” to verify the adding of  “PlotSettings”.

 

pl.copyfrom(CurrentLayout)?

“CopyFrom” API makes sure that the new “PlotSettings” is initialized correctly.



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 6 of 8

Hi Virupaksha, 

 

Thank you so much for taking the time to respond to my question. 

For your reference I attached my sample project solution stripped down to the bare essentials. 

 

I've done the following. 

 

Disable my Class2011Autocad from the registry from Autoloading. 

 

I'm running Autocad 2011 

E.208.0.0 (English Version 3)

 

My DLL's are: (I'm using the ones included in c:\ObjectARX 2011\inc)

AcDbMgd .NET 18.1.0.0

AcMgd .NET 18.1.0.0

I've set copy local to "FALSE"

 

I did notice that the DLL's in the (C:\Program Files\Autodesk\AutoCAD 2011)

AcDbMgd .NET 18.1.115.0

AcMgd  .Net  18.1.208.0

 

  1. Opended Autocad 2011. 
  2. NETLOAD TestPlotCode.dll
  3. Typed showmsg -Success!
  4. then typed addmyplot -Command recognized
  5. then typed pagesetup

It doesn't show in the pagesetup manager. (See image 1)

But when I press new pagesetup it shows in the list of available options. (see image2)

As you can see. 

 

It does work... but not intially. This is not the the way it is intended to work is it? 

 

 

IMAGE 1

PAGESETUPMANAGER.png

 

 

 

 

Then the pagesetup does show. 

 

 

IMAGE 2

NEWPAGESETUP.png

 

IMAGE 3afterswitchingtabs.png


Then the pagesetup does show. (see image3)

When I click on layout 1 and then back at model tab. 

 

Again thank you so much for looking into this problem!

 

Regards, 

Ben 

Message 7 of 8

Please accept my apologies… I missed very simple and basic step of adding the new plot setting to current “Transaction”.

 

<CommandMethod("AddMyPlot")> _
            Public Sub AddPlotSetting_test()
        Dim CurrentDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database

        Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction
            Dim pl As PlotSettings = New PlotSettings(True)
            Dim layoutId As ObjectId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout)
            Dim activeLyt As Layout = currentTransaction.GetObject(layoutId, OpenMode.ForRead)
            pl.CopyFrom(activeLyt)

            pl.PlotSettingsName = "Test"

            'set other setting

            Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
            psv.RefreshLists(pl)

            pl.AddToPlotSettingsDictionary(CurrentDatabase)
            currentTransaction.AddNewlyCreatedDBObject(pl, True)
            psv.RefreshLists(pl)

            currentTransaction.Commit()
        End Using
    End Sub

 



Virupaksha Aithal KM
Developer Technical Services
Autodesk Developer Network

Message 8 of 8

Thank you so much Virupaksha!


That resolved the issue.

Being someone learning the Vb.NET object model from scratch and coming from VBA this is a life saver!

 

So for future reference those who have this problem

 

Don't forget. 

currentTransaction.AddNewlyCreatedDBObject(pl, True)

 

Again the steps are: (If I understand it correctly)

1. Open Drawing Transaction

' Dim CurrentDatabase As Database = Application.DocumentManager.MdiActiveDocument.Database

' Using currentTransaction As Transaction = CurrentDatabase.TransactionManager.StartTransaction


2. Create New PlotSetting with

'Dim pl As PlotSettings = New PlotSettings(True)


3. Get (Active/Current) Layout ID (Model/Paper Space)

'Dim layoutId As ObjectId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout)

'Dim activeLyt As Layout = currentTransaction.GetObject(layoutId, OpenMode.ForRead)


4. Use CopyFrom property of the plotsetting to intialize it on the Layout 

(“CopyFrom” API makes sure that the new “PlotSettings” is initialized correctly.)

'pl.CopyFrom(activeLyt)

 

4.B Use Plot Settings Validator

'Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current


5. Add to the PlotSettings Dictionary (Adds to the Drawing Database)

'pl.AddToPlotSettingsDictionary(CurrentDatabase)


6. AddNewlyCreatedDBOject to the Transaction (Adds it to the Transaction)

' currentTransaction.AddNewlyCreatedDBObject(pl, True)


7. Refresh the The Plotsettings with Plotsettings Validator

' psv.RefreshLists(pl)

 

8. Commit Current Transaction

' currentTransaction.Commit()

 


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