Hi @harvey_craig2RCUH. What you are trying to do can be a little complicated to do by code, because it requires a lot of custom input that must be specified without the help of the user interface tools that you are showing in your picture. You would want to start out by getting a reference to the assembly document itself, then to its collection of assembly component occurrences. Then that collection has a method just for adding a custom iPart member. I will include a code example below that shows how to get to this collection and the method you will need to use, but you will have to customize that code to meet your specific needs. That method is asking for several things. The first is the full path and file name of the iPartFactory file. The second is a Matrix object, which is used to specify not only a location in 3D coordinate space, but also orientation & rotation of the component. The matrix is like a temporary 4 x 4 grid of numerical values that represent those specifications, in a very specific organization. Next it want you to specify the full path and file name to use for saving the new custom iPartMember file to disk. There are two more inputs being requested, but they are both optional. However, they may be needed in your case. The first optional one is for telling it which existing row of the iPartFactory table it should start from, and is complicated to explain, because this can be in different forms (an Integer for row index, a String specifying column names, comparison types, and values, in groups, or an actual iPartTableRow object, to directly specify a row. Then the last optional input is for the custom inputs, in the order of the columns, in the form of an array of Strings.
ComponentOccurrences.AddCustomiPartMember
As mentioned earlier, this is not a complete working example yet, and will need to be customized by you, to include actual file names, column names, and cell values, and that sort of thing.
Sub Main
Dim oADoc As AssemblyDocument = TryCast(ThisDoc.Document, Inventor.AssemblyDocument)
If oADoc Is Nothing Then Return
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oNewCustomiPartOccurrence As ComponentOccurrence = Nothing
'this should be the full file path and file name, with file extension, of the iPart Factory file.
Dim siPartFactoryFullFileName As String = "C:\Temp\MyCustomiPartFactory.ipt"
'this is used to place and orient the new assembly occurrence of the custom iPart member
Dim oMatrix As Inventor.Matrix = ThisApplication.TransientGeometry.CreateMatrix()
'this should be the full path and file name where the new custom iPart member file will be saved
Dim sNewFullFileName As String = "C:\Temp\MyCustomiPartFactoryMembers\MyNewCustomiPartMember1.ipt"
'this is an optional input, and should be either an Integer, representing the row index of the existing iPart member row in the factory table
'...or a String which includes column header names, comparison operators, and cell values, within [brackets],
'for it to use to find the row with those matching column values
'...or an iPartTableRow object
Dim oRow = "[Height=10 in][Length=24 in]"
'this is another optional input that represents an array of Strings that specify the custom input, in the order of the columns
'this is only valid to supply when the iPartFactory is a custom one
Dim oCustomInput
Try
oNewCustomiPartOccurrence = oOccs.AddCustomiPartMember(siPartFactoryFullFileName, _
oMatrix,sNewFullFileName, oRow, oCustomInput)
Catch
MsgBox("Error adding new custom iPart member as new assembly component occurrence.", vbCritical, "iLogic")
End Try
If oADoc.RequiresUpdate Then oADoc.Update2(True)
End Sub
Wesley Crihfield

(Not an Autodesk Employee)