By responding to FileUIEvents.OnFileInsertNewDialog the client can replace the 'Create In-Place Component' dialog with their own. This notification is sent to the client immediately after the command is executed but before the standard dialog is displayed to the end-user. By supplying at least the Filename argument and setting the HandlingCode to kEventHandled, Inventor will bypass displaying the standard dialog and use the information provided to create a new in-place component within the assembly. The rest of the command behavior remains the same. That is, if this isn't the first component being placed in the assembly, the end-user must select a location in the assembly to position the new component.
private WithEvents oFileUIE As FileUIEvents
'start file UI events
Sub startFileUIEvent()
_InvApplication = _
Runtime.InteropServices.Marshal. _
GetActiveObject("Inventor.Application")
oFileUIE = _InvApplication.FileUIEvents
End Sub
'end file UI events
Sub endFileUIEvent()
oFileDlgEvents = Nothing
End Sub
'OnFileInserNewDialog
Private Sub oFileUIE_OnFileInsertNewDialog(
ByVal TemplateDir As String,
ByRef FileTypes() As String,
ByVal DocumentObject As Inventor._Document,
ByVal ParentHWND As Integer,
ByRef TemplateFileName As String,
ByRef FileName As String,
ByRef RelativeFileName As String,
ByRef LibraryName As String,
ByRef CustomLogicalName() As Byte,
ByVal Context As Inventor.NameValueMap,
ByRef HandlingCode As Inventor.HandlingCodeEnum)
Handles oFileUIE.OnFileInsertNewDialog
TemplateDir = "C:\Users\Public\Documents\Autodesk\Inventor 2013\Templates\"
TemplateFileName = "C:\Users\Public\Documents\Autodesk\Inventor 2013\Templates\standard.ipt"
FileName = "c:\newpart.ipt"
HandlingCode = HandlingCodeEnum.kEventHandled
End Sub
But, when this is done, the dialog box that appears on selecting the "Create Component" command of the UI is by passed and so, the user is not given the following choices:
1) Constrain sketch plane to selected face or plane, which is specified on the check box which is normally displayed on the dialog box that appears on selecting the "Create Component" command of UI can no longer be specified.
2) the choice of selecting a face from existing occurrences that help in defining the xy,xz and yz planes of the new occurrence that is going to be created. A new part is created with the filename specified in the event, but, the x, y and z axis are the assembly's x, y and z axis and the user is not given a choice of where to create the part.
The workarounds are:
way 1. Create your own command which will execute the following code.
Sub CreateComponent()
' assume inventor application is available
_InvApplication.CommandManager.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, "c:\newpart.ipt")
Dim oCtrlDef As ButtonDefinition
oCtrlDef = _InvApplication.CommandManager.ControlDefinitions.Item("AssemblyCreateComponentCmd")
oCtrlDef.Execute
End Sub
_InvApplication.CommandManager.PostPrivateEvent (PrivateEventTypeEnum.kFileNameEvent, "c:\newpart.ipt")