Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX 7.5 NXOpen Automation - Alternate Solutions In Sketches

Status
Not open for further replies.

swaldon

Computer
Sep 30, 2011
4
I'm having some trouble using the NXOpen libraries in .NET to force a constraint to flip to its alternate solution in a sketch. I'm using NX 7.5.

In code, I'm passing various dimensions to a vertical dimension constraint in a sketch. Sometimes the values are positive, and sometimes they are negative. When the sign changes, I need to do an "Alternate Solution" on the vertical constraint because NX doesn't adjust the model based upon sign.

After I have my part open, I execute the following code:
Code:
Dim TheSketch As NXOpen.Sketch = Session.Parts.Work.Sketches.FindObject("Sketch1") 'My sketch is named inside the part file.
Dim VertConstraint As NXOpen.SketchHelpedDimensionalConstraint = CType(TheSketch.FindObject("DimensionalConstraint Rise"), NXOpen.SketchHelpedDimensionalConstraint) 'This successfully returns the correct vertical dimensional constraint. The expression name tied to the constraint is "Rise"
Try
     VertConstraint.UseAlternateSolution() 'this fails
Catch ex As NXOpen.NXException
     MsgBox(ex.Message)
End Try

However, the UseAlternateSolution function fails giving an "Unable to create alternate solution" error message. When I use the alternate solution tool interactively inside NX, the constraint changes without any issue. I've also tried using the type "SketchDimensionalConstraint" instead of the "SketchHelpedDimensionalConstraint", but got the same result.

Does anyone know how to switch a constraint to its alternate solution using the NXOpen API?

Thanks.
 
Replies continue below

Recommended for you

As an alternate method to solve this you might create a datum with an offset equal to the expression that could be positive or negative, and then constrain the sketch element to the datum. Datums are the only object in NX that I know of that will accept a negative value. Of course I am stuck at NX5 still.
 
Thanks for your response Edgray. This may be a solution to the problem if we can't get the Alternate Solution to work in code. I've tried your idea, and it does what I'd like it to do.

We're updating various dimensions in our model from a database, and would like to be able to flip alternate solutions in code as the need arises however. Our models also get adjusted interactively by a user after they're automatically generated, so we'd prefer to use dimensional constraints so that it's intuitive to change the numbers (by double clicking the dimension, rather than double clicking a datum plane, or changing the values through the expression editor).

Ideally, I'd like to be able to get the NXOpen code to switch to the alternate solution, but if that won't work out, I may take this approach. Has anyone succeeded in using NXOpen for using alternate solutions on dimensional constraints?

Thanks!
 
Do you plan on moving to NX8 any time soon?
From what I have seen in the what's new guide, NX8 will allow negative dimensions in sketches.
 
Alas, our company likes to drag its feet with upgrades for various reasons...we're just now about to move from NX5 to NX7.5. We have some other software that just now is becoming compatible with NX7.5, so it will probably be quite a while before we get to NX8.

If NX8 does truly allow for negative dimensions in sketches, that may be a nice leverage point to push for the upgrade. Thanks for the information.
 
I finally have solved my problem. Thank you to all who provided workarounds and other suggestions. Apparently, before making any changes to a constraint in a sketch, you have to activate the sketch even though you're working with the correct objects. I do wish the NXOpen API was documented a little bit better, but below is code that successfully produces the alternate solution in code. Hopefully someone else will find this useful some day.

Code:
Dim TheSketch As NXOpen.Sketch = Session.Parts.Work.Sketches.FindObject("Sketch1") 'My sketch is named inside the part file.
TheSketch.Activate(NXOpen.Sketch.ViewReorient.False) 'ADDED LINE. The sketch must be active before a constraint can be changed.
Dim VertConstraint As NXOpen.SketchHelpedDimensionalConstraint = CType(TheSketch.FindObject("DimensionalConstraint Rise"), NXOpen.SketchHelpedDimensionalConstraint) 'This successfully returns the correct vertical dimensional constraint. The expression name tied to the constraint is "Rise"
Try
     VertConstraint.UseAlternateSolution() 'this now works without error because of TheSketch.Activate()
Catch ex As NXOpen.NXException
     MsgBox(ex.Message)
End Try

Thanks again everyone.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor