×
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 7.5 NXOpen Automation - Alternate Solutions In Sketches

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:

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.

RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches

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.

RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches

(OP)
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!

RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches

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.

RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches

(OP)
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.  

RE: NX 7.5 NXOpen Automation - Alternate Solutions In Sketches

(OP)
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.  

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