Author Topic: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net  (Read 7950 times)

0 Members and 1 Guest are viewing this topic.

DANANDERSON72

  • Guest
Why does Plot Previous seem to be absent from any forum? Can't this be done yet?
I would prefer to find a coded method, not using some form of sendcommand, SendStringToExecute .

I am having difficulty using the example:

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
<CommandMethod("SendACommandToAutoCAD")> _Public Sub SendACommandToAutoCAD()
Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument 
'' Draws a circle and zooms to the extents or
'' limits of the drawing
acDoc.SendStringToExecute("._circle 2,2,0 4 ", True, False, False)
acDoc.SendStringToExecute("._zoom _all ", True, False, False)
End Sub

I tried this with no luck:

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.Interop
Module Module2

    <CommandMethod("SendACommandToAutoCAD")> _
    Public Sub SendACommandToAutoCAD()
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim CommandString As String

        CommandString = "(command " & Chr(34) & "-plot" & Chr(34) & " " & Chr(34) & "no" & Chr(34) & " " & Chr(34) & Chr(34) & " " & Chr(34) & "previous plot" & Chr(34) & " " & Chr(34) & Chr(34) & " " & " " & Chr(34) & Chr(34) & " " & " " & Chr(34) & Chr(34) & " " & " " & Chr(34) & Chr(34) & ")"

        acDoc.SendStringToExecute(CommandString, True, False, False)

    End Sub



Any guidence is appreciated,
thanks

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4076
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #1 on: February 10, 2012, 03:52:56 PM »
how did you do it in VBA?
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #2 on: February 10, 2012, 03:56:12 PM »
Used Thisdrawing.sendcommand.


Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #3 on: February 10, 2012, 04:00:27 PM »
The COM object AcadApplication has a UseLastPlotSettings toggle. Perhaps that will give you what you need:

Autodesk.AutoCAD.Interop.AcadPreferencesOutputClass.UseLastPlotSettings

DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #4 on: February 10, 2012, 04:06:18 PM »
I will look into it thank you. So far, I can't seem to find much info on it.

DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #5 on: February 10, 2012, 04:25:46 PM »
Found this VBA example. not sure how to utilize this for my desire.


Sub Example_UseLastPlotSettings()
    ' This example reads and modifies the UseLastPlotSettings
    ' preference value.
    ' When finished, this example resets the preference value back to
    ' it's original value.
   
    Dim ACADPref As AcadPreferencesOutput
    Dim originalValue As Boolean
   
    ' Get the user preferences object

    Set ACADPref = ThisDrawing.Application.preferences.Output
   
    ' Read and display the original value
    originalValue = ACADPref.UseLastPlotSettings
    MsgBox "The UseLastPlotSettings preference is set to: " & originalValue

    ' Modify the UseLastPlotSettings preference by toggling the value
    ACADPref.UseLastPlotSettings = Not ACADPref.UseLastPlotSettings

    MsgBox "The UseLastPlotSettings preference has been set to: " & ACADPref.UseLastPlotSettings

    ' Reset the preference back to it's original value
    ACADPref.UseLastPlotSettings = originalValue
    MsgBox "The UseLastPlotSettings preference was reset back to: " & originalValue
End Sub

Chumplybum

  • Newt
  • Posts: 97
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #6 on: February 12, 2012, 08:15:31 PM »
this doesn't use the sendcommand, but gets the previous plot settings from the registry and creates a plotsettings object...

Code: [Select]
imports AAAS = autodesk.AutoCAD.ApplicationServices
imports AADS = autodesk.AutoCAD.DatabaseServices
Imports AAG = autodesk.AutoCAD.Geometry
imports AAPS = autodesk.AutoCAD.PlottingServices
   
   
Public Class PlotSettings

Public Sub New
End Sub

Public Sub New(ByVal plotsettings As AADS.PlotSettings)

