Update derived part parameters

Update derived part parameters

Anonymous
Not applicable
412 Views
1 Reply
Message 1 of 2

Update derived part parameters

Anonymous
Not applicable

Hi All,

 

I'm writing a simple script to update user parameters of a derived part. The derived part already exists, I just want to add all new 'User Parameters'. I thought I had it figured out, but the line where I set "IncludeEntity" to true has no effect. Here's the code below, and the line that doesn't do what I want is highlighted in Red.

 

I would expect it to change "IncludeEntity" to true, but instead it just leaves it as false. No error messages, the file has read/write access so I'm not sure what else it could be.

 

Any suggestions?

 

Dim oapp As Application
Dim oDoc As PartDocument
Dim oDerDoc As DerivedPartComponent

Set oapp = ThisApplication
Set oDoc = oapp.ActiveDocument

On Error GoTo subError


'UPDATE DERIVED COMPONENT WITH ALL USER PARAMETERS
Dim sDerivedComp As String
sDerivedComp = "P00031-001-000.ipt"

If MsgBox("Get User Parameters from " & sDerivedComp & "?", vbYesNo, "Update Derived Component") = vbYes Then
    For Each oDerDoc In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
        If oDerDoc.Name = sDerivedComp Then Exit For
    Next
    If oDerDoc Is Nothing Then
        If MsgBox("No derived part named " & sDerivedComp & " found. Would you like to continue?", vbOKCancel) = vbCancel Then GoTo subExit
    End If
    
    Dim DerEnt As DerivedPartEntity
    Dim X1 As Integer
    For Each DerEnt In oDerDoc.Definition.Parameters
        X1 = X1 + 1
        If DerEnt.ReferencedEntity.Type = kUserParameterObject Then
            If oDerDoc.Definition.Parameters(X1).IncludeEntity = False Then
                oDerDoc.Definition.Parameters(X1).IncludeEntity = True
            End If
        End If
    Next
End If

 

 

 

0 Likes
413 Views
1 Reply
Reply (1)
Message 2 of 2

Jef_E
Collaborator
Collaborator

Hi!

 

i adjusted my post,

 

I edited your code so it should work.

 

        Dim oapp As Application
        Dim oDoc As PartDocument
        Dim oDerDoc As DerivedPartComponent
        Dim oDerDef As DerivedPartDefinition
        oapp = ThisApplication
        oDoc = oapp.ActiveDocument

        On Error GoTo subError

        'UPDATE DERIVED COMPONENT WITH ALL USER PARAMETERS
        Dim sDerivedComp As String
        sDerivedComp = "P00031-001-000.ipt"

        If MsgBox("Get User Parameters from " & sDerivedComp & "?", vbYesNo, "Update Derived Component") = vbYes Then
            For Each oDerDoc In oDoc.ComponentDefinition.ReferenceComponents.DerivedPartComponents
                If oDerDoc.Name = sDerivedComp Then Exit For
            Next
            If oDerDoc Is Nothing Then
                If MsgBox("No derived part named " & sDerivedComp & " found. Would you like to continue?", vbOKCancel) = vbCancel Then GoTo subExit
            End If

            oDerDef = oDerDoc.Definition

            Dim DerEnt As DerivedPartEntity
            Dim X1 As Integer
            For Each DerEnt In oDerDef.Parameters
                X1 = X1 + 1
                If DerEnt.ReferencedEntity.Type = kUserParameterObject Then
                    If oDerDoc.Definition.Parameters(X1).IncludeEntity = False Then
                        oDerDoc.Definition.Parameters(X1).IncludeEntity = True
                    End If
                End If
            Next
        End If

        oDerDoc.Definition = oDerDef


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes