Gday Guys
I have been suffering two issues on my final implentation of a program and would really love some input.
1. Where do you define a class so that all documents can access it
2. Using the DocumentCollection.open class the file is opened but not made active.
Let me elaborate, I have a class that will manage and remember a lot of items, files & directorys. The reason for this is because there is large time saving issues. However the way I am defining it now, a new class is created when the command is run for the first time for each document, I would like all documents to access the identical class, So that in the entire session on acad there is only 1 class ever.
All runs fine on the first document till the end where I open a file. It opens file but it is not made the active document, which is easily sorted. However upon the last document been opened and made active it causes issues when the command is then run in this new document, As in it freezes autocad2012 & VS2010.
Thanks alot for your help!
Namespace OpenFiles_AutoCad
' This class is instantiated by AutoCAD for each document when
' a command is called by the user the first time in the context
' of a given document. In other words, non static data in this class
' is implicitly per-document!
Public Class MyCommands
Dim NuffFiler As OpenFileForm '<--------------- this is the class I wont one instance of per autocad
' CommandFlags.Modal
<CommandMethod("Nuff")> _
Public Sub NuffCommand() ' This method can have any name
Dim AcDocCol As DocumentCollection = Application.DocumentManager
'Get data from registry or last opened project info & get data from current document if document is a related file.
Dim RegData() As String = GetRegHistory()
Dim FileData() As String = GetCurrentAutocadFileData()
'If open document is revalent make it the active information
If FileData IsNot Nothing Then
FileData.CopyTo(RegData, 0)
End If
'Check if class has been created, If not create, Eles reset settings
If NuffFiler Is Nothing Then
NuffFiler = New OpenFileForm(RegData)
Else
NuffFiler.Reset(RegData)
End If
Try
'Get files to open
Application.ShowModalDialog(NuffFiler)
If NuffFiler.HasFilesToOpen Then
'Because documents are not be made active remember last file
Dim LastDoc As Document = Nothing
'Open all files in list
For Each FileName As String In NuffFiler.FilesToOpen
Try
LastDoc = AcDocCol.Open(FileName, False)
Catch
End Try
Next
'Check if files have been open is so make it active
'If LastDoc IsNot Nothing Then
' Try
' AcDocCol.MdiActiveDocument = LastDoc
' Catch
' End Try
'End If
'To Do get information & put into history
End If
Catch ex As Autodesk.AutoCAD.Runtime.Exception
End Try
End Sub