me.CfgName = plotsettings.PlotConfigurationName
me.ModelType = plotsettings.ModelType
me.OriginX = plotsettings.PlotOrigin.X
me.OriginY = plotsettings.PlotOrigin.y
me.PaperHeight = plotsettings.PlotPaperSize.Y '?
me.PaperUnits = plotsettings.PlotPaperUnits
me.PaperWidth =  plotsettings.PlotPaperSize.X '?
me.PaperXMax = plotsettings.PlotPaperMargins.MaxPoint.X
me.PaperXMin = plotsettings.PlotPaperMargins.minpoint.X
me.PaperYMax = plotsettings.PlotPaperMargins.MaxPoint.y
me.PaperYMin = plotsettings.PlotPaperMargins.minpoint.y
me.PapersizeDesc = plotsettings.CanonicalMediaName
me.PlotCentered = plotsettings.PlotCentered
me.PlotHidden = plotsettings.PlotHidden
me.PlotPlotstyles = plotsettings.PlotPlotStyles
me.PlotRotation = plotsettings.PlotRotation
me.PlotType = plotsettings.PlotType
me.PrintLineweights = plotsettings.PrintLineweights
me.PrintScaleDenominator = plotsettings.CustomPrintScale.Denominator
me.PrintScaleNumerator = plotsettings.CustomPrintScale.Numerator
me.ScaleLineweights = plotsettings.ScaleLineweights
me.ScaleType = plotsettings.StdScaleType
me.ShowPlotstyles = plotsettings.ShowPlotStyles
me.StandardScale = plotsettings.StdScale
me.StyleSheet = plotsettings.CurrentStyleSheet
me.UseStandardScale = plotsettings.UseStandardScale
me.ViewportBorders = plotsettings.PlotViewportBorders
me.ViewportsFirst = plotsettings.DrawViewportsFirst
me.WindowXMax = plotsettings.PlotWindowArea.MaxPoint.X
me.WindowXMin = plotsettings.PlotWindowArea.MinPoint.X
me.WindowYMax = plotsettings.PlotWindowArea.MaxPoint.y
me.WindowYMin = plotsettings.PlotWindowArea.MinPoint.y

End Sub

#Region " Properties "

Public Property CfgName As String
Public Property ModelType As integer
Public Property OriginX As Double
Public Property OriginY As Double
Public Property PaperHeight As Double
Public Property PaperUnits As integer
Public Property PaperWidth As Double
Public Property PaperXMax As Double
Public Property PaperXMin As Double
Public Property PaperYMax As Double
Public Property PaperYMin As Double
Public Property PapersizeDesc As String
Public Property PlotCentered As integer
Public Property PlotHidden As integer
Public Property PlotPlotstyles As integer
Public Property PlotRotation As integer
Public Property PlotType As integer
Public Property PrintLineweights As integer
Public Property PrintScaleDenominator As Double
Public Property PrintScaleNumerator As Double
Public Property ScaleLineweights As integer
Public Property ScaleType As integer
Public Property SettingName As String
Public Property ShowPlotstyles As integer
Public Property StandardScale As Double
Public Property StyleSheet As String
Public Property UseStandardScale As integer
Public Property ViewportBorders As integer
Public Property ViewportsFirst As integer
Public Property WindowXMax As Double
Public Property WindowXMin As Double
Public Property WindowYMax As Double
Public Property WindowYMin As Double

#End Region

#Region " Shared "

Public Function AcadEquivalent() As AADS.PlotSettings

Dim Validator As AADS.PlotSettingsValidator = AADS.PlotSettingsValidator.Current

Dim ReturnValue As AADS.PlotSettings = new AADS.PlotSettings(me.ModelType)
Validator.SetPlotConfigurationName(ReturnValue, me.CfgName, me.PapersizeDesc)
Validator.SetPlotOrigin(ReturnValue, new AAG.Point2d(me.OriginX, me.OriginY))
Validator.SetPlotPaperUnits(ReturnValue, me.PaperUnits)

Validator.SetPlotWindowArea(ReturnValue, New AADS.Extents2d(me.WindowXMin, me.WindowYMin, me.WindowXMax, me.windowYMax))
Validator.SetPlotType(returnvalue, me.PlotType)
Validator.SetPlotCentered(ReturnValue, me.PlotCentered)
ReturnValue.PlotHidden = me.PlotHidden
Validator.SetPlotRotation(ReturnValue, me.PlotRotation)
ReturnValue.PrintLineweights = me.PrintLineweights

Validator.SetUseStandardScale(ReturnValue, me.UseStandardScale)
If ReturnValue.UseStandardScale= True Then
Validator.SetStdScale(ReturnValue, me.StdScale)
Validator.SetStdScaleType(ReturnValue,me.StdScaleType)
Else
Validator.SetCustomPrintScale(ReturnValue, new AADS.CustomScale(me.PrintScaleNumerator, me.PrintScaleDenominator))
End If

ReturnValue.ScaleLineweights = me.ScaleLineweights
ReturnValue.ShowPlotstyles = me.ShowPlotstyles
Validator.SetCurrentStyleSheet(returnvalue, me.StyleSheet)
ReturnValue.PlotViewportBorders = me.ViewportBorders
ReturnValue.DrawViewportsFirst = me.ViewportsFirst

Return returnvalue

End Function

Public Shared Function FromRegistry(byval ModelType as Boolean) As PlotSettings

Dim ReturnValue As new PlotSettings

'HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.1\ACAD-9002:409\Profiles\TRACKSTAR_GENERIC_MAP_2011\Previous plot settings
Dim PreviousPlotSettings As Microsoft.win32.RegistryKey = microsoft.Win32.Registry.CurrentUser.OpenSubKey(string.Format("Software\Autodesk\AutoCAD\R18.1\ACAD-9002:409\Profiles\{0}\Previous plot settings", aaas.Application.GetSystemVariable("cprofile")),false)
If ModelType = True Then
PreviousPlotSettings = PreviousPlotSettings.opensubkey("Model")
Else
PreviousPlotSettings = PreviousPlotSettings.opensubkey("Layout")
End If

ReturnValue.CfgName = PreviousPlotSettings.GetValue("Cfg Name")
ReturnValue.ModelType = PreviousPlotSettings.GetValue("Model type")
ReturnValue.OriginX = CDbl(PreviousPlotSettings.GetValue("Origin X"))
ReturnValue.OriginY = CDbl(PreviousPlotSettings.GetValue("Origin Y"))
ReturnValue.PaperHeight = PreviousPlotSettings.GetValue("Paper height")
ReturnValue.PaperUnits = PreviousPlotSettings.GetValue("Paper units")
ReturnValue.PaperWidth = PreviousPlotSettings.GetValue("Paper width")
ReturnValue.PaperXMax = PreviousPlotSettings.GetValue("Paper XMax")
ReturnValue.PaperXMin = PreviousPlotSettings.GetValue("Paper XMin")
ReturnValue.PaperYMax = PreviousPlotSettings.GetValue("Paper YMax")
ReturnValue.PaperYMin = PreviousPlotSettings.GetValue("Paper YMin")
ReturnValue.PapersizeDesc = PreviousPlotSettings.GetValue("Papersize desc")
ReturnValue.PlotCentered = PreviousPlotSettings.GetValue("Plot centered")
ReturnValue.PlotHidden = PreviousPlotSettings.GetValue("Plot hidden")
ReturnValue.PlotPlotstyles = PreviousPlotSettings.GetValue("Plot plotstyles")
ReturnValue.PlotRotation = PreviousPlotSettings.GetValue("Plot rotation")
ReturnValue.PlotType = PreviousPlotSettings.GetValue("Plot type")
ReturnValue.PrintLineweights = PreviousPlotSettings.GetValue("Print lineweights")
ReturnValue.PrintScaleDenominator = cdbl(PreviousPlotSettings.GetValue("Print scale denominator"))
ReturnValue.PrintScaleNumerator = cdbl(PreviousPlotSettings.GetValue("Print scale numerator"))
ReturnValue.ScaleLineweights = PreviousPlotSettings.GetValue("Scale lineweights")
ReturnValue.ScaleType = PreviousPlotSettings.GetValue("Scale type")
ReturnValue.ShowPlotstyles = PreviousPlotSettings.GetValue("Show plotstyles")
ReturnValue.StandardScale = PreviousPlotSettings.GetValue("Standard scale")
ReturnValue.StyleSheet = PreviousPlotSettings.GetValue("Style sheet")
ReturnValue.UseStandardScale = PreviousPlotSettings.GetValue("Use standard scale")
ReturnValue.ViewportBorders = PreviousPlotSettings.GetValue("Viewport borders")
ReturnValue.ViewportsFirst = PreviousPlotSettings.GetValue("Viewports first")
ReturnValue.WindowXMax = PreviousPlotSettings.GetValue("Window XMax")
ReturnValue.WindowXMin = PreviousPlotSettings.GetValue("Window XMin")
ReturnValue.WindowYMax = PreviousPlotSettings.GetValue("Window YMax")
ReturnValue.WindowYMin = PreviousPlotSettings.GetValue("Window YMin")

