Issue
I need to open an assembly and do some processing that takes some time. I need to prevent the user from accessing the document during the process. Is there a way to do this?
One way would be to open the assembly document invisibly and then make it visible. Here is a VB.NET and VBA examples that use this approach.
Note: Inventor 2009 added an application property named ScreenUpdating. To keep graphics locked set this property to True. Make sure to set it to False after the processing is finished. (Application.ScreenUpdating=False)
VB .NET:
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
Try ‘ Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime _
.InteropServices.Marshal _
.GetActiveObject("Inventor.Application")
Catch ‘ If not active, create a new Inventor session
Dim inventorAppType As Type _
= System.Type.GetTypeFromProgID("Inventor.Application")
m_inventorApp = System.Activator.CreateInstance(inventorAppType)
‘Must be set visible explicitly
m_inventorApp.Visible = True
End Try
Catch
System.Windows.Forms.MessageBox _
.Show("Error: couldn’t create Inventor instance")
End Try
OpenInvisibleAndMakeVisible()
End Sub
Public Sub openInvisibleAndMakeVisible()
Dim oDoc As AssemblyDocument
‘Open the document in the invisible mode
oDoc = m_inventorApp.Documents _
.Open("c:\temp\test_assly.iam", False)
‘Do some proccessing here
‘Now make the document visible
oDoc.Views.Add()
End Sub
VBA:
Public Sub openInvisibleAndMakeVisible()
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.Documents _
.Open("c:\temp\test_assly.iam", False)
‘ Do some proccessing here
‘ Now make the document visible
oDoc.Views.Add
End Sub
Another way would be to put up a model dialog that pops up in front of Inventor and shows some status so that the user cannot close the document until the processing is done.

Leave a Reply