- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello!
In my work, I commonly make part files with multiple model states representing different sections of the same assembly that I need to be able to pull into an assembly, but the number of sections varies depending on the assembly. The catch is that in the same part file I may or may not have in-process model states for each of those sections as well. I'm working on making a rule to automatically place the sections into an assembly, but I haven't been able to figure out how to ignore the in-process model states.
Below is what I have so far that already works as long as I don't have any in-process model states. The lines that are commented out are where I was attempting to figure out how to read the names of the model states in the component.
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 oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim ModelStateComponent(0 To 4)
If oPDef.ModelStates.Count > 1
For i = 1 To oPDef.ModelStates.Count - 1
' If oPDef.ModelStates.
' ' 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)
' 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
Let me know if I need to explain a little more, or if there are any questions.
Any help would be greatly appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thanks for the reply, but I don't think that is quite what I was looking for. If I'm understanding correctly, what you wrote up will place all of the model states from the file except the active model state.
What I'm trying to do is place certain model states based on the name I've assigned it. I want to be able to place all of the model states that are not the master model state and do not contain "In-Process" in the name of the model state.
For example, if I had the following list of model states:
- Master
- Section 1
- Section 1 In-Process
- Section 2
- Section 2 In-Process
I'd want to be able to place the model states with the names "Section 1" and "Section 2" into the assembly, but ignore the rest.
My models will sometimes have the "In-Process" model states, and sometimes won't, and the number of sections can vary from a single section up to four sections, so I want the rule to be able to check the names to determine which model states to place in the model.
Does that make a little more sense?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello
I think the code is almost correct. I've added an additional check. If the name of the model state is not "master" and also the name of the model state does not contain "In-Process", it will place the component with this model state.
Option Explicit On
If ThisDoc.Document.DocumentType = kAssemblyDocumentObject
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oDef As AssemblyComponentDefinition = oADoc.ComponentDefinition
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
If Not oPDef.ModelStates.Item(i).Name = "Master" And Not oPDef.ModelStates.Item(i).Name.Contains("In-Process") Then
'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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That's what I was looking for. I did take out the check for the active model state, as I don't want it to ignore the active model state just in case that happens to be one of the model states I am trying to add to the assembly. Thanks for your help!