- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
Before model states were introduced i used the following iLogic to push the value from a user parameter in my current assembly to all occurrences where a user parameter with the same name existed. This still works fine, except for parts with model states, for which 1. .IsModifiable returns false and 2.even if i circumvent that it still does not update the parameter. I already make sure that the parts are set to "edit all model states" as the parameters i want to change are supposed to have the same value for all model states.
I already saw solutions where parameters in specific model states were edited by referencing specific model state names or parameter names, but i need a "general" solution, which just works like "if the parameter with that name exists, i change the value". Also this is supposed to work in big assemblies, so I can't update the assembly after changing a model state parameter, as i also saw proposed somewhere.
Maybe someone has a simple solution so that my parameter-pushing works for all occurences again?
Thanks.
Public Class ChangeParameterOfSameName Public Sub Main() If ThisDoc.Document.DocumentType <> Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then MsgBox("The active document must be an assembly.") Return End If CopyUserParams() iLogicVb.UpdateWhenDone = True End Sub Private Sub CopyUserParams() Dim asmDoc As Inventor.AssemblyDocument = ThisDoc.Document For Each refDoc As Inventor.Document In asmDoc.AllReferencedDocuments If Not CheckPartValidity(refDoc) Then GoTo NextItem End If Dim refDocUserParams As UserParameters If refDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject Then Dim assyDoc As AssemblyDocument = refDoc refDocUserParams = assyDoc.ComponentDefinition.Parameters.UserParameters Else If refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Then Dim partDoc As PartDocument = refDoc refDocUserParams = partDoc.ComponentDefinition.Parameters.UserParameters End If Dim index As Integer = 0 For Each asmUserParam As UserParameter In asmDoc.ComponentDefinition.Parameters.UserParameters Dim checkParam As UserParameter = Nothing Try checkParam = refDocUserParams.Item(asmUserParam.Name) 'checkParam.Expression = asmUserParam.Expression copies the expression, below copies the constant value, no formulas checkParam.Value = asmUserParam.Value index += 1 Catch ex As Exception checkParam = Nothing End Try Next If index > 0 Then Try If (refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Or refDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject) Then refDoc.Rebuild End If Catch MessageBox.Show(refDoc.DisplayName + " konnte nicht aktualisiert werden") End Try index = 0 End If NextItem: Next End Sub Private Function CheckPartValidity(refDoc As Inventor.Document) As Boolean If Not (refDoc.DocumentType = Inventor.DocumentTypeEnum.kPartDocumentObject Or refDoc.DocumentType = Inventor.DocumentTypeEnum.kAssemblyDocumentObject) Then 'MsgBox("Part wrong doc type:" + refDoc.DisplayName ) Return False End If 'will also filter out docs with modelstates If Not refDoc.IsModifiable 'MsgBox("Part not modifiable:" + refDoc.ModelStateName ) Return False End If Return True End Function End Class
Solved! Go to Solution.