Hi Guys,
I am working on code to step thru the members of an iPart and perform an operation on each one. The part of the workflow I'm struggling with is below:
1. Make first row of iPart table the active member
2. Perform operations on that member
3. Move to next row
4. Perform operations on that member
5. Iterate till I reach the last member
I think I have the rest of it covered but I can't find any examples of stepping thru the members one by one and executing code on each one activated. Just to give you an idea of what I have to do I'm creating a flat pattern, performing an operation on it and then suppressing it for every member but the active one and then moving to the next member and repeat.
Thanks,
Randy Martens
RT Technologies
Inventor 2018.2
This is an example to add the iPart member to the assembly. And you could use the similar idea to go through all the members. Hope it helpful for you!
Public Sub AddiPartOccurrence()
' Open the factory document invisible.
Dim oFactoryDoc As PartDocument
Set oFactoryDoc = ThisApplication.Documents.Open("C:\temp\iPartFactory.ipt", False)
' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
Set oCompDef = oFactoryDoc.ComponentDefinition
' Make sure we have an iPart factory.
If oCompDef.IsiPartFactory = False Then
MsgBox "Chosen document is not a factory.", vbExclamation
Exit Sub
End If
' Set a reference to the factory.
Dim oiPartFactory As iPartFactory
Set oiPartFactory = oCompDef.iPartFactory
' Get the number of rows in the factory.
Dim iNumRows As Integer
iNumRows = oiPartFactory.TableRows.Count
' Create a new assembly document
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.Documents.Add(kAssemblyDocumentObject, , True)
Dim oOccs As ComponentOccurrences
Set oOccs = oDoc.ComponentDefinition.Occurrences
Dim oPos As Matrix
Set oPos = ThisApplication.TransientGeometry.CreateMatrix
Dim oStep As Double
oStep = 0#
Dim iRow As Long
' Add an occurrence for each member in the factory.
For iRow = 1 To iNumRows
oStep = oStep + 10
' Add a translation along X axis
oPos.SetTranslation ThisApplication.TransientGeometry.CreateVector(oStep, oStep, 0)
Dim oOcc As ComponentOccurrence
Set oOcc = oOccs.AddiPartMember("C:\temp\iPartFactory.ipt ", oPos, iRow)
Next
End Sub
Can't find what you're looking for? Ask the community or share your knowledge.