Inventor 2014提供了快速装配模式,详情见此文章: http://blog.csdn.net/autodeskinventorapi/article/details/8860045
大家知道, API可以定制自己的打开文件对话框。有开发者发现,自己的对话框显示出来,但【快速模式】(不知中文版翻译成什么,英文是Open Express) 选项不见了。
其实API文档没有提及,FileDialog.InsertMode 将影响是否这个选项的出现。缺省是true,需要设置为false。另外,即便设置了,也只是说文件对话框知道是快速打开还是常规打开,代码还需要将此信息传递给Inventor的打开文件流程。请看如下VBA代码。
‘*****module******
Option Explicit
Private oEventHandler As Class1
Private Sub StartFileOpen()
Set oEventHandler = New Class1
End Sub
Private Sub EndFileOpen()
Set oEventHandler = Nothing
End Sub
‘****even class *******
Option Explicit
Private WithEvents oEvents As FileUIEvents
Private inCustomDlg As Boolean
Private Sub Class_Initialize()
Set oEvents = ThisApplication.FileUIEvents
inCustomDlg = False
End Sub
Private Sub Class_Terminate()
Set oEvents = Nothing
End Sub
Private Sub oEvents_OnFileOpenDialog(FileTypes() As String, ByVal ParentHWND As Long, FileName As String, ByVal Context As NameValueMap, HandlingCode As HandlingCodeEnum)
If inCustomDlg = False Then ' to avoid recursive callback
inCustomDlg = True
Dim oFileLocations As FileLocations
Set oFileLocations = ThisApplication.FileLocations
Dim FileOpenForm As FileDialog
Call ThisApplication.CreateFileDialog(FileOpenForm)
FileOpenForm.InsertMode = False
FileOpenForm.InitialDirectory = oFileLocations.Workspace
With FileOpenForm
' Set the initial Directory
.InitialDirectory = oFileLocations.Workspace
.DialogTitle = "My File Open"
.Filter = "Part File (*.ipt)|*.ipt" _
& "|Assembly File (*.iam)|*.iam" _
& "|Presentation File (*.ipn)|*.ipn" _
& "|Drawing File (*.idw)|*.idw" _
& "|Design element File (*.ide)|*.ide" _
.FilterIndex = 2 ' *.iam files
.OptionsEnabled = True
'.Flags = cdlOFNHideReadOnly
.ShowOpen
End With
FileName = FileOpenForm.FileName
If FileOpenForm.OptionValues.Count >= 6 Then
' assembly has 6 options
Dim index As Integer
Dim oKey As String
For index = 1 To FileOpenForm.OptionValues.Count
oKey = FileOpenForm.OptionValues.Name(index)
If oKey = "OpenExpressMode" Then
' this is a Boolean for OpenExpress/Don't open Express
If FileOpenForm.OptionValues.Item(index) Then
'if OpenExpress was specified, pass it back through the context
Context.Add "ExpressModeBehavior", "OpenExpress"
End If
End If
Next
End If
If FileName = "" Then
HandlingCode = kEventCanceled
Else
HandlingCode = kEventHandled
End If
inCustomDlg = False
End If
End Sub