<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Plot from model space in VBA Forum</title>
    <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336458#M18134</link>
    <description>Hi Joe, Thanks for looking at my issue!&lt;BR /&gt;
Im all tangled up and not sure were to add your example in my code? I'm still gettin error saying the "new" keyword.&lt;BR /&gt;
&lt;BR /&gt;
Here is the rest of my code if that helps...&lt;BR /&gt;
&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop.Common&lt;BR /&gt;
&lt;BR /&gt;
Public Class Form1&lt;BR /&gt;
    Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication&lt;BR /&gt;
    Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub GetAcadApplication()&lt;BR /&gt;
        Try&lt;BR /&gt;
            AcadApp = GetObject(, "AutoCAD.Application.17.1")&lt;BR /&gt;
            AcadApp.Visible = True&lt;BR /&gt;
        Catch&lt;BR /&gt;
            Try&lt;BR /&gt;
                AcadApp = CreateObject("AutoCAD.Application.17.1")&lt;BR /&gt;
                AcadApp.Visible = True&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                MsgBox(ex.ToString, MsgBoxStyle.Critical)&lt;BR /&gt;
                Exit Sub&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End Try&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub RetrieveDwgs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetrieveDwgs.Click&lt;BR /&gt;
        Dim openFileDialog1 As New OpenFileDialog()&lt;BR /&gt;
        Try&lt;BR /&gt;
            openFileDialog1.InitialDirectory = "j:\"&lt;BR /&gt;
        Catch&lt;BR /&gt;
            openFileDialog1.InitialDirectory = "c:\"&lt;BR /&gt;
        End Try&lt;BR /&gt;
        openFileDialog1.Filter = "dwg files (*.dwg)|*.dwg"&lt;BR /&gt;
        openFileDialog1.FilterIndex = 2&lt;BR /&gt;
        openFileDialog1.RestoreDirectory = True&lt;BR /&gt;
        openFileDialog1.Multiselect = True&lt;BR /&gt;
        If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            Dim count As Integer = openFileDialog1.FileNames.Length.ToString&lt;BR /&gt;
            Dim I&lt;BR /&gt;
            For I = 0 To count - 1&lt;BR /&gt;
                ListBox1.Items.Add(openFileDialog1.FileNames.GetValue(I).ToString)&lt;BR /&gt;
            Next&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick&lt;BR /&gt;
        ListBox1.Items.Remove(ListBox1.SelectedItem)&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub ProcessDirectory(ByVal targetDirectory As String)&lt;BR /&gt;
        Dim fileEntries As String() = System.IO.Directory.GetFiles(targetDirectory)&lt;BR /&gt;
        Dim fileName As String&lt;BR /&gt;
        For Each fileName In fileEntries&lt;BR /&gt;
            If LCase(System.IO.Path.GetExtension(fileName)) = ".dwg" Then&lt;BR /&gt;
                ListBox1.Items.Add(fileName)&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next fileName&lt;BR /&gt;
        Dim subdirectoryEntries As String() = System.IO.Directory.GetDirectories(targetDirectory)&lt;BR /&gt;
        Dim subdirectory As String&lt;BR /&gt;
        For Each subdirectory In subdirectoryEntries&lt;BR /&gt;
            ProcessDirectory(subdirectory)&lt;BR /&gt;
        Next subdirectory&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub WholeDirectory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WholeDirectory.Click&lt;BR /&gt;
        If FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            ProcessDirectory(FolderBrowserDialog1.SelectedPath)&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click&lt;BR /&gt;
        If ListBox1.Items.Count &amp;lt; 1 Then&lt;BR /&gt;
            MsgBox("You haven't selected any drawings to process.", MsgBoxStyle.Information, "Totals")&lt;BR /&gt;
            Exit Sub&lt;BR /&gt;
        End If&lt;BR /&gt;
        Call GetAcadApplication()&lt;BR /&gt;
        Dim I&lt;BR /&gt;
        Dim R As Integer = 0&lt;BR /&gt;
        Dim DwgName As String = ""&lt;BR /&gt;
        For I = 0 To ListBox1.Items.Count - 1&lt;BR /&gt;
            Try&lt;BR /&gt;
                acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
            Catch&lt;BR /&gt;
                acadDoc = AcadApp.Documents.Add&lt;BR /&gt;
            End Try&lt;BR /&gt;
            DwgName = ListBox1.Items.Item(0)&lt;BR /&gt;
            ProcessDwg(DwgName)&lt;BR /&gt;
            Try&lt;BR /&gt;
                acadDoc.Close(False, DwgName)&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                'MsgBox("Some Error closing the drawing." &amp;amp; vbCrLf &amp;amp; ex.ToString)&lt;BR /&gt;
            End Try&lt;BR /&gt;
            ListBox1.Items.RemoveAt(0)&lt;BR /&gt;
            R = R + 1&lt;BR /&gt;
        Next&lt;BR /&gt;
        MsgBox("Processed " &amp;amp; R &amp;amp; " Drawings")&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub ProcessDwg(ByVal ThisDwg As String)&lt;BR /&gt;
        acadDoc.Application.Documents.Open(ThisDwg)&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        'Add code to do something with the drawing here.&lt;BR /&gt;
        'code....&lt;BR /&gt;
        'code....&lt;BR /&gt;
        'code....&lt;BR /&gt;
