Submitted by steve on Wed, 10/07/2015 - 07:36
Forums:
I am having trouble counting the auto-dimensions in a sketch. This is what I currently use:
dim numUnconstrainedSketches As Integer = 0
For Each ts As Sketch In myPart.Sketches
ts.Activate(Sketch.ViewReorient.False)
Dim dofNeeded As Integer
Dim myStatus As NXOpen.Sketch.Status = ts.GetStatus(dofNeeded)
If myStatus = 3 And dofNeeded = 0 Then
'all good
Else
MsgBox(ts.Name & " is not fully and properly constrained.")
numUnconstrainedSketches = numUnconstrainedSketches + 1
End If
Next
NX apparently considers a sketch that is "fully constrained with n autodimensions" to be well constrained with 0 dof. I however, consider it underconstrained. How can I count autodimensions?
Thanks
re: sketch dimensions
The code below shows how to tell the difference between a driving dimension, a reference dimension, and an auto dimension.
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module SketchAutoDim
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
For Each objSketch As Sketch In workPart.Sketches
objSketch.Activate(Sketch.ViewReorient.False)
lw.WriteLine("sketch: " & objSketch.Name)
Dim sketchDimTags() As Tag
Dim numSketchDim As Integer
theUfSession.Sket.AskDimensionsOfSketch(objSketch.Tag, numSketchDim, sketchDimTags)
lw.WriteLine("number of dimensions: " & numSketchDim.ToString)
Dim numDriving As Integer = 0
Dim numRef As Integer = 0
Dim numAuto As Integer = 0
For Each temp As Tag In sketchDimTags
Dim expTag As Tag
Dim expString As String
Dim expValue As Double
Dim status As Integer
theUfSession.Sket.AskDimStatus(temp, expTag, expString, expValue, status)
Dim refStat As UFSket.ReferenceStatus
theUfSession.Sket.AskReferenceStatus(objSketch.Tag, temp, refStat)
'auto dimensions are active, but have no expression
'associated with them
If refStat = UFSket.ReferenceStatus.Reference Then
numRef += 1
Else
If expTag = Tag.Null Then
numAuto += 1
Else
numDriving += 1
End If
End If
Next
lw.WriteLine("number of driving dimensions: " & numDriving.ToString)
lw.WriteLine("number of reference dimensions: " & numRef.ToString)
lw.WriteLine("number of auto dimensions: " & numAuto.ToString)
lw.WriteLine("")
objSketch.Deactivate(Sketch.ViewReorient.False, Sketch.UpdateLevel.SketchOnly)
Next
lw.Close()
End Sub
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
End Function
End Module
counting auto dimensions on sketch
Nice! Thanks so much. I'll be testing and report back.