wmassie
2009-08-14, 07:46 PM
I am writing my first practical .NET app. So I am very much a beginner. In the code below, after executing the following line:
Dim acDoc As Document = acDocMgr.Open(strFileName, False)
inspection of "acDoc" shows that it is not the active document (rather the document in which the NETLOAD command was issued remains active). Is there a way to run the app over multiple documents so that the document returned from the "open" function automatically becomes the active document or is there a way to make it active?
By the way, I am also open to any suggestions on improving any other aspect of the code below. The app is supposed to open a folder browser dialog allowing the user to select a folder, opens each drawing file in the folder one-at-a-time, edits the file (these editing steps are not shown in the code below), and then saves and closes the drawing before going to the next drawing file in the folder.
Thanks,
Will
Using: Acad 2007, Visual Basic Express 2005
Public Sub SlideUpdate()
Dim FolderBrowserDialog1 As New FolderBrowserDialog 'declare variable for folder browser dialog object
Dim BrowseFolderResult As DialogResult 'declare varialbe for result of dialog
Dim strDirName As String = "" 'declare variable for the path of the folder that will be searched
BrowseFolderResult = FolderBrowserDialog1.ShowDialog() 'show dialog and store result as either OK or cancel
If BrowseFolderResult = DialogResult.OK Then 'check if user clicked OK
strDirName = FolderBrowserDialog1.SelectedPath 'store path of folder selected
End If
'cycle through each file in the folder that is an AutoCAD drawing
For Each strFileName As String In My.Computer.FileSystem.GetFiles(strDirName, FileIO.SearchOption.SearchAllSubDirectories, "*.dwg")
'declare variable for drawing file object
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
If (File.Exists(strFileName)) Then 'check if file exists
Dim acDoc As Document = acDocMgr.Open(strFileName, False) 'open the file in the editor
'perform operations to edit the drawing here
'close and save the current drawing
acDoc.CloseAndSave(strFileName)
Else
'give error message if drawing file does not exist
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & strFileName & " does not exist.")
End If
Next 'cycle to the next drawing file
End Sub
Dim acDoc As Document = acDocMgr.Open(strFileName, False)
inspection of "acDoc" shows that it is not the active document (rather the document in which the NETLOAD command was issued remains active). Is there a way to run the app over multiple documents so that the document returned from the "open" function automatically becomes the active document or is there a way to make it active?
By the way, I am also open to any suggestions on improving any other aspect of the code below. The app is supposed to open a folder browser dialog allowing the user to select a folder, opens each drawing file in the folder one-at-a-time, edits the file (these editing steps are not shown in the code below), and then saves and closes the drawing before going to the next drawing file in the folder.
Thanks,
Will
Using: Acad 2007, Visual Basic Express 2005
Public Sub SlideUpdate()
Dim FolderBrowserDialog1 As New FolderBrowserDialog 'declare variable for folder browser dialog object
Dim BrowseFolderResult As DialogResult 'declare varialbe for result of dialog
Dim strDirName As String = "" 'declare variable for the path of the folder that will be searched
BrowseFolderResult = FolderBrowserDialog1.ShowDialog() 'show dialog and store result as either OK or cancel
If BrowseFolderResult = DialogResult.OK Then 'check if user clicked OK
strDirName = FolderBrowserDialog1.SelectedPath 'store path of folder selected
End If
'cycle through each file in the folder that is an AutoCAD drawing
For Each strFileName As String In My.Computer.FileSystem.GetFiles(strDirName, FileIO.SearchOption.SearchAllSubDirectories, "*.dwg")
'declare variable for drawing file object
Dim acDocMgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
If (File.Exists(strFileName)) Then 'check if file exists
Dim acDoc As Document = acDocMgr.Open(strFileName, False) 'open the file in the editor
'perform operations to edit the drawing here
'close and save the current drawing
acDoc.CloseAndSave(strFileName)
Else
'give error message if drawing file does not exist
acDocMgr.MdiActiveDocument.Editor.WriteMessage("File " & strFileName & " does not exist.")
End If
Next 'cycle to the next drawing file
End Sub