&lt;BR /&gt;
        Call TEST()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub TEST()&lt;BR /&gt;
&lt;BR /&gt;
        Dim ACADPref As AcadPreferencesOpenSave&lt;BR /&gt;
        Dim originalValue As Object&lt;BR /&gt;
        ACADPref = acadDoc.Application.Preferences.OpenSave&lt;BR /&gt;
&lt;BR /&gt;
        originalValue = ACADPref.SaveAsType&lt;BR /&gt;
&lt;BR /&gt;
        MsgBox(originalValue.ToString)&lt;BR /&gt;
&lt;BR /&gt;
        ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg&lt;BR /&gt;
&lt;BR /&gt;
        Exit Sub&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click&lt;BR /&gt;
        Call GetAcadApplication()&lt;BR /&gt;
        Call Ch9_PrintModelSpace()&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
        Dim ACADPref As AcadPreferencesOpenSave&lt;BR /&gt;
        ACADPref = acadDoc.Application.Preferences.OpenSave&lt;BR /&gt;
        ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg&lt;BR /&gt;
        acadDoc.Save()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub Ch9_PrintModelSpace()&lt;BR /&gt;
        ' Verify that the active space is model space&lt;BR /&gt;
        If acadDoc.ActiveSpace = AcActiveSpace.acModelSpace Then&lt;BR /&gt;
            acadDoc.MSpace = True&lt;BR /&gt;
            acadDoc.ActiveSpace = AcActiveSpace.acModelSpace&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the extents and scale of the plot area&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.PlotType = AcPlotType.acExtents&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.StandardScale = AcPlotScale.acScaleToFit&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the number of copies to one&lt;BR /&gt;
        acadDoc.Plot.NumberOfCopies = 1&lt;BR /&gt;
&lt;BR /&gt;
        ' Initiate the plot&lt;BR /&gt;
        acadDoc.Plot.PlotToDevice()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
End Class</description>
    <pubDate>Fri, 05 Sep 2008 10:32:02 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2008-09-05T10:32:02Z</dc:date>
    <item>
      <title>Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336453#M18129</link>
      <description>I’m new to VB and looking for some help on this...I’m writing a windows app that will batch plot acad dwgs...I found this example code in the developers help section &lt;BR /&gt;
but get this error - Use the "new" keyword to create an object instance.&lt;BR /&gt;
&lt;BR /&gt;
I tried a few different scenarios with no luck &lt;BR /&gt;
I haven’t got a clue where to use the "new" keyword&lt;BR /&gt;
&lt;BR /&gt;
Here is the code&lt;BR /&gt;
&lt;BR /&gt;
Sub Ch9_PrintModelSpace()&lt;BR /&gt;
        ' Verify that the active space is model space&lt;BR /&gt;
        If acadDoc.ActiveSpace = AcActiveSpace.acModelSpace Then&lt;BR /&gt;
            acadDoc.MSpace = True&lt;BR /&gt;
            acadDoc.ActiveSpace = AcActiveSpace.acModelSpace&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the extents and scale of the plot area&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.PlotType = AcPlotType.acExtents&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.StandardScale = AcPlotScale.acScaleToFit&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the number of copies to one&lt;BR /&gt;
        acadDoc.Plot.NumberOfCopies = 1&lt;BR /&gt;
