My purpose is to create an part in an assembly, in which an Adaptive plane of the part is based on a circular face on another part in the assembly. So the plane will follow if the circular face moves in the assembly. WorkPlanes.AddByPlaneAndOffset method does not work in assembly; WorkPlanes.AddFixed Method works in assembly but the generated plane is not adaptive.
So I use a workaround to execute a native Inventor command ("PartPlanarPlaneWorkPlaneCmd") through API. It works and only problem is I don't want the minitoolbar dialog to pop up. Instead, I want to accept "OK" by default in background and run through it.
I tried JCamper's method (SendKeys.Sendwait...). The dialog blinks for 1 second then go. It is better, but is there any way to make it no show at all?
The following is the code, and the models attached. Open the assembly then run the code you will see what I am looking for. Thanks everyone.
Public Sub create_workplane_from_assy_by_pick_faceproxy()
Try
' Get the active document. This is an assembly.
Dim oAsmDoc As AssemblyDocument
oAsmDoc = ThisApplication.ActiveDocument
' Get a reference to the ComponentOccurrences collection.
Dim oOccs As ComponentOccurrences
oOccs = oAsmDoc.ComponentDefinition.Occurrences
' Create a part to insert. This creates the document
' invisibly so the end-user doesn't see anything happen.
Dim oNewPartDoc As PartDocument
oNewPartDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
ThisApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject), False)
' Insert this part into the assembly automatically.
'Just like the UI command "Create Component" (Create In-Place Component) under Assembly tab
Dim oOcc As ComponentOccurrence
oOcc = oOccs.AddByComponentDefinition(oNewPartDoc.ComponentDefinition,
ThisApplication.TransientGeometry.CreateMatrix)
'get into part in assembly mode to create an ADAPTIVE workplane in the part
oOcc.Edit()
Dim oSelectSet As SelectSet
oSelectSet = oAsmDoc.SelectSet
oSelectSet.Clear()
Dim oface_assy_proxy As FaceProxy
'Call the Pick method and set the filter to pick a planer face.
oface_assy_proxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick a planar face")
'kPartFacePlanarFilter
oSelectSet.Select(oface_assy_proxy)
Dim odef As Inventor.ButtonDefinition
odef = ThisApplication.CommandManager.ControlDefinitions.Item("PartPlanarPlaneWorkPlaneCmd")
Call odef.Execute2(True) 'will wait till pick finishes
'not work. you still need click OK in the UI
'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_OKCmd").Execute2()
'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_DoneCmd").Execute()
'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_ApplyCmd").Execute()
'ThisApplication.CommandManager.ControlDefinitions.Item("AppContinueCmd").Execute()
'ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_ContinueCmd").Execute
oOcc.ExitEdit(ExitTypeEnum.kExitToParent)
End Sub