×
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

Assembly Constraints using NX Open
2

Assembly Constraints using NX Open

Assembly Constraints using NX Open

(OP)
I am new to NX open programming.
I have written a program in VB.NET to assemble components using
assembly constraints.
However when i try to run the program , even though all the assembly
constraints gets created successfully and their constraint solver
status as "Solved", Still the parts are distanced apart and they are
not mating.
Any Idea on what i am missing in my code?
 
I have developed the code mainly by recording journal in NX6.0

RE: Assembly Constraints using NX Open

I haven't done much work automating constraints, but I'd be willing to take a look if you post your code. If you have a small simplified assembly that you are testing with you should provide that as well, or at least instructions on how to recreate it.  

RE: Assembly Constraints using NX Open

(OP)
The code is below.

Begin of Assembly Creation

Public Sub SCreateAssemlyConstraints(ByVal workPart As Part)
        Dim objComponentPositioner As Positioning.ComponentPositioner
        Dim objarrangement As Arrangement
        Dim objNetwork As Positioning.Network

        _objComponentPositioner = workPart.ComponentAssembly.Positioner
        _objComponentPositioner.ClearNetwork()

        objarrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), Arrangement)
        _objComponentPositioner.PrimaryArrangement = objarrangement
        _objComponentPositioner.BeginAssemblyConstraints()

        objNetwork = _objComponentPositioner.EstablishNetwork()

        _objComponentNetwork = CType(objNetwork, Positioning.ComponentNetwork)
        _objComponentNetwork.MoveObjectsState = True
        Dim nullAssemblies_Component As Assemblies.Component = Nothing
        _objComponentNetwork.DisplayComponent = nullAssemblies_Component
        _objComponentNetwork.MoveObjectsState = True
        _objComponentNetwork.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing

    End Sub


Creating Constraints
Public Sub CreateConstraint(ByVal sTypeofConstraint As String, ByVal objComp1ToMate As NXObject, ByVal objComp2ToMate As NXObject, _
        ByVal objComponent1 As NXObject, ByVal objComponent2 As NXObject)
        Dim objConstraint As Positioning.Constraint
        'Dim objComp1 As Object
        'Dim objComp2 As Object
        Dim objComponentConstraint As Positioning.ComponentConstraint
        Dim objConstraintReference1 As Positioning.ConstraintReference
        Dim objConstraintReference2 As Positioning.ConstraintReference

        objConstraint = _objComponentPositioner.CreateConstraint()
        objComponentConstraint = CType(objConstraint, Positioning.ComponentConstraint)
        
        _objComponentNetwork.AddConstraint(objConstraint)
        If sTypeofConstraint = "Touch&Align-Axis" Then
            'objComp1 = CType(objComponent1, DatumAxis)
            'objComp2 = CType(objComponent1, DatumAxis)
            objComponentConstraint.ConstraintAlignment = Positioning.Constraint.Alignment.CoAlign
            objComponentConstraint.ConstraintType = Positioning.Constraint.Type.Touch
            objConstraintReference1 = objComponentConstraint.CreateConstraintReference(objComp1ToMate, objComponent1, False, False, False)
            objConstraintReference2 = objComponentConstraint.CreateConstraintReference(objComp2ToMate, objComponent2, False, False, False)
            objConstraintReference1.SetFixHint(True)
            objConstraintReference1.SetFixHintForUpdate(True)
            objConstraintReference2.SetFixHint(True)
            objConstraintReference2.SetFixHintForUpdate(True)

        ElseIf sTypeofConstraint = "Touch&Align-Face" Then
            'objComp1 = CType(objComponent1, Face)
            'objComp2 = CType(objComponent1, Face)
            objComponentConstraint.ConstraintAlignment = Positioning.Constraint.Alignment.InferAlign 'Positioning.Constraint.Alignment.InferAlign
            objComponentConstraint.ConstraintType = Positioning.Constraint.Type.Touch
            objConstraintReference1 = objComponentConstraint.CreateConstraintReference(objComp1ToMate, objComponent1, False, False, False)
            objConstraintReference2 = objComponentConstraint.CreateConstraintReference(objComp2ToMate, objComponent2, False, False, False)
            objConstraintReference1.SetFixHint(True)
            objConstraintReference1.SetFixHintForUpdate(True)
            objConstraintReference2.SetFixHint(True)
            objConstraintReference2.SetFixHintForUpdate(True)
            objComponentConstraint.SetAlignmentHint(Positioning.Constraint.Alignment.ContraAlign)

        ElseIf sTypeofConstraint = "Parallel" Then
            'objComp1 = CType(objComponent1, Face)
            'objComp2 = CType(objComponent1, Face)
            objComponentConstraint.ConstraintType = Positioning.Constraint.Type.Parallel
            objConstraintReference1 = objComponentConstraint.CreateConstraintReference(objComp1ToMate, objComponent1, False, False, False)
            objConstraintReference2 = objComponentConstraint.CreateConstraintReference(objComp2ToMate, objComponent2, False, False, False)
            objConstraintReference1.SetFixHint(True)
            objConstraintReference1.SetFixHintForUpdate(True)
            objConstraintReference2.SetFixHint(True)
            objConstraintReference2.SetFixHintForUpdate(True)
        End If
        objConstraint.ReverseDirection()

        'objComponentConstraint.FlipAlignment()
        _objComponentNetwork.Solve()

        _objComponentNetwork.ApplyToModel()
        objConstraint = Nothing
        objComponentConstraint = Nothing
        objConstraintReference1 = Nothing
        objConstraintReference2 = Nothing

    End Sub


End Assembly Constraints
Public Sub SEndAssemblyConstraints()
        _objComponentNetwork.ResetDisplay()
        _objComponentNetwork.ApplyToModel()
        _objComponentPositioner.ClearNetwork()
        Dim nErrs1 As Integer
        nErrs1 = FnGetNxSession().UpdateManager.AddToDeleteList(_objComponentNetwork)
        _objComponentPositioner.DeleteNonPersistentConstraints()
        Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing
        _objComponentPositioner.PrimaryArrangement = nullAssemblies_Arrangement
        _objComponentPositioner.EndAssemblyConstraints()
        
    End Sub

 

RE: Assembly Constraints using NX Open

(OP)
I have also noticed that even though the solver status is solved for all the assembly constraints , yet when i click redefine in the dialog that opens , it only shows beside geometry in brackets (1) instead of 2
Although the connected features are getting highlighted in the created assembly.

Redefine Dialog
http://files.engineering.com/getfile.aspx?folder=135e5265-eb5d-403d-9d65-8de9abc8d8b3&file=Redefine_Dialog.jpg

Constraint Info
http://files.engineering.com/getfile.aspx?folder=6b027737-2d7b-4669-9bfb-dd6aa66dede1&file=Constraint_Information.jpg

Parallel Constraint Created
Your file's link is: http://files.engineering.com/getfile.aspx?folder=88792870-5e71-430b-b494-b6fdc44a81a3&file=Parallel_Constraint.jpg

RE: Assembly Constraints using NX Open

From the parallel_constraint.jpg that you posted of the assembly, it appears that the faces are indeed parallel (difficult to tell for sure from that angle, but looks like they are). If the faces started off as parallel before you created the constraint, the components will not move. Try deleting that constraint, rotating one of the components and running the journal again to see if the component moves. It is odd that the redefine dialog lists 1 object, but both are highlighted.

Nothing in your code really stands out to me, I would suggest adding some code to output to the listing window and echoing the values of variables/objects along the way to get a better idea of what is really happening.

www.nxjournaling.com

RE: Assembly Constraints using NX Open

(OP)
On digging further , i found in the help file a property called
NxOpen.Preferences.SessionAssemblies.InterPartPositioning

However i am unable to use the property in my NX 6.0 code.
Any idea what is the alternative in NX 6.0 NX Open Code.

The Help states "Returns or sets the option to allow interpart geometry selection in the assembly constraints dialog " for the above property.

RE: Assembly Constraints using NX Open

