12-24-2021
01:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
12-24-2021
01:47 AM
Hello
Don't know if I understand, but just try ![]()
I used a separate integer to number the occurrences. Otherwise there are numbers missing if skipped a modelstate. I also used the original modelstate name, not create it. Created name could be a point of failure.
If ThisDoc.Document.DocumentType = kAssemblyDocumentObject
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oADoc.ComponentDefinition
'Dim oPDoc As PartDocument = ThisApplication.Documents.ItemByName("C:\Work\Inventor\TEMP\assembly test\part test.ipt")
Dim oPDoc As PartDocument
Dim oDoc As Document
For Each oDoc In ThisApplication.Documents
If oDoc.FullFileName = "C:\Work\Inventor\TEMP\assembly test\part test.ipt" Then
opdoc = DirectCast(oDoc, Inventor.PartDocument)
Exit For
End If
Next
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim sActiveModelState As String= oPDef.ModelStates.ActiveModelState.Name
Dim ModelStateComponent(0 To 4)
Dim addCompB = True
Dim j As Integer = 1
If oPDef.ModelStates.Count > 1
For i = 1 To oPDef.ModelStates.Count
If oPDef.ModelStates.Item(i).Name = sActiveModelState Then
' Do Nothing because the in-process part doesn't need to be added to the assembly
Else
'ModelStateComponent(i-1) = Components.AddWithModelState("Part:" & i, "part test.ipt", "Section " & i, , True)
ModelStateComponent(i - 1) = Components.AddWithModelState("Part:" & j, oPDoc.FullFileName, oPDef.ModelStates.Item(i).Name, , True)
j+=1
End If
Next
Else
Dim componentA = Components.Add("Part:1", "part test.ipt", , True)
End If
Else
MessageBox.Show("This rule should only be run in an assembly document.")
End If
R. Krieg
RKW Solutions
www.rkw-solutions.com