return returnvalue

End Function
       
#End Region

End Class


then access the previous plot using this

Code: [Select]

<CommandMethodAttribute("PPT")> _
Public Sub PreviousPlot

Dim pe As New PlottingServices.PlotEngine
pe.Plot(PlotSettings.FromRegistry(False).AcadEquivalent)

End Sub

you just need to either supply true or false, depending on if your plotting from modelspace or paperspace


hope this helps

cheers, Mark

Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #7 on: February 13, 2012, 12:15:56 AM »
Good idea, Mark, nice code. Couple of comments if I might....

Reading the Registry works fine as long as no plots have been run in the current instance of Autocad, as the PreviousPlotSettings only get written to the Registry when Autocad closes.

Hard coding the registry location is better handled by getting the currently in use location. Use the following to get this:

Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey

which on my C3D2012 system returns: "Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-a000:409"
from there you can get the profile.

Chumplybum

  • Newt
  • Posts: 97
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #8 on: February 13, 2012, 12:59:24 AM »
Hi Jeff, thanks for the comments... i could've sworn i was using the DynamicLinker.ProductKey as you've suggested, but guess i was a bit slow that day :-)
And you're right about the registry only being written to when AutoCAD closes... can't believe i missed that one, looks like its back to square one for me

thanks again

DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #9 on: February 27, 2012, 12:34:40 PM »
Thank you for the comments.  I was hoping for a solution that would allow me to use the previous plot, not the one stored in the registry, since it was pointed out that the registry is only updated when the session closes. 

Is this possible? Am I asking the unthinkable?

Bueler?

how about sending the lisp code "(command "-plot" "no" "" "previous plot" "" "" "" "")"????


DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #10 on: February 27, 2012, 01:01:32 PM »
Jeff, Can you expand on your comment.  I am very new to .NET, trying to convert existing VBA.  Admitingly, I need help.

Jeff H

  • Needs a day job
  • Posts: 6151
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #11 on: February 27, 2012, 01:58:29 PM »
Hard coding the registry location is better handled by getting the currently in use location. Use the following to get this:

Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey

which on my C3D2012 system returns: "Software\\Autodesk\\AutoCAD\\R18.2\\ACAD-a000:409"
from there you can get the profile.
Hey Jeff I have always used HostApplicationServices.Current.RegistryProductRootKey
 
I just tested both
Code - C#: [Select]
  1.  
  2.          [CommandMethod("ProductKey")]
  3.          public void ProductKey()
  4.          {
  5.              Document doc = Application.DocumentManager.MdiActiveDocument;
  6.              Database db = doc.Database;
  7.              Editor ed = doc.Editor;
  8.  
  9.              ed.WriteMessage("\n" + HostApplicationServices.Current.RegistryProductRootKey);
  10.  
  11.              ed.WriteMessage("\n" + Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey);
  12.            
  13.          }
  14.  
  15.  

and they return the same value Software\Autodesk\AutoCAD\R18.2\ACAD-a001:409
 
Do you know any reason to use one over the other?
 
Sorry For Hijacking.

DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #12 on: February 27, 2012, 03:07:40 PM »
I appreciate everyones input, I am abit lost with the fragments of code, and where to place what together.

In the 1st code I get errors on these two lines:
Code: [Select]
Validator.SetStdScale(ReturnValue, Me.StdScale)
Validator.SetStdScaleType(ReturnValue, Me.StdScaleType)

'StdScale not a member of ...
'StdScaleType not a member of...

