Submitted by Gopal Parthasarathy on Sat, 03/08/2014 - 04:25
Forums:
Actually I have Part modeled used diffrent sketches,
I need Nx journal to run and check any sketch in the part has Fix constraints, and msg the sketch number.
Example: I have modeled the fork of the knuckle joint with 10 sketches. So the Model tree has 10 sketches.
In that i want to check any of the sketch has fix constrain or not.
If not alert with message or if it's it has fix constrain to alert the sketch name or ID or list of the sketches has Fix constrain
Regards,
Gopal Parthasarathy
re: fixed constraints
If you have a checkmate license, you may be better served running this type of test through checkmate. However, it can also be done with a journal. Below is some sample code.
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim fixedFound As Boolean = False
For Each ts As Sketch In workPart.Sketches
ts.Activate(Sketch.ViewReorient.False)
Try
Dim fixedConstraints() As SketchConstraint
fixedConstraints = ts.GetAllConstraintsOfType(Sketch.ConstraintClass.Geometric, Sketch.ConstraintType.Fixed)
If fixedConstraints.Length > 0 Then
fixedFound = True
lw.WriteLine(ts.Name)
lw.WriteLine(" contains " & fixedConstraints.Length.ToString & " fixed constraint(s)")
lw.WriteLine("")
End If
Catch ex As NXException
Finally
ts.Deactivate(Sketch.ViewReorient.False, Sketch.UpdateLevel.SketchOnly)
End Try
Next
If Not fixedFound Then
lw.WriteLine("no fixed constraints found in any sketches in work part")
End If
End Sub
End Module
Regard Sketch Constraints.
In the above Program, If I want to delete that particular constrain.
can I use the below code for that.
'******************************************************
'Dim objects1(6) As NXObject
'Dim sketchGeometricConstraint8 As SketchGeometricConstraint = CType(theSession.ActiveSketch.FindObject("Fixed "), SketchGeometricConstraint)
'objects1(6) = sketchGeometricConstraint8
'Dim errorList1 As ErrorList
'errorList1 = theSession.ActiveSketch.DeleteObjects(objects1)
'******************************************************
Iam not able to do delete constrain.
Could you help me on this code.
Regards,
Gopal Parthasarathy
Gopal Parthasarathy
CERT/FEA Engineer
B/E Aerospace
re: delete fixed sketch constraint
The code below will find the constraints and delete them.
Option Strict Off
Imports System
Imports NXOpen
Module Module1
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim fixedFound As Boolean = False
For Each ts As Sketch In workPart.Sketches
ts.Activate(Sketch.ViewReorient.False)
Try
Dim fixedConstraints() As SketchConstraint
fixedConstraints = ts.GetAllConstraintsOfType(Sketch.ConstraintClass.Geometric, Sketch.ConstraintType.Fixed)
If fixedConstraints.Length > 0 Then
fixedFound = True
lw.WriteLine(ts.Name)
lw.WriteLine(" contains " & fixedConstraints.Length.ToString & " fixed constraint(s)")
lw.WriteLine(" attempting to delete the fixed constraint(s)")
Dim errorList1 As ErrorList
errorList1 = theSession.ActiveSketch.DeleteObjects(fixedConstraints)
lw.WriteLine(" " & errorList1.Length.ToString & " errors encountered")
lw.WriteLine("")
errorList1.Dispose()
End If
Catch ex As NXException
Finally
ts.Deactivate(Sketch.ViewReorient.False, Sketch.UpdateLevel.Model)
End Try
Next
If Not fixedFound Then
lw.WriteLine("no fixed constraints found in any sketches in work part")
End If
End Sub
End Module