Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
josh.nieman
in reply to: J-Camper

The formatting botched my code snippet, but I am specifying a solutiontype of "undirected"

However, if that is changing the default, I consider that a bug.

Specifying an optional parameters on an 'addConstraint' function shouldn't change a user-set default value.  That is the very reason 'defaults' exist.  So it would default to a thing unless otherwise stated: implying that it's ok to state otherwise without changing things.

Can anyone else replicate the behavior (trying a second code snip that better shows my code)

    <Extension()>
    Public Function ConstrainIt(TheScrew As ComponentOccurrence, Optional WasherBool As Boolean = False, Optional TheWasher As ComponentOccurrence = Nothing) As Boolean
        Dim ScrewDef As PartComponentDefinition = TheScrew.Definition
        Dim WashDef As PartComponentDefinition = Nothing
        If WasherBool Then
            Debug.Print("constrain0")
            WashDef = TheWasher.Definition
        End If

        Debug.Print("constrain1")
        Dim MateOffset As String = "0"

        Dim XY As WorkPlaneProxy = Nothing
        TheScrew.CreateGeometryProxy(ScrewDef.WorkPlanes.Item(3), XY)
        Dim Z As WorkAxisProxy = Nothing
        TheScrew.CreateGeometryProxy(ScrewDef.WorkAxes.Item(3), Z)

        If ScrewType = "FHCS" Then
            'offset by some factor (or get the parameter from the part) so we're flush
            MateOffset = 1
        ElseIf ScrewType = "SHCS" OrElse
                ScrewType = "HHCS" OrElse
                ScrewType = "BHCS" OrElse
                ScrewType = "LHCS" Then
            If WasherBool Then
                Debug.Print(WasherUsed.Thickness & " washer thickness")
                MateOffset = "-" & WasherUsed.Thickness ' negative value
                Debug.Print("Mate Offset = " & MateOffset)
            End If
            HoleConst1 = AsmDef.Constraints.AddMateConstraint2(Z, ScrewHole1, "0",
                                                               InferredTypeEnum.kInferredLine,
                                                               InferredTypeEnum.kInferredLine,
                                                               MateConstraintSolutionTypeEnum.kUndirectedSolutionType)
            FaceConst2 = AsmDef.Constraints.AddFlushConstraint(XY, FastenFace1, MateOffset)
            If WasherBool AndAlso WashDef IsNot Nothing Then
                Dim washXY As WorkPlaneProxy = Nothing
                TheWasher.CreateGeometryProxy(WashDef.WorkPlanes.Item(3), washXY)
                Dim washZ As WorkAxisProxy = Nothing
                TheWasher.CreateGeometryProxy(WashDef.WorkAxes.Item(3), washZ)
                HoleConstW1 = AsmDef.Constraints.AddMateConstraint2(washZ, ScrewHole1, "0",
                                                                    InferredTypeEnum.kInferredLine,
                                                                    InferredTypeEnum.kInferredLine,
                                                                    MateConstraintSolutionTypeEnum.kUndirectedSolutionType)
                FaceConstW2 = AsmDef.Constraints.AddFlushConstraint(washXY, FastenFace1, WasherUsed.Thickness * 2.54 / 2 * -1) 'half washer thickness, inch to cm, and negative
            End If
        Else
            ' not FHCS/SHCS/HHCS/BHCS/LHCS so maybe they hit escape to cancel or something
            Return False
        End If
        Return True
    End Function