NX VB Journal Reference Dimensions
NX VB Journal Reference Dimensions
(OP)
I'm using NX6, but a solution in NX7.5 or nx8 is just as good. Is there a way to "look at" modeling sketch reference dimensions programatically? I can "see" the driving dimensions just fine, but I need to analyze the dimensions I set as reference as well. I was thinking that UFsession might get me there, but so far has gotten me nowhere. Here is the code I have in that vein:
Do
ufs.Obj.CycleObjsInPart(parttag, UFConstants.UF_dimension_type, objtag)
If objtag <> NXOpen.Tag.Null Then
ReDim Preserve thetags(j)
thetags(j) = objtag
j = j + 1
End If
Loop While objtag <> NXOpen.Tag.Null
Thanks for any tips or suggestions you have.
Do
ufs.Obj.CycleObjsInPart(parttag, UFConstants.UF_dimension_type, objtag)
If objtag <> NXOpen.Tag.Null Then
ReDim Preserve thetags(j)
thetags(j) = objtag
j = j + 1
End If
Loop While objtag <> NXOpen.Tag.Null
Thanks for any tips or suggestions you have.





RE: NX VB Journal Reference Dimensions
RE: NX VB Journal Reference Dimensions
newarray = workpart.Expressions.ToArray()
Dim expindex As Integer = newarray.Length-1
ReDim dimexpression(expindex)
Dim exparms(expindex)
Dim k As Integer
For k = 0 To expindex
dimexpression(k) = workpart.Expressions.GetVisibleExpressions.GetValue(k)
Next
Now I notice that if I convert a dimension to reference, it is still grabbed by this, but when I change the values of the driving dimensions the reference dimension that is grabbed by the code is not updated, and when viewing the expresions (tools>expressions) it is not updated. However if I manually convert the ref sketch dimension to driving and then back again it updates the value. This might get me what I need if there is a way to programatically see if a dimension is set to reference, convert it and convert it back again.
RE: NX VB Journal Reference Dimensions
www.nxjournaling.com
RE: NX VB Journal Reference Dimensions
Here's the new code for looking at the sketch dimensions:
Dim dimnums As Integer
Dim dimtags(0) As Tag
Do
ufs.Obj.CycleObjsInPart(parttag, UFConstants.UF_sketch_type, objtag)
If objtag <> NXOpen.Tag.Null Then
ReDim Preserve thetags(j)
thetags(j) = objtag
ufs.Sket.AskDimensionsOfSketch(objtag, dimnums, dimtags)
'error checking to see what we're grabbing
MsgBox(j.ToString & " " & objtag.ToString & " " & dimnums.tostring)
j = j + 1
End If
Loop While objtag <> NXOpen.Tag.Null
The msgbox kick out the number 29 in my error checking model for the number of dimensions, there are 35 in the sketch with 4 of those being reference, so if the index starts at 0 that works out right.
RE: NX VB Journal Reference Dimensions
CODE
Imports System
Imports NXOpen
Imports NXOpen.UI
Imports NXOpen.Utilities
Imports NXOpen.UF
Module select_a_sketch_module
Dim s As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Sub Main()
Dim sketch As Tag
Dim sketchDims() As Tag
Dim numDims As Integer
Dim lw As ListingWindow = s.ListingWindow
lw.Open()
While select_a_sketch(sketch) = Selection.Response.Ok
'MsgBox("sketch Tag:" & sketch.ToString())
ufs.Disp.SetHighlight(sketch, 0)
ufs.Sket.AskDimensionsOfSketch(sketch, numDims, sketchDims)
'MsgBox("number of dimensions: " & numDims)
Dim expTag As Tag
Dim expString As String
Dim expValue As Double
Dim dimStatus As Integer
Dim refDim As Annotations.Dimension
Dim mainText() As String
Dim dualText() As String
For Each dimTag As Tag In sketchDims
ufs.Sket.AskDimStatus(dimTag, expTag, expString, expValue, dimStatus)
If dimStatus = 1 Then 'reference dimension
refDim = Utilities.NXObjectManager.Get(dimTag)
refDim.GetDimensionText(mainText, dualText)
lw.WriteLine("Reference dimension: " & mainText(0))
Else
lw.WriteLine("Active dimension: " & expString)
End If
Next
End While
End Sub
Function select_a_sketch(ByRef sketch As NXOpen.Tag) As Selection.Response
Dim message As String
Dim title As String = "Select a sketch"
Dim scope As Integer = UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY
Dim response As Integer
Dim obj As NXOpen.Tag
Dim view As NXOpen.Tag
Dim cursor(2) As Double
Dim mask_sketch As UFUi.SelInitFnT = AddressOf mask_for_sketchs
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
Try
ufs.Ui.SelectWithSingleDialog(message, title, scope, mask_sketch, _
Nothing, response, sketch, cursor, view)
Finally
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
End Try
If response <> UFConstants.UF_UI_OBJECT_SELECTED And _
response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
Return Selection.Response.Cancel
Else
Return Selection.Response.Ok
End If
End Function
Function mask_for_sketchs(ByVal select_ As IntPtr, _
ByVal userdata As IntPtr) As Integer
Dim num_triples As Integer = 1
Dim mask_triples(0) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_sketch_type
ufs.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function GetUnloadOption(ByVal dummy As String) As Integer
GetUnloadOption = UFConstants.UF_UNLOAD_IMMEDIATELY
End Function
End Module
The sketch selection code was taken from a GTAC example, the rest of the code inside the while loop is mine.
www.nxjournaling.com
RE: NX VB Journal Reference Dimensions
RE: NX VB Journal Reference Dimensions
RE: NX VB Journal Reference Dimensions
www.nxjournaling.com
RE: NX VB Journal Reference Dimensions