&lt;BR /&gt;
        ' Initiate the plot&lt;BR /&gt;
        acadDoc.Plot.PlotToDevice()&lt;BR /&gt;
    End Sub</description>
      <pubDate>Thu, 04 Sep 2008 19:23:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336453#M18129</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-04T19:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336454#M18130</link>
      <description>do you have more code you could post?  i.e. did you set acaddoc to anything?</description>
      <pubDate>Thu, 04 Sep 2008 23:21:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336454#M18130</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-04T23:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336455#M18131</link>
      <description>Sounds like you have not instantiated your AcadDoc object. Based on your &lt;BR /&gt;
posting I don't see where that occurs. Basically, you must do the following &lt;BR /&gt;
somewhere within your application.&lt;BR /&gt;
&lt;BR /&gt;
Dim AcadApp As AcadApplication&lt;BR /&gt;
&lt;BR /&gt;
On Error Resume Next&lt;BR /&gt;
&lt;BR /&gt;
Set AcadApp = GetObject(Class:="AutoCAD.Application")&lt;BR /&gt;
&lt;BR /&gt;
If Err Then&lt;BR /&gt;
  Err.Clear&lt;BR /&gt;
&lt;BR /&gt;
  Set AcadApp = CreateObject(Class:="AutoCAD.Application")&lt;BR /&gt;
&lt;BR /&gt;
  If Err Then&lt;BR /&gt;
    MsgBox "Error connecting to AutoCAD", vbCritical, "AutoCAD Fatal Error"&lt;BR /&gt;
    Exit Sub&lt;BR /&gt;
  End If&lt;BR /&gt;
End If&lt;BR /&gt;
&lt;BR /&gt;
Set AcadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
Joe ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"smiche" wrote in message news:6023496@discussion.autodesk.com...&lt;BR /&gt;
I’m new to VB and looking for some help on this...I’m writing a windows app &lt;BR /&gt;
that will batch plot acad dwgs...I found this example code in the developers &lt;BR /&gt;
help section&lt;BR /&gt;
but get this error - Use the "new" keyword to create an object instance.&lt;BR /&gt;
&lt;BR /&gt;
I tried a few different scenarios with no luck&lt;BR /&gt;
I haven’t got a clue where to use the "new" keyword&lt;BR /&gt;
&lt;BR /&gt;
Here is the code&lt;BR /&gt;
&lt;BR /&gt;
Sub Ch9_PrintModelSpace()&lt;BR /&gt;
        ' Verify that the active space is model space&lt;BR /&gt;
        If acadDoc.ActiveSpace = AcActiveSpace.acModelSpace Then&lt;BR /&gt;
            acadDoc.MSpace = True&lt;BR /&gt;
            acadDoc.ActiveSpace = AcActiveSpace.acModelSpace&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the extents and scale of the plot area&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.PlotType = AcPlotType.acExtents&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.StandardScale = AcPlotScale.acScaleToFit&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the number of copies to one&lt;BR /&gt;
        acadDoc.Plot.NumberOfCopies = 1&lt;BR /&gt;
&lt;BR /&gt;
        ' Initiate the plot&lt;BR /&gt;
        acadDoc.Plot.PlotToDevice()&lt;BR /&gt;
    End Sub</description>
      <pubDate>Thu, 04 Sep 2008 23:25:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336455#M18131</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-04T23:25:38Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336456#M18132</link>
      <description>much better said! that's why you're an author &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 04 Sep 2008 23:44:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336456#M18132</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-04T23:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336457#M18133</link>
      <description>Sorry, I posted before hitting refresh.&lt;BR /&gt;
&lt;BR /&gt;
Joe ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"cadger" wrote in message news:6023781@discussion.autodesk.com...&lt;BR /&gt;
much better said! that's why you're an author &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 05 Sep 2008 00:31:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336457#M18133</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-05T00:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336458#M18134</link>
      <description>Hi Joe, Thanks for looking at my issue!&lt;BR /&gt;
