2 Replies Latest reply on Apr 16, 2018 6:44 AM by Dan Clubley

    check for errors

    Harold Black

      Is there a way to check if a sketch is in an unsolvable state after adding a constraint? I have a for loop where I create a line and then constrain it to another line. If the constraint makes the sketch unsolvable, then I need to call a function to perform some operations.

        • Re: check for errors
          Dan Clubley

          Hi Harold,

           

          The following checks the constraint status for the active sketch and prints it to the immediate window.

           

          Option Explicit

           

          Sub main()

              Dim swApp               As SldWorks.SldWorks
              Dim swModel             As SldWorks.ModelDoc2
              Dim swSketch            As SldWorks.Sketch
             
              Dim ConstraintStatus    As Integer
             
              Set swApp = Application.SldWorks
              Set swModel = swApp.ActiveDoc
              Set swSketch = swModel.GetActiveSketch2()
             
              ConstraintStatus = swSketch.GetConstrainedStatus
             
              Debug.Print "Sketch = " & swSketch.Name
              Debug.Print ""
              Debug.Print "  Sketch Constraint Status = " & ConstraintStatus
              Debug.Print ""
              Debug.Print " 1 = Unknown constraint"
              Debug.Print " 2 = Under constrained"
              Debug.Print " 3 = Fully constrained"
              Debug.Print " 4 = Over constrained"
              Debug.Print " 5 = No solution"
              Debug.Print " 6 = Invalid solution"
              Debug.Print " 7 = Auto Solve Off"
              Debug.Print ""
             
          End Sub