Managing changes in Model States (iLogic)
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- パーマリンクを表示
- 印刷
- 報告
Model States has brought a lot of new functionality in managing the configurations of our Inventor documents, but also added a bit of complexity in passing down parameters, managing the model state we want active etc.
When we have to do with straightforward models and cases, it's extremely simple: Add the Model States you need, make the changes in views, iProperties and Parameters you want for each Model State and you are done.
What happens though when each Model State is not static? It is very often, for example, that we have a model that some of its parameters are ever-changing according to the customer order that we have. Sometimes the variety of a parameter value cannot be cut down to specific cases but can have hundreds of different possible values. That's where it gets complicated.
Every change we make in any model state, it is stored and set in that specific model state. And if we open the Excel spreadsheet that lists all the changes for all our Model States, we can see and manage all those changes. I found myself in such a situation recently. The following ilogic snippets are a solution to the above issue.
First, I needed a way to be able to delete that parameter column from the Excel sheet that has its values for each Model State:
Sub DeleteTableColumn(AssDoc As AssemblyDocument, oPart As String, oParam As String)
Dim Occ As Inventor.ComponentOccurrence = AssDoc.ComponentDefinition.Occurrences.ItemByName(oPart)
Dim partdoc As PartDocument = Occ.Definition.FactoryDocument
Try
partdoc.ComponentDefinition.ModelStates.ModelStateTable.TableColumns.Item(oParam).Delete
Catch
End Try
End Sub
I called the code above to the following snippets according to what I needed to do each time. If you don't need or want to delete the parameter column, just delete or comment the line that calls the above code.
The snippet below will internally activate the specified Model State and change the value of the desired parameter.
Sub setParamValueInModelState(AssDoc As AssemblyDocument, oPart As String, oModelStateName As String, oParam As String, oParamValue As Integer)
''Choose the part to make the changes
Dim Occ As Inventor.ComponentOccurrence = AssDoc.ComponentDefinition.Occurrences.ItemByName(oPart)
Dim partdoc As PartDocument = Occ.Definition.FactoryDocument
''Activates the model state to change parameter values
partdoc.ComponentDefinition.ModelStates.Item(oModelStateName).Activate()
''Delete the model state column of the specified parameter
DeleteTableColumn(AssDoc, oPart, oParam)
''Give value to specified model state and parameter
partdoc.ComponentDefinition.Parameters.UserParameters.Item(oParam).Value = oParamValue / 10
AssDoc.Update2
End Sub
The snippet below will change the value of the desired parameter in the current Model State the Part is on:
Sub setParamValueInCurrentModelState(AssDoc As AssemblyDocument, oPart As String, oParam As String, oParamValue As Integer)
''Choose the part to make the changes
Dim Occ As Inventor.ComponentOccurrence = AssDoc.ComponentDefinition.Occurrences.ItemByName(oPart)
Dim partdoc As PartDocument = Occ.Definition.FactoryDocument
''Activate master model state
'If partdoc.ComponentDefinition.ModelStates.ActiveModelState.ModelStateType = ModelStateTypeEnum.kSubstituteModelStateType Then
' partdoc.ComponentDefinition.ModelStates.Item(1).Activate
'End If
''Delete the model state column of the specified parameter
'DeleteTableColumn(AssDoc, oPart, oParam)
''Give value to specified model state and parameter
partdoc.ComponentDefinition.Parameters.UserParameters.Item(oParam).Value = oParamValue / 10
End Sub
The snippet below will activate the specified Model State and change the value of the desired parameter:
Sub setParamValueInActivatedModelState(AssDoc As AssemblyDocument, oPart As String, oModelStateName As String, oParam As String, oParamValue As Integer)
''Choose the part to make the changes
Dim Occ As Inventor.ComponentOccurrence = AssDoc.ComponentDefinition.Occurrences.ItemByName(oPart)
Dim partdoc As PartDocument = Occ.Definition.FactoryDocument
''Set active model state
Occ.ActiveModelState = oModelStateName 'selects the model state
''Delete the model state column of the specified parameter
DeleteTableColumn(AssDoc, oPart, oParam)
''Give value to specified model state and parameter
partdoc.ComponentDefinition.Parameters.UserParameters.Item(oParam).Value = oParamValue / 10
End Sub
I really hope those will help you as much as they helped me!