- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I want to place a exist ipt file into the active assemble document.
How can i do this by iLogic code?
Solved! Go to Solution.
I want to place a exist ipt file into the active assemble document.
How can i do this by iLogic code?
Solved! Go to Solution.
Here is the API help sample for regular part.
The sample is written in VBA. To convert to ilogic/VB.NET environment
To add an ipart use this modification of the sample. Where iRow is the member row number.
oOcc = oOccs.AddiPartMember("C:\temp\iPartFactory.ipt ", oPos, iRow)
Alternatively you can use pure ilogic snippets to add iparts. Simply place a part manually then use capture snippets and component.Add to capture the parts location and occurrence name and any constraints. You can then use the ipart change row
to work with other members.
If oCompDef.IsiPartFactory = False Then
MsgBox("Chosen document is not a factory.")
Exit Sub
End If
the ipart must be a factory? What's the meaning?
The ipartfactory is the factory file containing the excel table that the members are derived from. If your just adding an ipart you likely don't need to work directly with the factory document. Just supplying the filename and member number would be enough.
Method1:Dim asmDef As AssemblyComponentDefinition= asmDoc.ComponentDefinition
asmDef.Occurrences.Add(memberFilename, transMatrix)
Method2:
dim oPartFile as string="C:\temp\123.ipt"
Dim oPartDoc As PartDocument = g_inventorApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, oPartFile, True)
These two method all opened the ipart file in a new window. This is not what i want.
I want to place the opened ipart file in the assembly window, just like the part circled by red line, like the screeshot below.
Here is the minimum required for adding occurrence to the active assembly.
' Set a reference to the assembly component definintion. ' This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition = ThisApplication.ActiveDocument.ComponentDefinition ' Set a reference to the transient geometry object. Dim oTG As TransientGeometry = ThisApplication.TransientGeometry ' Create a matrix. A new matrix is initialized with an identity matrix. Dim oMatrix As Matrix = oTG.CreateMatrix ' Add the occurrence. 'Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add("C:\1234-M-001.ipt", oMatrix)'Add standard part Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.AddiPartMember("C:\ipart factory.ipt", oMatrix,1) 'Add ipart member
Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.Add("C:\1234-M-001.ipt", oMatrix)'Add standard part
I try to run your code, but it still can't place the ipart into the opened assembly. It only opened the ipart file in a new window.
Just like the screeshot below. Maybe the problem is the Inventor version. I use the Inventor professional 2018, maybe this version can't do this action?
Have you tried placing the ipart factory and specifying the member?
Dim oOcc As ComponentOccurrence = oAsmCompDef.Occurrences.AddiPartMember("C:\ipart factory.ipt", oMatrix,1) 'Add ipart member from factory
The 2018 help file suggest there is no change.
Cam you also try a regular part note the differences in syntax. Can you post back the code your using it is displaying strange behavior.
Public Sub AddOccurrence() ' Set a reference to the assembly component definintion. ' This assumes an assembly document is open. Dim oAsmCompDef As AssemblyComponentDefinition Set oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition ' Set a reference to the transient geometry object. Dim oTG As TransientGeometry Set oTG = ThisApplication.TransientGeometry ' Create a matrix. A new matrix is initialized with an identity matrix. Dim oMatrix As Matrix Set oMatrix = oTG.CreateMatrix ' Set the rotation of the matrix for a 45 degree rotation about the Z axis. Call oMatrix.SetToRotation(3.14159265358979 / 4, _ oTG.CreateVector(0, 0, 1), oTG.CreatePoint(0, 0, 0)) ' Set the translation portion of the matrix so the part will be positioned ' at (3,2,1). Call oMatrix.SetTranslation(oTG.CreateVector(3, 2, 1)) ' Add the occurrence. Dim oOcc As ComponentOccurrence Set oOcc = oAsmCompDef.Occurrences.Add("C:\Temp\Part1.ipt", oMatrix) End Sub
The above code is VBA version have you tried to run that also? Can you record a video of the code being run?