should these read:
Code: [Select]
'Validator.SetStdScale(ReturnValue, Me.StdScale)
Validator.SetStdScale(ReturnValue, Me.StandardScale)
'Validator.SetStdScaleType(ReturnValue, Me.StdScaleType)
Validator.SetStdScaleType(ReturnValue, Me.ScaleType)





and should I change the line

from:
Code: [Select]
Dim PreviousPlotSettings As Microsoft.win32.RegistryKey = microsoft.Win32.Registry.CurrentUser.OpenSubKey(String.Format("Software\Autodesk\AutoCAD\R18.1\ACAD-9002:409\Profiles\{0}\Previous plot settings", aaas.Application.GetSystemVariable("cprofile")), False)
To:
Code: [Select]
Dim ProdKeyStr As String
ProdKeyStr = Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey
Dim PreviousPlotSettings As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(String.Format(ProdKeyStr & "\Profiles\{0}\Previous plot settings", AAAS.Application.GetSystemVariable("cprofile")), False)
« Last Edit: February 27, 2012, 03:23:13 PM by DANANDERSON72 »

DANANDERSON72

  • Guest
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #13 on: February 27, 2012, 03:19:37 PM »
What I have so far:
I do get an error on line:
Code: [Select]
Dim ReturnValue As New PlotSettings
Code: [Select]
Imports AAAS = Autodesk.AutoCAD.ApplicationServices
Imports AADS = Autodesk.AutoCAD.DatabaseServices
Imports AAG = Autodesk.AutoCAD.Geometry
Imports AAPS = Autodesk.AutoCAD.PlottingServices


Public Class PlotSettings

    Public Sub New(ByVal plotsettings As AADS.PlotSettings)

        Me.CfgName = plotsettings.PlotConfigurationName
        Me.ModelType = plotsettings.ModelType
        Me.OriginX = plotsettings.PlotOrigin.X
        Me.OriginY = plotsettings.PlotOrigin.y
        Me.PaperHeight = plotsettings.PlotPaperSize.Y '?
        Me.PaperUnits = plotsettings.PlotPaperUnits
        Me.PaperWidth = plotsettings.PlotPaperSize.X '?
        Me.PaperXMax = plotsettings.PlotPaperMargins.MaxPoint.X
        Me.PaperXMin = plotsettings.PlotPaperMargins.minpoint.X
        Me.PaperYMax = plotsettings.PlotPaperMargins.MaxPoint.y
        Me.PaperYMin = plotsettings.PlotPaperMargins.minpoint.y
        Me.PapersizeDesc = plotsettings.CanonicalMediaName
        Me.PlotCentered = plotsettings.PlotCentered
        Me.PlotHidden = plotsettings.PlotHidden
        Me.PlotPlotstyles = plotsettings.PlotPlotStyles
        Me.PlotRotation = plotsettings.PlotRotation
        Me.PlotType = plotsettings.PlotType
        Me.PrintLineweights = plotsettings.PrintLineweights
        Me.PrintScaleDenominator = plotsettings.CustomPrintScale.Denominator
        Me.PrintScaleNumerator = plotsettings.CustomPrintScale.Numerator
        Me.ScaleLineweights = plotsettings.ScaleLineweights
        Me.ScaleType = plotsettings.StdScaleType
        Me.ShowPlotstyles = plotsettings.ShowPlotStyles
        Me.StandardScale = plotsettings.StdScale
        Me.StyleSheet = plotsettings.CurrentStyleSheet
        Me.UseStandardScale = plotsettings.UseStandardScale
        Me.ViewportBorders = plotsettings.PlotViewportBorders
        Me.ViewportsFirst = plotsettings.DrawViewportsFirst
        Me.WindowXMax = plotsettings.PlotWindowArea.MaxPoint.X
        Me.WindowXMin = plotsettings.PlotWindowArea.MinPoint.X
        Me.WindowYMax = plotsettings.PlotWindowArea.MaxPoint.y
        Me.WindowYMin = plotsettings.PlotWindowArea.MinPoint.y

    End Sub