Im all tangled up and not sure were to add your example in my code? I'm still gettin error saying the "new" keyword.&lt;BR /&gt;
&lt;BR /&gt;
Here is the rest of my code if that helps...&lt;BR /&gt;
&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop.Common&lt;BR /&gt;
&lt;BR /&gt;
Public Class Form1&lt;BR /&gt;
    Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication&lt;BR /&gt;
    Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub GetAcadApplication()&lt;BR /&gt;
        Try&lt;BR /&gt;
            AcadApp = GetObject(, "AutoCAD.Application.17.1")&lt;BR /&gt;
            AcadApp.Visible = True&lt;BR /&gt;
        Catch&lt;BR /&gt;
            Try&lt;BR /&gt;
                AcadApp = CreateObject("AutoCAD.Application.17.1")&lt;BR /&gt;
                AcadApp.Visible = True&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                MsgBox(ex.ToString, MsgBoxStyle.Critical)&lt;BR /&gt;
                Exit Sub&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End Try&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub RetrieveDwgs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetrieveDwgs.Click&lt;BR /&gt;
        Dim openFileDialog1 As New OpenFileDialog()&lt;BR /&gt;
        Try&lt;BR /&gt;
            openFileDialog1.InitialDirectory = "j:\"&lt;BR /&gt;
        Catch&lt;BR /&gt;
            openFileDialog1.InitialDirectory = "c:\"&lt;BR /&gt;
        End Try&lt;BR /&gt;
        openFileDialog1.Filter = "dwg files (*.dwg)|*.dwg"&lt;BR /&gt;
        openFileDialog1.FilterIndex = 2&lt;BR /&gt;
        openFileDialog1.RestoreDirectory = True&lt;BR /&gt;
        openFileDialog1.Multiselect = True&lt;BR /&gt;
        If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            Dim count As Integer = openFileDialog1.FileNames.Length.ToString&lt;BR /&gt;
            Dim I&lt;BR /&gt;
            For I = 0 To count - 1&lt;BR /&gt;
                ListBox1.Items.Add(openFileDialog1.FileNames.GetValue(I).ToString)&lt;BR /&gt;
            Next&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick&lt;BR /&gt;
        ListBox1.Items.Remove(ListBox1.SelectedItem)&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub ProcessDirectory(ByVal targetDirectory As String)&lt;BR /&gt;
        Dim fileEntries As String() = System.IO.Directory.GetFiles(targetDirectory)&lt;BR /&gt;
        Dim fileName As String&lt;BR /&gt;
        For Each fileName In fileEntries&lt;BR /&gt;
            If LCase(System.IO.Path.GetExtension(fileName)) = ".dwg" Then&lt;BR /&gt;
                ListBox1.Items.Add(fileName)&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next fileName&lt;BR /&gt;
        Dim subdirectoryEntries As String() = System.IO.Directory.GetDirectories(targetDirectory)&lt;BR /&gt;
        Dim subdirectory As String&lt;BR /&gt;
        For Each subdirectory In subdirectoryEntries&lt;BR /&gt;
            ProcessDirectory(subdirectory)&lt;BR /&gt;
        Next subdirectory&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub WholeDirectory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WholeDirectory.Click&lt;BR /&gt;
        If FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            ProcessDirectory(FolderBrowserDialog1.SelectedPath)&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click&lt;BR /&gt;
        If ListBox1.Items.Count &amp;lt; 1 Then&lt;BR /&gt;
            MsgBox("You haven't selected any drawings to process.", MsgBoxStyle.Information, "Totals")&lt;BR /&gt;
            Exit Sub&lt;BR /&gt;
        End If&lt;BR /&gt;
        Call GetAcadApplication()&lt;BR /&gt;
        Dim I&lt;BR /&gt;
        Dim R As Integer = 0&lt;BR /&gt;
        Dim DwgName As String = ""&lt;BR /&gt;
        For I = 0 To ListBox1.Items.Count - 1&lt;BR /&gt;
            Try&lt;BR /&gt;
                acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
            Catch&lt;BR /&gt;
                acadDoc = AcadApp.Documents.Add&lt;BR /&gt;
            End Try&lt;BR /&gt;
            DwgName = ListBox1.Items.Item(0)&lt;BR /&gt;
            ProcessDwg(DwgName)&lt;BR /&gt;
            Try&lt;BR /&gt;
                acadDoc.Close(False, DwgName)&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                'MsgBox("Some Error closing the drawing." &amp;amp; vbCrLf &amp;amp; ex.ToString)&lt;BR /&gt;
            End Try&lt;BR /&gt;
            ListBox1.Items.RemoveAt(0)&lt;BR /&gt;
            R = R + 1&lt;BR /&gt;
        Next&lt;BR /&gt;
        MsgBox("Processed " &amp;amp; R &amp;amp; " Drawings")&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub ProcessDwg(ByVal ThisDwg As String)&lt;BR /&gt;
        acadDoc.Application.Documents.Open(ThisDwg)&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        'Add code to do something with the drawing here.&lt;BR /&gt;
        'code....&lt;BR /&gt;
        'code....&lt;BR /&gt;
        'code....&lt;BR /&gt;
&lt;BR /&gt;
        Call TEST()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub TEST()&lt;BR /&gt;
&lt;BR /&gt;
        Dim ACADPref As AcadPreferencesOpenSave&lt;BR /&gt;
        Dim originalValue As Object&lt;BR /&gt;
        ACADPref = acadDoc.Application.Preferences.OpenSave&lt;BR /&gt;
&lt;BR /&gt;
        originalValue = ACADPref.SaveAsType&lt;BR /&gt;
&lt;BR /&gt;
        MsgBox(originalValue.ToString)&lt;BR /&gt;
&lt;BR /&gt;
        ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg&lt;BR /&gt;
&lt;BR /&gt;
        Exit Sub&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click&lt;BR /&gt;
        Call GetAcadApplication()&lt;BR /&gt;
        Call Ch9_PrintModelSpace()&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
        Dim ACADPref As AcadPreferencesOpenSave&lt;BR /&gt;
        ACADPref = acadDoc.Application.Preferences.OpenSave&lt;BR /&gt;
        ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg&lt;BR /&gt;
        acadDoc.Save()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub Ch9_PrintModelSpace()&lt;BR /&gt;
        ' Verify that the active space is model space&lt;BR /&gt;
        If acadDoc.ActiveSpace = AcActiveSpace.acModelSpace Then&lt;BR /&gt;
            acadDoc.MSpace = True&lt;BR /&gt;
            acadDoc.ActiveSpace = AcActiveSpace.acModelSpace&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the extents and scale of the plot area&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.PlotType = AcPlotType.acExtents&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.StandardScale = AcPlotScale.acScaleToFit&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the number of copies to one&lt;BR /&gt;
        acadDoc.Plot.NumberOfCopies = 1&lt;BR /&gt;
&lt;BR /&gt;
        ' Initiate the plot&lt;BR /&gt;
        acadDoc.Plot.PlotToDevice()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
End Class</description>
      <pubDate>Fri, 05 Sep 2008 10:32:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336458#M18134</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-05T10:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336459#M18135</link>
      <description>What line of code causes the error?&lt;BR /&gt;
&lt;BR /&gt;
Joe ...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;SMICHE&gt; wrote in message news:6024032@discussion.autodesk.com...&lt;BR /&gt;
Hi Joe, Thanks for looking at my issue!&lt;BR /&gt;
Im all tangled up and not sure were to add your example in my code? I'm &lt;BR /&gt;
still gettin error saying the "new" keyword.&lt;BR /&gt;
&lt;BR /&gt;
Here is the rest of my code if that helps...&lt;BR /&gt;
&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop&lt;BR /&gt;
Imports Autodesk.AutoCAD.Interop.Common&lt;BR /&gt;
&lt;BR /&gt;
Public Class Form1&lt;BR /&gt;
    Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication&lt;BR /&gt;
    Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument&lt;BR /&gt;
&lt;BR /&gt;
    Public Sub GetAcadApplication()&lt;BR /&gt;
        Try&lt;BR /&gt;
            AcadApp = GetObject(, "AutoCAD.Application.17.1")&lt;BR /&gt;
            AcadApp.Visible = True&lt;BR /&gt;
        Catch&lt;BR /&gt;
            Try&lt;BR /&gt;
                AcadApp = CreateObject("AutoCAD.Application.17.1")&lt;BR /&gt;
                AcadApp.Visible = True&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                MsgBox(ex.ToString, MsgBoxStyle.Critical)&lt;BR /&gt;
                Exit Sub&lt;BR /&gt;
            End Try&lt;BR /&gt;
        End Try&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub RetrieveDwgs_Click(ByVal sender As System.Object, ByVal e As &lt;BR /&gt;
System.EventArgs) Handles RetrieveDwgs.Click&lt;BR /&gt;
        Dim openFileDialog1 As New OpenFileDialog()&lt;BR /&gt;
        Try&lt;BR /&gt;
            openFileDialog1.InitialDirectory = "j:\"&lt;BR /&gt;
        Catch&lt;BR /&gt;
            openFileDialog1.InitialDirectory = "c:\"&lt;BR /&gt;
        End Try&lt;BR /&gt;
        openFileDialog1.Filter = "dwg files (*.dwg)|*.dwg"&lt;BR /&gt;
        openFileDialog1.FilterIndex = 2&lt;BR /&gt;
        openFileDialog1.RestoreDirectory = True&lt;BR /&gt;
        openFileDialog1.Multiselect = True&lt;BR /&gt;
        If openFileDialog1.ShowDialog() = &lt;BR /&gt;
System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            Dim count As Integer = openFileDialog1.FileNames.Length.ToString&lt;BR /&gt;
            Dim I&lt;BR /&gt;
            For I = 0 To count - 1&lt;BR /&gt;
                ListBox1.Items.Add(openFileDialog1.FileNames.GetValue(I).ToString)&lt;BR /&gt;
            Next&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As &lt;BR /&gt;
System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick&lt;BR /&gt;
        ListBox1.Items.Remove(ListBox1.SelectedItem)&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub ProcessDirectory(ByVal targetDirectory As String)&lt;BR /&gt;
        Dim fileEntries As String() = &lt;BR /&gt;
System.IO.Directory.GetFiles(targetDirectory)&lt;BR /&gt;
        Dim fileName As String&lt;BR /&gt;
        For Each fileName In fileEntries&lt;BR /&gt;
            If LCase(System.IO.Path.GetExtension(fileName)) = ".dwg" Then&lt;BR /&gt;
                ListBox1.Items.Add(fileName)&lt;BR /&gt;
            End If&lt;BR /&gt;
        Next fileName&lt;BR /&gt;
        Dim subdirectoryEntries As String() = &lt;BR /&gt;
System.IO.Directory.GetDirectories(targetDirectory)&lt;BR /&gt;
        Dim subdirectory As String&lt;BR /&gt;
        For Each subdirectory In subdirectoryEntries&lt;BR /&gt;
            ProcessDirectory(subdirectory)&lt;BR /&gt;
        Next subdirectory&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub WholeDirectory_Click(ByVal sender As System.Object, ByVal e &lt;BR /&gt;
As System.EventArgs) Handles WholeDirectory.Click&lt;BR /&gt;
        If FolderBrowserDialog1.ShowDialog() = &lt;BR /&gt;
System.Windows.Forms.DialogResult.OK Then&lt;BR /&gt;
            ProcessDirectory(FolderBrowserDialog1.SelectedPath)&lt;BR /&gt;
        End If&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub Go_Click(ByVal sender As System.Object, ByVal e As &lt;BR /&gt;
System.EventArgs) Handles Go.Click&lt;BR /&gt;
        If ListBox1.Items.Count &amp;lt; 1 Then&lt;BR /&gt;
            MsgBox("You haven't selected any drawings to process.", &lt;BR /&gt;
MsgBoxStyle.Information, "Totals")&lt;BR /&gt;
            Exit Sub&lt;BR /&gt;
        End If&lt;BR /&gt;
        Call GetAcadApplication()&lt;BR /&gt;
        Dim I&lt;BR /&gt;
        Dim R As Integer = 0&lt;BR /&gt;
        Dim DwgName As String = ""&lt;BR /&gt;
        For I = 0 To ListBox1.Items.Count - 1&lt;BR /&gt;
            Try&lt;BR /&gt;
                acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
            Catch&lt;BR /&gt;
                acadDoc = AcadApp.Documents.Add&lt;BR /&gt;
            End Try&lt;BR /&gt;
            DwgName = ListBox1.Items.Item(0)&lt;BR /&gt;
            ProcessDwg(DwgName)&lt;BR /&gt;
            Try&lt;BR /&gt;
                acadDoc.Close(False, DwgName)&lt;BR /&gt;
            Catch ex As Exception&lt;BR /&gt;
                'MsgBox("Some Error closing the drawing." &amp;amp; vbCrLf &amp;amp; &lt;BR /&gt;
