NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
(OP)
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:
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.
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
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.





RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
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!
RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
From what I have seen in the what's new guide, NX8 will allow negative dimensions in sketches.
RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
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.
RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches
CODE
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.