(OP)
"If the faces started off as parallel before you created the constraint, the components will not move" , If that is the case how do i mate the two components and how do i check whether the faces are parallel before the constraint.
My end result should be irrespective of the current positioning , the components should get mated properly with respect to the constraints.
Also i am unable to understand why does the redefine dialog show geometry selected as 1 when in the assembly it highlights both the geometries.

RE: Assembly Constraints using NX Open

Perhaps I should have worded that differently; if the faces are parallel before you create a parallel constraint, the components will not move on screen - not because there is something keeping them from moving, but simply because they don't need to to satisfy the constraint. The parts are already in position according to that one constraint. If you need the clamp arm to move down toward the clamp, you'll need to add one or more additional constraints to accomplish that.

Quote:

Also i am unable to understand why does the redefine dialog show geometry selected as 1 when in the assembly it highlights both the geometries.
This is indeed the puzzling bit. Since I don't have access to your code and parts, I recorded a journal while applying constraints - the code generated looked very similar to the parts of your code that you posted, but the redefine dialog worked correctly for me.

www.nxjournaling.com

RE: Assembly Constraints using NX Open

(OP)
that sounds good.Can you please share your recorded journal code in which the redefine dialog works correctly for you.
Also should i try using the Fix constraint on the clamp part and then constrain the other 2 parts with respect to these two parts.

RE: Assembly Constraints using NX Open

(OP)
I have also noticed a strange thing even though i am trying to use CoAlign Alignment type in my code to align the axis.When i turn on the journal recording and then run my VB.NET code , the journal recorded shows ContraAlign instead of CoAlign for the axis

[b]My code[\b]
If sTypeofConstraint = "Touch&Align-Axis" Then
            'objComp1 = CType(objComponent1, DatumAxis)
            'objComp2 = CType(objComponent1, DatumAxis)
            objComponentConstraint.ConstraintAlignment = Positioning.Constraint.Alignment.CoAlign
            objComponentConstraint.ConstraintType = Positioning.Constraint.Type.Touch
            objConstraintReference1 = objComponentConstraint.CreateConstraintReference(objComp1ToMate, objComponent1, False, False, False)
            objConstraintReference2 = objComponentConstraint.CreateConstraintReference(objComp2ToMate, objComponent2, False, False, False)
            objConstraintReference1.SetFixHint(True)
            objConstraintReference1.SetFixHintForUpdate(True)

[b]Journal Recorded Code obtained running my programme[\b]
Dim componentConstraint1 As Positioning.ComponentConstraint = CType(constraint1, Positioning.ComponentConstraint)

componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.InferAlign

componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch

Dim constraintReference1 As Positioning.ConstraintReference
constraintReference1 = componentConstraint1.CreateConstraintReference(component2, datumAxis1, False, False, False)

Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint1.CreateConstraintReference(component4, datumAxis2, False, False, False)

constraintReference1.SetFixHint(True)

componentNetwork1.Solve()
 

RE: Assembly Constraints using NX Open

Below is the journal I recorded. My test assembly was 2 simple 'blocks' as components, and I used a touch constraint on 2 of the faces. After I recorded the journal, I deleted the constraint, ran the journal and checked the redefine dialog. It correctly highlighted the 2 faces and reported (2) objects as being used.

CODE

' NX 7.5.0.32
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Assemblies->Component Position->Assembly Constraints...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim componentPositioner1 As Positioning.ComponentPositioner
componentPositioner1 = workPart.ComponentAssembly.Positioner

componentPositioner1.ClearNetwork()

Dim arrangement1 As Assemblies.Arrangement = CType(workPart.ComponentAssembly.Arrangements.FindObject("Arrangement 1"), Assemblies.Arrangement)
componentPositioner1.PrimaryArrangement = arrangement1

componentPositioner1.BeginAssemblyConstraints()

Dim allowInterpartPositioning1 As Boolean
allowInterpartPositioning1 = theSession.Preferences.Assemblies.InterpartPositioning

Dim network1 As Positioning.Network
network1 = componentPositioner1.EstablishNetwork()

Dim componentNetwork1 As Positioning.ComponentNetwork = CType(network1, Positioning.ComponentNetwork)

componentNetwork1.MoveObjectsState = True

Dim nullAssemblies_Component As Assemblies.Component = Nothing

componentNetwork1.DisplayComponent = nullAssemblies_Component

componentNetwork1.NetworkArrangementsMode = Positioning.ComponentNetwork.ArrangementsMode.Existing

theSession.SetUndoMarkName(markId1, "Assembly Constraints Dialog")

componentNetwork1.MoveObjectsState = True

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints Update")

Dim rotMatrix1 As Matrix3x3
rotMatrix1.Xx = 0.900483351968208
rotMatrix1.Xy = 0.0335721640585612
rotMatrix1.Xz = 0.433592715146975
rotMatrix1.Yx = -0.275765289860863
rotMatrix1.Yy = 0.815020565584467
rotMatrix1.Yz = 0.509602769402139
rotMatrix1.Zx = -0.336278512153327
rotMatrix1.Zy = -0.578458630737584
rotMatrix1.Zz = 0.743170488373391
Dim translation1 As Point3d = New Point3d(-15.2091219822707, -2.50274212963751, 8.08264700947146)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix1, translation1, 0.243863736713582)

Dim rotMatrix2 As Matrix3x3
rotMatrix2.Xx = 0.818062547608542
rotMatrix2.Xy = 0.574101389456565
rotMatrix2.Xz = 0.0343695042772528
rotMatrix2.Yx = -0.277416222689856
rotMatrix2.Yy = 0.341542983125992
rotMatrix2.Yz = 0.89799144208945
rotMatrix2.Zx = 0.503799471604243
rotMatrix2.Zy = -0.744147824898682
rotMatrix2.Zz = 0.438668561797908
Dim translation2 As Point3d = New Point3d(-14.4195735017611, -3.89000909896482, -0.917898482618078)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix2, translation2, 0.238183791552755)

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Create Constraint")

Dim constraint1 As Positioning.Constraint
constraint1 = componentPositioner1.CreateConstraint()

Dim componentConstraint1 As Positioning.ComponentConstraint = CType(constraint1, Positioning.ComponentConstraint)

componentConstraint1.ConstraintAlignment = Positioning.Constraint.Alignment.InferAlign

componentConstraint1.Persistent = True

componentConstraint1.ConstraintType = Positioning.Constraint.Type.Touch

Dim component1 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT test_comp2 1"), Assemblies.Component)

Dim face1 As Face = CType(component1.FindObject("PROTO#.Features|BLOCK(0)|FACE 3 {(0,4,4) BLOCK(0)}"), Face)

Dim constraintReference1 As Positioning.ConstraintReference
constraintReference1 = componentConstraint1.CreateConstraintReference(component1, face1, False, False, False)

Dim helpPoint1 As Point3d = New Point3d(20.5, 4.00578507010411, 5.78865875843652)
constraintReference1.HelpPoint = helpPoint1

Dim component2 As Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT test_comp1 1"), Assemblies.Component)

Dim face2 As Face = CType(component2.FindObject("PROTO#.Features|BLOCK(0)|FACE 6 {(10,5,5) BLOCK(0)}"), Face)

Dim constraintReference2 As Positioning.ConstraintReference
constraintReference2 = componentConstraint1.CreateConstraintReference(component2, face2, False, False, False)

Dim helpPoint2 As Point3d = New Point3d(10.0, 8.15214612309787, 6.53388392507978)
constraintReference2.HelpPoint = helpPoint2

constraintReference2.SetFixHint(True)

componentConstraint1.SetAlignmentHint(Positioning.Constraint.Alignment.ContraAlign)

componentNetwork1.Solve()

Dim rotMatrix3 As Matrix3x3
rotMatrix3.Xx = 0.84137975223596
rotMatrix3.Xy = 0.538967539341624
rotMatrix3.Xz = -0.0399262327723193
rotMatrix3.Yx = -0.236234875315951
rotMatrix3.Yy = 0.433217631810186
rotMatrix3.Yz = 0.869779033532788
rotMatrix3.Zx = 0.486079413482829
rotMatrix3.Zy = -0.722382499113046
rotMatrix3.Zz = 0.491823473172417
Dim translation3 As Point3d = New Point3d(-13.8211811519369, -4.69878410763003, -1.13712218839268)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix3, translation3, 0.240464719615703)

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Assembly Constraints")

componentNetwork1.Solve()

componentNetwork1.ResetDisplay()

componentNetwork1.ApplyToModel()

componentPositioner1.ClearNetwork()

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(componentNetwork1)

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)

componentPositioner1.DeleteNonPersistentConstraints()

Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.DoUpdate(markId2)

theSession.DeleteUndoMark(markId4, Nothing)

theSession.SetUndoMarkName(markId1, "Assembly Constraints")

Dim nullAssemblies_Arrangement As Assemblies.Arrangement = Nothing

componentPositioner1.PrimaryArrangement = nullAssemblies_Arrangement

componentPositioner1.EndAssemblyConstraints()

theSession.DeleteUndoMark(markId2, Nothing)

theSession.DeleteUndoMark(markId3, Nothing)

' ----------------------------------------------
'   Menu: Tools->Journal->Stop Recording
' ----------------------------------------------
Dim rotMatrix4 As Matrix3x3
rotMatrix4.Xx = 0.839789139499119
rotMatrix4.Xy = 0.541434295380841
rotMatrix4.Xz = -0.0400387932483081
rotMatrix4.Yx = -0.226635376243314
rotMatrix4.Yy = 0.416625025064284
rotMatrix4.Yz = 0.880374917137714
rotMatrix4.Zx = 0.493346336172044
rotMatrix4.Zy = -0.730255087127531
rotMatrix4.Zz = 0.472585336537204
Dim translation4 As Point3d = New Point3d(-13.7771427645447, -5.04073423625269, -1.06794351266175)
workPart.ModelingViews.WorkView.SetRotationTranslationScale(rotMatrix4, translation4, 0.236784597850366)


End Sub
End Module

www.nxjournaling.com

RE: Assembly Constraints using NX Open

When I open the assembly, all the constraints have green checkmarks. Yet when I try to redefine any constraint, an alert pops up that warns "The constraint contains invalid geometry references..."; it will not allow me to deselect existing geometry or select new (different) geometry. It does, however, report that 2 references are selected.

I deleted the parallel constraint and the constraints associated to the blade immediately became invalid. After I reapplied the parallel constraint, it behaved normally yet appeared the same as the 'invalid' constraint.

If these constraints were applied by your journal code, I would add some debugging output to make sure the values are valid and what you expect as the code executes.

ps I notice that you are on an early release of NX6, I would encourage you to update to the latest MR for that release (I do not think this will solve your problem, but will eliminate some possibilities). I'm on NX 7.5 and I still see problems, but not exactly the same ones you do.

www.nxjournaling.com

RE: Assembly Constraints using NX Open

(OP)
Thanks Cowski for the effort from your end.
i tried doing an update and an interpart update yesterday in my code and things are a bit better.
I will also try running my code in NX7.5 to see if the problem persists.
I will also try to add some debugging output to my code so that i can resolve the issues at my end.
I feel the solver in one of the constraints is causing the issue as it is not able to solve properly.

It is indeed going to be a long research as i donot find people putting much stuff in the open internet on automating assembly constraints.

RE: Assembly Constraints using NX Open

(OP)
After doing some research over this weekend, i was able to pinpoint the problem area. It is the way by which we are retrieving the faetures/faces to be constrained.

PFB my exaplanation:

The correct way of identifying the features to be constrained is using the Journal Identifier.

For a feature we should append "PROTO#" to the value retrieved by the feature.JournalIdentifier

For a face inside a body we should append "PROTO#.Features|Body.JournalIdentifier|Face.journalIdentifier"

and then find the object using component.FindObject(journal identifier value as string)

By doing this one will be able to create the assembly constraints perfectly :)

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