#Region " Properties "

    Public Property CfgName As String
    Public Property ModelType As Integer
    Public Property OriginX As Double
    Public Property OriginY As Double
    Public Property PaperHeight As Double
    Public Property PaperUnits As Integer
    Public Property PaperWidth As Double
    Public Property PaperXMax As Double
    Public Property PaperXMin As Double
    Public Property PaperYMax As Double
    Public Property PaperYMin As Double
    Public Property PapersizeDesc As String
    Public Property PlotCentered As Integer
    Public Property PlotHidden As Integer
    Public Property PlotPlotstyles As Integer
    Public Property PlotRotation As Integer
    Public Property PlotType As Integer
    Public Property PrintLineweights As Integer
    Public Property PrintScaleDenominator As Double
    Public Property PrintScaleNumerator As Double
    Public Property ScaleLineweights As Integer
    Public Property ScaleType As Integer
    Public Property SettingName As String
    Public Property ShowPlotstyles As Integer
    Public Property StandardScale As Double
    Public Property StyleSheet As String
    Public Property UseStandardScale As Integer
    Public Property ViewportBorders As Integer
    Public Property ViewportsFirst As Integer
    Public Property WindowXMax As Double
    Public Property WindowXMin As Double
    Public Property WindowYMax As Double
    Public Property WindowYMin As Double

#End Region

