×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

NX VB Journal Reference Dimensions

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.

RE: NX VB Journal Reference Dimensions

(OP)
I was thinking maybe instead of collecting the reference dimensions, that I could collect a measurement of the same geometry instead, but again I'm not sure how I would access a measurement, or collection of measurements.

RE: NX VB Journal Reference Dimensions

(OP)
For the driving dimensions I was using this:     


  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

Perhaps UF_SKET_ask_dimensions_of_sketch in conjunction with UF_SKET_ask_dim_status will get what you need.

www.nxjournaling.com

RE: NX VB Journal Reference Dimensions

(OP)
I was in the middle of writing about my disappointment in this only grabbing driving dimensions from the sketch, but.. it only grabs driving dimensions from the sketch! So I can compare the list this gets me to the list I get from the expressions to determine which dimensions are reference.  The only issue now is getting those values to refresh.  I've been banging my head against this for months now, but this is the furthest I've gotten, thanks alot!


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

Actually, this is more what I had in mind:

CODE

Option Strict Off  

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

(OP)
Cool, I ran your code with the line uncommented out that displayed what numdims was grabbing and it says the same thing as mine, so it shows that I can't use numdims as an index number when cycling through all the dimensions, your way is better for that, but it shows that I'm on the right track.  My code will cycle through each sketch and now I know how to cycle through each dimension in each sketch.  Thank you so much.

RE: NX VB Journal Reference Dimensions

(OP)
I take back the counting thing.  The number grabbed by dimnums is 100% correct and includes the reference dimensions.  I was counting the out of sketch dimensions (chamfer sizes, extrude distance).   

RE: NX VB Journal Reference Dimensions

Quote (beng021228):

shows that I'm on the right track
Run my code and select a sketch that has both reference and driving dimensions, it will report (via the listing window) whether the dimension is active or reference along with the current value. Is this not what you were looking for?

www.nxjournaling.com

RE: NX VB Journal Reference Dimensions

(OP)
Yeah, but this is part of a bigger project, you gave me what I was looking for, thank you so much.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources