Cancel
Showing results for 
Search instead for 
Did you mean: 

Dimension Status

Experimenter
Experimenter

Hi all,

 

I'm making a NXOPEN app and I need to know every dimension status in modeling sketch. It could be overconstrained, conflincting, reference or nothing. And I'm really stuck here.

 

It seems easy but I'm not able to find which property or function I need to check/ask to find it. After scanning the whole NET Ref documentation without succes I decided that a solution could be to check the color of the dimension. My surprise's been that the color of dimension doesn't match the "Displayed Color". In fact is the Displayed Color the one is giving me the status of the dimension, but also, I don't find where can I get this info in the API. 

 

Does any of you have any clue of how can I solve this Dimension Status problem?

 

Thanks in advance!

9 REPLIES 9

Re: Dimension Status

Legend
Legend

@NXPROTO 

Go through the below code and you need to clean it up. all sketch constraints are obtained based on its type. 

using System; 
using NXOpen; 
using NXOpen.UF;
using NXOpen.Features;

static class report_all_sketches_in_work_part 
{ 
    public static void Main() 
    { 
        
        Session theSession = Session.GetSession(); 
        UFSession theUfSession = UFSession.GetUFSession(); 
        UI ui = UI.GetUI(); 
        ListingWindow lw = theSession.ListingWindow;
        int nObjType, nSubType;
        lw.Open(); 
        
        foreach (Sketch sk in theSession.Parts.Work.Sketches) 
        { 
            lw.WriteLine("\n"); 
            
            int dofNeeded = 0;
            sk.Highlight(); 

            lw.WriteLine(sk.Name + " (" + sk.ToString() + ")"); 

            Feature skFeat = sk.Feature;
            lw.WriteLine(" From Feature: " + skFeat.GetFeatureName()); 

            lw.WriteLine(" IsActive?: " + sk.IsActive); 
            sk.Activate(Sketch.ViewReorient.False);
            lw.WriteLine(" Status: " + sk.GetStatus(out dofNeeded).ToString()); 
            if( dofNeeded > 0 )
                lw.WriteLine(" DOF needed: " + dofNeeded.ToString()); 
            lw.WriteLine(" InferredConstraints?: " + sk.Preferences.CreateInferredConstraints.ToString()); 
            lw.WriteLine(" AutoDimensioning?: " + sk.Preferences.ContinuousAutoDimensioningSetting.ToString()); 
            lw.WriteLine(" IsBlanked?: " + sk.IsBlanked); 
            lw.WriteLine(" IsDraftingSketch?: " + sk.IsDraftingSketch); 
            lw.WriteLine(" Color: " + sk.Color); 
            lw.WriteLine(" Layer: " + sk.Layer); 
            lw.WriteLine(" Font: " + sk.LineFont); 
            lw.WriteLine(" Width: " + sk.LineWidth); 
            lw.WriteLine(" Objects:"); 
            
            NXObject[] objects = sk.GetAllGeometry(); 
            foreach (NXObject obj in objects)
                lw.WriteLine("  " + obj.Name); 

            lw.WriteLine(" Dimensions:"); 
            SketchConstraint[] constraints1 = sk.GetAllConstraintsOfType(Sketch.ConstraintClass.Dimension, Sketch.ConstraintType.NoCon);
            foreach (SketchConstraint skc1 in constraints1) 
            {
                SketchDimensionalConstraint skdc = (SketchDimensionalConstraint) skc1;
                theUfSession.Obj.AskTypeAndSubtype(skdc.Tag, out nObjType, out nSubType);
                double dimValue = skdc.AssociatedDimension.ComputedSize;
                SketchDimensionalConstraint.DimensionStateType dimState = skdc.DimensionState;
                lw.WriteLine("  type: " + skdc.ConstraintType.ToString() + " - " + nObjType.ToString() + "/" + nSubType.ToString() +
                             "  value: " + dimValue.ToString() + " - " + dimState.ToString()); 
            }

            lw.WriteLine(" Geometric:"); 
            SketchConstraint[] constraints2 = sk.GetAllConstraintsOfType(Sketch.ConstraintClass.Geometric, Sketch.ConstraintType.NoCon);
            foreach (SketchConstraint skc2 in constraints2) 
            {
                SketchGeometricConstraint skgc = (SketchGeometricConstraint) skc2;
                theUfSession.Obj.AskTypeAndSubtype(skgc.Tag, out nObjType, out nSubType);
                lw.WriteLine("  type: " + skgc.ConstraintType.ToString() + " - " + nObjType.ToString() + "/" + nSubType.ToString());
            }

           

            ui.NXMessageBox.Show("Information", NXMessageBox.DialogType.Information, "Sketch " + sk.Name + " is highlighted"); 

            sk.Unhighlight(); 
            sk.Deactivate(Sketch.ViewReorient.False, Sketch.UpdateLevel.Model);
        } 
        
    } 
} 

SketchDimensionalConstraint.color may return the color of its constrain. 

伊尔凡

Re: Dimension Status

Experimenter
Experimenter

Thanks @Irfan23 !!

 

But things are getting weirdier...

 

As you said I've checked SketchDimensionalConstraint.Color. Here is the output:

 

NXDimensionsColor3.PNG

 

Now I have a new color Smiley LOL.

 

So the displayed colors are red, blue and gray. Dimension.Color sais that all dimensions are black. In fact, if I check "Display Object Color" in the sketch settings they turn black (not the red ones). And now SketchDimensionalConstraint.Color sais they are... green?

 

This is the code:

 

Imports NXOpen
Imports NXOpen.UF

Module NXTest

    Dim theSession As Session
    Dim theUfSession As UFSession
    Dim ui As UI
    Dim lw As ListingWindow

    Sub Main()

        theSession = Session.GetSession()
        theUfSession = UFSession.GetUFSession()
        ui = UI.GetUI()
        lw = theSession.ListingWindow
        lw.Open()

        For Each sk As Sketch In theSession.Parts.Work.Sketches

            lw.WriteLine(vbLf)
            Dim dofNeeded As Integer = 0
            lw.WriteLine(sk.Name & " (" + sk.ToString() & ")")
            sk.Activate(Sketch.ViewReorient.[False])
            lw.WriteLine(" Status: " & sk.GetStatus(dofNeeded).ToString())
            If dofNeeded > 0 Then lw.WriteLine(" DOF needed: " & dofNeeded.ToString())
            lw.WriteLine(" Color: " & GetColorName(sk.Color))
            lw.WriteLine(vbCrLf)
            lw.WriteLine(vbCrLf)
            lw.WriteLine(" Dimensions:")

            For Each skc1 As SketchConstraint In sk.GetAllConstraintsOfType(Sketch.ConstraintClass.Dimension, Sketch.ConstraintType.NoCon)
lw.WriteLine(vbCrLf) Dim skdc As SketchDimensionalConstraint = CType(skc1, SketchDimensionalConstraint) Dim skdcDimension As Annotations.Dimension = skdc.AssociatedDimension Dim skdcExpression As Expression = skdc.AssociatedExpression Dim nObjType, nSubType As Integer theUfSession.Obj.AskTypeAndSubtype(skdc.Tag, nObjType, nSubType) Dim dimState As SketchDimensionalConstraint.DimensionStateType = skdc.DimensionState
lw.WriteLine(" name: " & skdcExpression.Name & " - " & dimState.ToString()) lw.WriteLine(" SketchDimConst color: " & vbTab & GetColorName(skdc.Color)) lw.WriteLine(" Dimension color: " & vbTab & GetColorName(skdcDimension.Color))
Next sk.Deactivate(Sketch.ViewReorient.[False], Sketch.UpdateLevel.Model) Next End Sub Private Function GetColorName(ByVal colorCode As Integer) As String Dim Color As String = "" Dim ColorVal(2) As Double theUfSession.Disp.AskColor(colorCode, UFConstants.UF_DISP_rgb_model, Color, ColorVal) Return colorCode & " (" & Color & ")" End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately End Function End Module

 

 

 

 

Re: Dimension Status

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

There is a journal here that will report driving, reference, and auto dimensions.

Re: Dimension Status

Experimenter
Experimenter

Thanks @cowski1

 

But Overconstrained (red) and Conflicting (purple), isn't there anything in the NX API that gives this information? For me it was so obvious that the API would offer this information that I made this assumption in my app design. 

 

Can you think of any indirect check like, I don't know, see if the computed size of a driving dimension and its expression value are different? I'll try anyway. Let you know if I find something.

Re: Dimension Status

Legend
Legend

@NXPROTO 

 

Then constrain color are just floating colors. They are adding upto with existing colors. when a dimension is over constrained, check what is its display color (Select dim and press CTRL+J). if it display the same color in the screen (over constrained dimesion color) then somehow we can get the color, if not then the work around would to find the preference color in the session and match with the status of the dimension. This may be a bit tricky. 

伊尔凡

Re: Dimension Status

Experimenter
Experimenter

@Irfan23 

 

Exactly, display color is "something" that is overriding the object color based on its status. If I select the dimension, go to properties > information, I get that Color and Display Color are different things.