#Region " Shared "

    Public Function AcadEquivalent() As AADS.PlotSettings

        Dim Validator As AADS.PlotSettingsValidator = AADS.PlotSettingsValidator.Current

        Dim ReturnValue As AADS.PlotSettings = New AADS.PlotSettings(Me.ModelType)
        Validator.SetPlotConfigurationName(ReturnValue, Me.CfgName, Me.PapersizeDesc)
        Validator.SetPlotOrigin(ReturnValue, New AAG.Point2d(Me.OriginX, Me.OriginY))
        Validator.SetPlotPaperUnits(ReturnValue, Me.PaperUnits)

        Validator.SetPlotWindowArea(ReturnValue, New AADS.Extents2d(Me.WindowXMin, Me.WindowYMin, Me.WindowXMax, Me.windowYMax))
        Validator.SetPlotType(returnvalue, Me.PlotType)
        Validator.SetPlotCentered(ReturnValue, Me.PlotCentered)
        ReturnValue.PlotHidden = Me.PlotHidden
        Validator.SetPlotRotation(ReturnValue, Me.PlotRotation)
        ReturnValue.PrintLineweights = Me.PrintLineweights

        Validator.SetUseStandardScale(ReturnValue, Me.UseStandardScale)
        If ReturnValue.UseStandardScale = True Then
            'Validator.SetStdScale(ReturnValue, Me.StdScale)
            Validator.SetStdScale(ReturnValue, Me.StandardScale)
            'Validator.SetStdScaleType(ReturnValue, Me.StdScaleType)
            Validator.SetStdScaleType(ReturnValue, Me.ScaleType)
        Else
            Validator.SetCustomPrintScale(ReturnValue, New AADS.CustomScale(Me.PrintScaleNumerator, Me.PrintScaleDenominator))
        End If

        ReturnValue.ScaleLineweights = Me.ScaleLineweights
        ReturnValue.ShowPlotstyles = Me.ShowPlotstyles
        Validator.SetCurrentStyleSheet(returnvalue, Me.StyleSheet)
        ReturnValue.PlotViewportBorders = Me.ViewportBorders
        ReturnValue.DrawViewportsFirst = Me.ViewportsFirst

        Return returnvalue

    End Function

    Public Shared Function FromRegistry(ByVal ModelType As Boolean) As PlotSettings

        Dim ReturnValue As New PlotSettings

        'HKEY_CURRENT_USER\Software\Autodesk\AutoCAD\R18.1\ACAD-9002:409\Profiles\TRACKSTAR_GENERIC_MAP_2011\Previous plot settings
        Dim ProdKeyStr As String
        ProdKeyStr = Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.ProductKey
        Dim PreviousPlotSettings As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(String.Format(ProdKeyStr & "\Profiles\{0}\Previous plot settings", AAAS.Application.GetSystemVariable("cprofile")), False)
        'Dim PreviousPlotSettings As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(String.Format("Software\Autodesk\AutoCAD\R18.1\ACAD-9002:409\Profiles\{0}\Previous plot settings", AAAS.Application.GetSystemVariable("cprofile")), False)
       
        If ModelType = True Then
            PreviousPlotSettings = PreviousPlotSettings.opensubkey("Model")
        Else
            PreviousPlotSettings = PreviousPlotSettings.opensubkey("Layout")
        End If

        ReturnValue.CfgName = PreviousPlotSettings.GetValue("Cfg Name")
        ReturnValue.ModelType = PreviousPlotSettings.GetValue("Model type")
        ReturnValue.OriginX = CDbl(PreviousPlotSettings.GetValue("Origin X"))
        ReturnValue.OriginY = CDbl(PreviousPlotSettings.GetValue("Origin Y"))
        ReturnValue.PaperHeight = PreviousPlotSettings.GetValue("Paper height")
        ReturnValue.PaperUnits = PreviousPlotSettings.GetValue("Paper units")
        ReturnValue.PaperWidth = PreviousPlotSettings.GetValue("Paper width")
        ReturnValue.PaperXMax = PreviousPlotSettings.GetValue("Paper XMax")
        ReturnValue.PaperXMin = PreviousPlotSettings.GetValue("Paper XMin")
        ReturnValue.PaperYMax = PreviousPlotSettings.GetValue("Paper YMax")
        ReturnValue.PaperYMin = PreviousPlotSettings.GetValue("Paper YMin")
        ReturnValue.PapersizeDesc = PreviousPlotSettings.GetValue("Papersize desc")
        ReturnValue.PlotCentered = PreviousPlotSettings.GetValue("Plot centered")
        ReturnValue.PlotHidden = PreviousPlotSettings.GetValue("Plot hidden")
        ReturnValue.PlotPlotstyles = PreviousPlotSettings.GetValue("Plot plotstyles")
        ReturnValue.PlotRotation = PreviousPlotSettings.GetValue("Plot rotation")
        ReturnValue.PlotType = PreviousPlotSettings.GetValue("Plot type")
        ReturnValue.PrintLineweights = PreviousPlotSettings.GetValue("Print lineweights")
        ReturnValue.PrintScaleDenominator = CDbl(PreviousPlotSettings.GetValue("Print scale denominator"))
        ReturnValue.PrintScaleNumerator = CDbl(PreviousPlotSettings.GetValue("Print scale numerator"))
        ReturnValue.ScaleLineweights = PreviousPlotSettings.GetValue("Scale lineweights")
        ReturnValue.ScaleType = PreviousPlotSettings.GetValue("Scale type")
        ReturnValue.ShowPlotstyles = PreviousPlotSettings.GetValue("Show plotstyles")
        ReturnValue.StandardScale = PreviousPlotSettings.GetValue("Standard scale")
        ReturnValue.StyleSheet = PreviousPlotSettings.GetValue("Style sheet")
        ReturnValue.UseStandardScale = PreviousPlotSettings.GetValue("Use standard scale")
        ReturnValue.ViewportBorders = PreviousPlotSettings.GetValue("Viewport borders")
        ReturnValue.ViewportsFirst = PreviousPlotSettings.GetValue("Viewports first")
        ReturnValue.WindowXMax = PreviousPlotSettings.GetValue("Window XMax")
        ReturnValue.WindowXMin = PreviousPlotSettings.GetValue("Window XMin")
        ReturnValue.WindowYMax = PreviousPlotSettings.GetValue("Window YMax")
        ReturnValue.WindowYMin = PreviousPlotSettings.GetValue("Window YMin")

        Return returnvalue

    End Function

#End Region

End Class




Where do I put this following code?

Code: [Select]
<CommandMethodAttribute("PPT")> _
Public Sub PreviousPlot

Dim pe As New PlottingServices.PlotEngine
pe.Plot(PlotSettings.FromRegistry(False).AcadEquivalent)

End Sub


Jeff_M

  • King Gator
  • Posts: 4099
  • C3D user & customizer
Re: Need Plot Previous, and Send command...NOOB. Coverting VBA to VB.Net
« Reply #14 on: February 27, 2012, 04:30:41 PM »
Do you know any reason to use one over the other?
Nope. Until just recently I wasn't aware there were 2 methods to do this. I learned to use the DynamicLinker approach from an old post by Tony on the Autodesk .NET forum. 2013 will change how I do this.....