Code for Number of Constraints - 2D and 3D Sketch

Code for Number of Constraints - 2D and 3D Sketch

RoyWickrama_RWEI
Advisor Advisor
557 Views
2 Replies
Message 1 of 3

Code for Number of Constraints - 2D and 3D Sketch

RoyWickrama_RWEI
Advisor
Advisor

In the code below, I am not able to finish the codes for

oCount_Constraints_Dimensions = ????
oCount_Constraints_Constraints = ???

 

I need information for the following. I appreciate receiving help. Thank.

I also wish to expand this rule for 3D sketches. I appreciate any help.

 

Dim oCommandMgr As CommandManager
    oCommandMgr = ThisApplication.CommandManager

 ' Dim and select Sketch1
        Dim oSketches As PlanarSketches = ThisApplication.ActiveEditDocument.ComponentDefinition.Sketches
If TypeOf ThisApplication.ActiveEditObject Is Sketch Then
    Dim oSketch As Sketch = ThisApplication.ActiveEditObject
    oSketch.ExitEdit
End If
    oSketches("Sketch1").Edit

    ' Get control definition for the line command. 
    Dim oControlDef As ControlDefinition 
    ' Get control definition for the line command. 
    oControlDef = oCommandMgr.ControlDefinitions.Item("SketchAutoDimensionCmd")  
	 
oCount_Constraints_Dimensions= 1 '1 is wrong. Need to fix code
oCount_Constraints_Constraints = 1	'1 is wrong. Need to fix code

oYN = MessageBox.Show("Missing dimensions: " & oCount_Constraints_Dimensions _
& vbLf & "Missing constraints: " & oCount_Constraints_Constraints, _
"Do you want to add dimensions automatically?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2)

If oYN = vbYes Then
Call oControlDef.Execute 
'Press Apply button
Dim oKCmd As ControlDefinition
oKCmd = ThisApplication.CommandManager.ControlDefinitions.Item("AppContextual_OKCmd")
Call oKCmd.Execute
Else
MessageBox.Show("Message", "Title")

'Code to add dimensions
End If

oSketches("Sketch1").ExitEdit

 

 

 

0 Likes
Accepted solutions (1)
558 Views
2 Replies
Replies (2)
Message 2 of 3

DRoam
Mentor
Mentor
Accepted solution

I don't think there's an API property for missing constraints or missing dimensions (or even for total degrees of freedom), but there is one for whether or not it's fully constrained:

 

If oSketch.ConstraintStatus <> ConstraintStatusEnum.kFullyConstrainedConstraintStatus Then
	' Sketch is not fully constrained. It could be underconstrained, over-constrained, or unknown.
End If

 

You can find the possible statuses here: ConstraintStatusEnum Enumerator.

 

Unfortunately, there's a bug where sometimes, if there is projected geometry in the sketch, it returns the "Unknown" status even if the sketch is fully constrained. So "Unknown" could mean fully constrained, or it could mean not fully constrained... it truly is unknown.

 

However, this bug is inconsistent so it may not be an issue for your datasets. So unless you really need to know the missing constraints & missing dimensions numbers, you could give it a try and see if it works for you.

 

As for 3D sketches, I don't believe there's a property for whether or not it's fully constrained. At least, I don't see one here: Sketch3D Object. I don't even think the UI has this anywhere, unfortunately. But you can vote for this here: Degrees of freedom in 3d sketch.

Message 3 of 3

RoyWickrama_RWEI
Advisor
Advisor

Thanks DRoam for your reply with details.

I will stick to use with your piece of codes.

 

I will give up exploring the rule for 3D sketches.

0 Likes