Sketch Fully Contraint in Sketch mode, but Macro says Not

Sketch Fully Contraint in Sketch mode, but Macro says Not

Anonymous
Not applicable
673 Views
3 Replies
Message 1 of 4

Sketch Fully Contraint in Sketch mode, but Macro says Not

Anonymous
Not applicable

Dear Team,

I have written a small macro to identify whether my Sketch is fully Constraint or not.

below the small piece of code which i written. I want to go thru the loop as I have many Sketches in my Part

 

If oSketch.ConstraintStatus = kFullyConstrainedConstraintStatus Then
MsgBox oSketchName & ": Fully Constrained."
Else
MsgBox oSketchName & ": Not Fully Constrained."
End If

 

Problem Identified, but anyone knows the solution?

 

Problem:

If the Constraints are made using X,Y coordinates to arrest, then the macro shows "Fully Contrained"

If X,Y coordinates are not used, and though the Sketch is fully Contraint, "oSketch.ConstraintStatus" returns "Unknown Constraints"

 

 

Can anyone help me resolve this? Or Is there any other way to close this up?

 

 

Regards

Alex

 

0 Likes
674 Views
3 Replies
Replies (3)
Message 2 of 4

Curtis_W
Consultant
Consultant

Hi alexindya,

 

See this link:

https://forums.autodesk.com/t5/inventor-customization/ilogic-underconstrained-sketches/td-p/3104766

 

Also just as a tip, you can search and ask programming questions of this type on the Inventor Customization forum too:
http://forums.autodesk.com/t5/Autodesk-Inventor-Customization/bd-p/120

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 EESignature

Message 3 of 4

Anonymous
Not applicable

Hello Curtis,

Thanx for the mail. This helped to think other way.

I made few changes and below is my Code; Smiley LOL

 

---------------------------------------------------------------------------------------------------------------------------------------------

Private Sub CheckBox1_Click()

Dim oFtype As String
oFtype = ThisApplication.ActiveDocument.DocumentType
       
'If Active Document is Part/Sheet Metal
If oFtype = kPartDocumentObject Then

    Dim oSketches As PlanarSketches
    Set oSketches = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches
             
    Dim oSketch As Sketch
    Set oSketch = Nothing
    Dim oSketchCount As String
    oSketchCount = oSketches.Count
    Dim oSketchName As String
   
    'i for counter
    Dim i As Long
    i = 0
       
'Looping thru' all Sketches to check Sketch Constraint Status
    For Each oSketch In oSketches
        oSketchName = oSketch.Name
        oSketches(oSketchName).Edit

        ' To Check Movable entities in the sketch
        Dim oSketchObjects As ObjectCollection
        Set oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
        Dim oSketchEntity As SketchEntity
      
        For Each oSketchEntity In oSketch.SketchEntities
            If Not oSketchEntity.[_GeometryMoveableStatus] = kFixedGeometryMoveableStatus Then
                If Not oSketchEntity.ConstraintStatus = kFullyConstrainedConstraintStatus Then
                    oSketchObjects.Add oSketchEntity
                End If
             End If
        Next
     
        ' To Check the Broken and Under Constrained Objects
        If oSketchObjects.Count > 0 Then
            MsgBox oSketchName & ":  Is Not Fully Constrained.", vbOKOnly
            i = i + 1
        End If

        oSketches(oSketch.Name).ExitEdit
       
    Next
       
        If i = oSketchCount Then
            MsgBox "All " & oSketchCount & " Sketches needs to be Constrained"
        ElseIf i = 0 Then
            MsgBox "All " & oSketchCount & " sketches are Fully Constrained."
        ElseIf i = 1 Then
            MsgBox "Out of " & oSketchCount & " sketches " & i & " Is not Fully Constrained."
        ElseIf i > 1 Then
            MsgBox "Out of " & oSketchCount & " sketches " & i & " are not Fully Constrained."
        End If
          
Else
    MsgBox "Select Part Model to check Sketch Constraint"
End If

End Sub

---------------------------------------------------------------------------------------------------------------------------------------------

 

Thanks once again!

 

 

Regards,

Alex

Message 4 of 4

Anonymous
Not applicable

A Small Correct on my Code on showing Results using Message box. I thought I was too smart Smiley Frustrated

However the below code works perfect.

 

 

-----------------------------------------------------------------------

Public Sub SketchConstraintChk()

    Dim oSketches As PlanarSketches
    Set oSketches = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches
             
    Dim oSketch As Sketch
    Set oSketch = Nothing
    Dim sSketchCount As String
    sSketchCount = oSketches.Count
    Dim sSketchName As String
   
    'i for counter
    Dim i As Long
    i = 0
       
'Looping thru' all Sketches to check Sketch Constraint Status
    For Each oSketch In oSketches
        sSketchName = oSketch.Name
        oSketches(sSketchName).Edit

        ' To Check Movable entities in the sketch
        Dim oSketchObjects As ObjectCollection
        Set oSketchObjects = ThisApplication.TransientObjects.CreateObjectCollection
        Dim oSketchEntity As SketchEntity
      
        For Each oSketchEntity In oSketch.SketchEntities
            If Not oSketchEntity.[_GeometryMoveableStatus] = kFixedGeometryMoveableStatus Then
                If Not oSketchEntity.ConstraintStatus = kFullyConstrainedConstraintStatus Then
                    oSketchObjects.Add oSketchEntity
                End If
             End If
        Next
     
        ' To Check the Broken and Under Constrained Objects
        If oSketchObjects.Count > 0 Then
            MsgBox ThisApplication.ActiveDocument.DisplayName & ":" & vbCrLf & vbCrLf + sSketchName & ":  Is Not Fully Constrained.", vbOKOnly
            i = i + 1
        End If
       
        oSketches(oSketch.Name).ExitEdit
       
    Next
       
        If i = 0 Then
            MsgBox ThisApplication.ActiveDocument.DisplayName & ":" & vbCrLf & vbCrLf + "Great... " & vbCrLf + " All " & oSketches.Count & " Sketches are Fully Constrained."
        ElseIf i >= 1 Then
            MsgBox ThisApplication.ActiveDocument.DisplayName & ":" & vbCrLf & vbCrLf + "Out of " & oSketches.Count & " Sketches " & i & " are not Fully Constrained."
        End If
          
    ThisApplication.ActiveView.GoHome
End Sub

 

----------------------------------------------------------------------------

0 Likes