NXDimensionsColor4.PNG

 

If I check the display settings of the dimension, the dialog is showing no color, idk why:

NXDimensionsColor5.PNG

 

 

To find the preference color and match it with the dimension color is easy. There're the properties workPart.Preferences.PartSketch.OverconstrainedColor/ConflictingColor that hold this value. This I've checked and at least is working:

OverconstrainedColor: 186 (Red)
ConflictingColor: 181 (Magenta)

 

If I had the Display Color I only would have to compare integers.

 

As @cowski1 said, to find driving/reference status is easy, but the full status of the dimension is "hidding" somewhere. I only can think of creating an algorithm to test every dimension, changing its value and check if they get stuck. But this is going to be time consuming... Smiley Sad

Re: Dimension Status

Legend
Legend

@NXPROTO 

 

Now you need to collect all dimesion constrains based on its status and through preference you can get the colour of Constraints. collect it and use for your purpose. From the colour you can get its integer value and compare it. 
This might be a work around.

 

EOD we need output. 

伊尔凡

Re: Dimension Status

Experimenter
Experimenter

@Irfan23 

 

I can't. I can get the colour of Constraints through the preferences, but I don't have anything to compare it to, cause when I check the color porperty of the dimension it will return black (or medium moss if I ask to SketchDimensionaConstraint ), no matter which status it is. When I look to the screen I see that dimensions are red, magenta, blue (medium royal) and gray (strong stone), but NXOpen-wise I cannot find any (NXOpen.Annotations.)Dimension property or (NXOpen.)SketchDimensionaConstraint property, or whatever, saying this.

 

This is the output of my code, and the code is below. Please, let me know if you have a different output.

 

NXDimensionsColor6.PNG

 

 

Imports NXOpen
Imports NXOpen.UF

Module NXTest

    Dim theSession As Session
    Dim theUfSession As UFSession
    Dim ui As UI
    Dim lw As ListingWindow

    Sub Main()

        theSession = Session.GetSession()
        theUfSession = UFSession.GetUFSession()
        ui = UI.GetUI()
        lw = theSession.ListingWindow
        lw.Open()

        lw.WriteLine(" DimensionColor: " & GetColorName(theSession.Parts.Work.Preferences.PartSketch.DimensionColor))
        lw.WriteLine(" ReferenceDimensionColor: " & GetColorName(theSession.Parts.Work.Preferences.PartSketch.ReferenceDimensionColor))
        lw.WriteLine(" OverconstrainedColor: " & GetColorName(theSession.Parts.Work.Preferences.PartSketch.OverconstrainedColor))
        lw.WriteLine(" ConflictingColor: " & GetColorName(theSession.Parts.Work.Preferences.PartSketch.ConflictingColor))

        For Each sk As Sketch In theSession.Parts.Work.Sketches

            sk.Activate(Sketch.ViewReorient.[False])

            For Each skc1 As SketchConstraint In sk.GetAllConstraintsOfType(Sketch.ConstraintClass.Dimension, Sketch.ConstraintType.NoCon)

                lw.WriteLine(vbCrLf)

                Dim skdc As SketchDimensionalConstraint = CType(skc1, SketchDimensionalConstraint)

                Dim skdcDimension As Annotations.Dimension = skdc.AssociatedDimension
                Dim skdcExpression As Expression = skdc.AssociatedExpression
                Dim dimState As SketchDimensionalConstraint.DimensionStateType = skdc.DimensionState

                lw.WriteLine(" name: " & skdcExpression.Name & " - " & dimState.ToString())
                lw.WriteLine(" SketchDimConst color: " & vbTab & GetColorName(skdc.Color))
                lw.WriteLine(" Dimension color: " & vbTab & GetColorName(skdcDimension.Color))

            Next

            sk.Deactivate(Sketch.ViewReorient.[False], Sketch.UpdateLevel.Model)

        Next

    End Sub

    Private Function GetColorName(ByVal colorCode As Integer) As String

        Dim Color As String = ""
        Dim ColorVal(2) As Double
        theUfSession.Disp.AskColor(colorCode, UFConstants.UF_DISP_rgb_model, Color, ColorVal)
        Return colorCode & " (" & Color & ")"

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        GetUnloadOption = Session.LibraryUnloadOption.Immediately
    End Function

End Module

Re: Dimension Status

Legend
Legend

Yes, You are right i believed there would be method similar to assembly constrain, where we can find what is status of it.  Now, we need to find a workaround. I have gone through NXopen documentation and cant find one. 
can you check manually is there any other way to find whether the Dim constrain is overconstained other than visual inspection. i.e attribute or LW information. 

伊尔凡