Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NX VB Journal Reference Dimensions

Status
Not open for further replies.

beng021228

Mechanical
Apr 10, 2012
17
0
0
US
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.
 
Replies continue below

Recommended for you

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.
 
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.
 
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.
 
Actually, this is more what I had in mind:

Code:
[COLOR=blue]Option[/color] [COLOR=blue]Strict[/color] [COLOR=blue]Off[/color]  

[COLOR=blue]Imports[/color] System  

[COLOR=blue]Imports[/color] NXOpen  
[COLOR=blue]Imports[/color] NXOpen.UI  
[COLOR=blue]Imports[/color] NXOpen.Utilities  
[COLOR=blue]Imports[/color] NXOpen.UF  

[COLOR=blue]Module[/color] select_a_sketch_module  

    [COLOR=blue]Dim[/color] s [COLOR=blue]As[/color] Session [COLOR=blue]=[/color] Session.GetSession()  
    [COLOR=blue]Dim[/color] ufs [COLOR=blue]As[/color] UFSession [COLOR=blue]=[/color] UFSession.GetUFSession()  

    [COLOR=blue]Sub[/color] Main()  
        [COLOR=blue]Dim[/color] sketch [COLOR=blue]As[/color] Tag  
        [COLOR=blue]Dim[/color] sketchDims() [COLOR=blue]As[/color] Tag  
        [COLOR=blue]Dim[/color] numDims [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  
        [COLOR=blue]Dim[/color] lw [COLOR=blue]As[/color] ListingWindow [COLOR=blue]=[/color] s.ListingWindow  

        lw.Open()  

        [COLOR=blue]While[/color] select_a_sketch(sketch) [COLOR=blue]=[/color] Selection.Response.Ok  

 [COLOR=green]'MsgBox("sketch Tag:" & sketch.ToString())[/color]
            ufs.Disp.SetHighlight(sketch, 0)  
            ufs.Sket.AskDimensionsOfSketch(sketch, numDims, sketchDims)  
 [COLOR=green]'MsgBox("number of dimensions: " & numDims)[/color]
            [COLOR=blue]Dim[/color] expTag [COLOR=blue]As[/color] Tag  
            [COLOR=blue]Dim[/color] expString [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
            [COLOR=blue]Dim[/color] expValue [COLOR=blue]As[/color] [COLOR=blue]Double[/color]  
            [COLOR=blue]Dim[/color] dimStatus [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  
            [COLOR=blue]Dim[/color] refDim [COLOR=blue]As[/color] Annotations.Dimension  
            [COLOR=blue]Dim[/color] mainText() [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
            [COLOR=blue]Dim[/color] dualText() [COLOR=blue]As[/color] [COLOR=blue]String[/color]  

            [COLOR=blue]For[/color] [COLOR=blue]Each[/color] dimTag [COLOR=blue]As[/color] Tag [COLOR=blue]In[/color] sketchDims  
                ufs.Sket.AskDimStatus(dimTag, expTag, expString, expValue, dimStatus)  
[COLOR=blue]If[/color] dimStatus [COLOR=blue]=[/color] 1 [COLOR=blue]Then[/color]  [COLOR=green]'reference dimension[/color]
                    refDim [COLOR=blue]=[/color] Utilities.NXObjectManager.Get(dimTag)  
                    refDim.GetDimensionText(mainText, dualText)  
                    lw.WriteLine("Reference dimension: " [COLOR=blue]&[/color] mainText(0))  
                [COLOR=blue]Else[/color]  
                    lw.WriteLine("Active dimension: " [COLOR=blue]&[/color] expString)  
                End [COLOR=blue]If[/color]  
            [COLOR=blue]Next[/color]  
        End [COLOR=blue]While[/color]  

    End [COLOR=blue]Sub[/color]  

    [COLOR=blue]Function[/color] select_a_sketch(ByRef sketch [COLOR=blue]As[/color] NXOpen.Tag) [COLOR=blue]As[/color] Selection.Response  

        [COLOR=blue]Dim[/color] message [COLOR=blue]As[/color] [COLOR=blue]String[/color]  
        [COLOR=blue]Dim[/color] title [COLOR=blue]As[/color] [COLOR=blue]String[/color] [COLOR=blue]=[/color] "Select a sketch"  
        [COLOR=blue]Dim[/color] scope [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY  
        [COLOR=blue]Dim[/color] response [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  
        [COLOR=blue]Dim[/color] obj [COLOR=blue]As[/color] NXOpen.Tag  
        [COLOR=blue]Dim[/color] view [COLOR=blue]As[/color] NXOpen.Tag  
        [COLOR=blue]Dim[/color] cursor(2) [COLOR=blue]As[/color] [COLOR=blue]Double[/color]  
        [COLOR=blue]Dim[/color] mask_sketch [COLOR=blue]As[/color] UFUi.SelInitFnT [COLOR=blue]=[/color] [COLOR=blue]AddressOf[/color] mask_for_sketchs  

        ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)  

        [COLOR=blue]Try[/color]  
            ufs.Ui.SelectWithSingleDialog(message, title, scope, mask_sketch, _  
                         Nothing, response, sketch, cursor, view)  
        [COLOR=blue]Finally[/color]  
            ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)  
        End [COLOR=blue]Try[/color]  

        [COLOR=blue]If[/color] response <> UFConstants.UF_UI_OBJECT_SELECTED [COLOR=blue]And[/color] _  
           response <> UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME [COLOR=blue]Then[/color]  
            [COLOR=blue]Return[/color] Selection.Response.Cancel  
        [COLOR=blue]Else[/color]  
            [COLOR=blue]Return[/color] Selection.Response.Ok  
        End [COLOR=blue]If[/color]  

    End [COLOR=blue]Function[/color]  

    [COLOR=blue]Function[/color] mask_for_sketchs(ByVal select_ [COLOR=blue]As[/color] IntPtr, _  
                           [COLOR=blue]ByVal[/color] userdata [COLOR=blue]As[/color] IntPtr) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

        [COLOR=blue]Dim[/color] num_triples [COLOR=blue]As[/color] [COLOR=blue]Integer[/color] [COLOR=blue]=[/color] 1  
        [COLOR=blue]Dim[/color] mask_triples(0) [COLOR=blue]As[/color] UFUi.Mask  
        mask_triples(0).object_type [COLOR=blue]=[/color] UFConstants.UF_sketch_type  


        ufs.Ui.SetSelMask(select_, _  
                           UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _  
                           num_triples, mask_triples)  
        [COLOR=blue]Return[/color] UFConstants.UF_UI_SEL_SUCCESS  

    End [COLOR=blue]Function[/color]  

    [COLOR=blue]Public[/color] [COLOR=blue]Function[/color] GetUnloadOption(ByVal dummy [COLOR=blue]As[/color] [COLOR=blue]String[/color]) [COLOR=blue]As[/color] [COLOR=blue]Integer[/color]  

        GetUnloadOption [COLOR=blue]=[/color] UFConstants.UF_UNLOAD_IMMEDIATELY  

    End [COLOR=blue]Function[/color]  

End [COLOR=blue]Module[/color]

The sketch selection code was taken from a GTAC example, the rest of the code inside the while loop is mine.


 
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.
 
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).
 
Status
Not open for further replies.
Back
Top