Hi Joe, Thanks for looking at my issue!
Im all tangled up and not sure were to add your example in my code? I'm still gettin error saying the "new" keyword.
Here is the rest of my code if that helps...
Imports Autodesk.AutoCAD.Interop
Imports Autodesk.AutoCAD.Interop.Common
Public Class Form1
Public WithEvents AcadApp As Autodesk.AutoCAD.Interop.AcadApplication
Dim acadDoc As Autodesk.AutoCAD.Interop.AcadDocument
Public Sub GetAcadApplication()
Try
AcadApp = GetObject(, "AutoCAD.Application.17.1")
AcadApp.Visible = True
Catch
Try
AcadApp = CreateObject("AutoCAD.Application.17.1")
AcadApp.Visible = True
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical)
Exit Sub
End Try
End Try
End Sub
Private Sub RetrieveDwgs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RetrieveDwgs.Click
Dim openFileDialog1 As New OpenFileDialog()
Try
openFileDialog1.InitialDirectory = "j:\"
Catch
openFileDialog1.InitialDirectory = "c:\"
End Try
openFileDialog1.Filter = "dwg files (*.dwg)|*.dwg"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
openFileDialog1.Multiselect = True
If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim count As Integer = openFileDialog1.FileNames.Length.ToString
Dim I
For I = 0 To count - 1
ListBox1.Items.Add(openFileDialog1.FileNames.GetValue(I).ToString)
Next
End If
End Sub
Private Sub ListBox1_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListBox1.MouseDoubleClick
ListBox1.Items.Remove(ListBox1.SelectedItem)
End Sub
Sub ProcessDirectory(ByVal targetDirectory As String)
Dim fileEntries As String() = System.IO.Directory.GetFiles(targetDirectory)
Dim fileName As String
For Each fileName In fileEntries
If LCase(System.IO.Path.GetExtension(fileName)) = ".dwg" Then
ListBox1.Items.Add(fileName)
End If
Next fileName
Dim subdirectoryEntries As String() = System.IO.Directory.GetDirectories(targetDirectory)
Dim subdirectory As String
For Each subdirectory In subdirectoryEntries
ProcessDirectory(subdirectory)
Next subdirectory
End Sub
Private Sub WholeDirectory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WholeDirectory.Click
If FolderBrowserDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
ProcessDirectory(FolderBrowserDialog1.SelectedPath)
End If
End Sub
Private Sub Go_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Go.Click
If ListBox1.Items.Count < 1 Then
MsgBox("You haven't selected any drawings to process.", MsgBoxStyle.Information, "Totals")
Exit Sub
End If
Call GetAcadApplication()
Dim I
Dim R As Integer = 0
Dim DwgName As String = ""
For I = 0 To ListBox1.Items.Count - 1
Try
acadDoc = AcadApp.ActiveDocument
Catch
acadDoc = AcadApp.Documents.Add
End Try
DwgName = ListBox1.Items.Item(0)
ProcessDwg(DwgName)
Try
acadDoc.Close(False, DwgName)
Catch ex As Exception
'MsgBox("Some Error closing the drawing." & vbCrLf & ex.ToString)
End Try
ListBox1.Items.RemoveAt(0)
R = R + 1
Next
MsgBox("Processed " & R & " Drawings")
End Sub
Sub ProcessDwg(ByVal ThisDwg As String)
acadDoc.Application.Documents.Open(ThisDwg)
acadDoc = AcadApp.ActiveDocument
acadDoc = AcadApp.ActiveDocument
'Add code to do something with the drawing here.
'code....
'code....
'code....
Call TEST()
End Sub
Sub TEST()
Dim ACADPref As AcadPreferencesOpenSave
Dim originalValue As Object
ACADPref = acadDoc.Application.Preferences.OpenSave
originalValue = ACADPref.SaveAsType
MsgBox(originalValue.ToString)
ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg
Exit Sub
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call GetAcadApplication()
Call Ch9_PrintModelSpace()
acadDoc = AcadApp.ActiveDocument
Dim ACADPref As AcadPreferencesOpenSave
ACADPref = acadDoc.Application.Preferences.OpenSave
ACADPref.SaveAsType = AcSaveAsType.ac2000_dwg
acadDoc.Save()
End Sub
Sub Ch9_PrintModelSpace()
' Verify that the active space is model space
If acadDoc.ActiveSpace = AcActiveSpace.acModelSpace Then
acadDoc.MSpace = True
acadDoc.ActiveSpace = AcActiveSpace.acModelSpace
End If
' Set the extents and scale of the plot area
acadDoc.ModelSpace.Layout.PlotType = AcPlotType.acExtents
acadDoc.ModelSpace.Layout.StandardScale = AcPlotScale.acScaleToFit
' Set the number of copies to one
acadDoc.Plot.NumberOfCopies = 1
' Initiate the plot
acadDoc.Plot.PlotToDevice()
End Sub
End Class