ex.ToString)&lt;BR /&gt;
            End Try&lt;BR /&gt;
            ListBox1.Items.RemoveAt(0)&lt;BR /&gt;
            R = R + 1&lt;BR /&gt;
        Next&lt;BR /&gt;
        MsgBox("Processed " &amp;amp; R &amp;amp; " Drawings")&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub ProcessDwg(ByVal ThisDwg As String)&lt;BR /&gt;
        acadDoc.Application.Documents.Open(ThisDwg)&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
&lt;BR /&gt;
        'Add code to do something with the drawing here.&lt;BR /&gt;
        'code....&lt;BR /&gt;
        'code....&lt;BR /&gt;
        'code....&lt;BR /&gt;
&lt;BR /&gt;
        Call TEST()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub TEST()&lt;BR /&gt;
&lt;BR /&gt;
        Dim ACADPref As AcadPreferencesOpenSave&lt;BR /&gt;
        Dim originalValue As Object&lt;BR /&gt;
        ACADPref = acadDoc.Application.Preferences.OpenSave&lt;BR /&gt;
&lt;BR /&gt;
        originalValue = ACADPref.SaveAsType&lt;BR /&gt;
&lt;BR /&gt;
        MsgBox(originalValue.ToString)&lt;BR /&gt;
&lt;BR /&gt;
        ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg&lt;BR /&gt;
&lt;BR /&gt;
        Exit Sub&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As &lt;BR /&gt;
System.EventArgs) Handles Button1.Click&lt;BR /&gt;
        Call GetAcadApplication()&lt;BR /&gt;
        Call Ch9_PrintModelSpace()&lt;BR /&gt;
        acadDoc = AcadApp.ActiveDocument&lt;BR /&gt;
        Dim ACADPref As AcadPreferencesOpenSave&lt;BR /&gt;
        ACADPref = acadDoc.Application.Preferences.OpenSave&lt;BR /&gt;
        ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg&lt;BR /&gt;
        acadDoc.Save()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
    Sub Ch9_PrintModelSpace()&lt;BR /&gt;
        ' Verify that the active space is model space&lt;BR /&gt;
        If acadDoc.ActiveSpace = AcActiveSpace.acModelSpace Then&lt;BR /&gt;
            acadDoc.MSpace = True&lt;BR /&gt;
            acadDoc.ActiveSpace = AcActiveSpace.acModelSpace&lt;BR /&gt;
        End If&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the extents and scale of the plot area&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.PlotType = AcPlotType.acExtents&lt;BR /&gt;
        acadDoc.ModelSpace.Layout.StandardScale = AcPlotScale.acScaleToFit&lt;BR /&gt;
&lt;BR /&gt;
        ' Set the number of copies to one&lt;BR /&gt;
        acadDoc.Plot.NumberOfCopies = 1&lt;BR /&gt;
&lt;BR /&gt;
        ' Initiate the plot&lt;BR /&gt;
        acadDoc.Plot.PlotToDevice()&lt;BR /&gt;
&lt;BR /&gt;
    End Sub&lt;BR /&gt;
&lt;BR /&gt;
End Class&lt;/SMICHE&gt;</description>
      <pubDate>Sat, 06 Sep 2008 18:08:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336459#M18135</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-06T18:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Plot from model space</title>
      <link>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336460#M18136</link>
      <description>Joe,&lt;BR /&gt;
&lt;BR /&gt;
 I ended up using a script file to batch plot multiple dwgs!&lt;BR /&gt;
&lt;BR /&gt;
Thanks</description>
      <pubDate>Mon, 08 Sep 2008 14:01:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/vba-forum/plot-from-model-space/m-p/2336460#M18136</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2008-09-08T14:01:11Z</dc:date>
    </item>
  </channel>
</rss>

