×
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

Move assembly component using NX Journal

Move assembly component using NX Journal

Move assembly component using NX Journal

(OP)
Hi all,

I'm new to working with the NX Journal tool, and I am trying to write a code that will allow me to move a component within an assembly. I used the record function and currently have a working program. I want to allow the user to pick which component is moved, but of course that cannot be done via the record function.

How can I edit my current program to allow the user to select a part within the active assembly?

NX 7.5//VB.net

Thanks :)

RE: Move assembly component using NX Journal

The code below illustrates one way to allow the user to interactively select a component while your journal is running. I think the code will work on NX 7.5, but I no longer have that version installed to test.

CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Module componentOriginalPosition
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim sel As Selection = NXOpen.UI.GetUI.SelectionManager

Sub Main()

Dim selectedObjectsArray() As NXObject
SelectComponent(selectedObjectsArray)

Dim pt as Point3D
Dim RotMat as Matrix3x3

Dim pt2 as Vector3D
Dim RotMat2 as Matrix3x3

Dim SelComp(selectedObjectsArray.Length - 1) As NXOpen.Assemblies.Component
SelComp(0) = CType(selectedObjectsArray(0), NXOpen.Assemblies.Component)
SelComp(0).GetPosition(pt, RotMat)
'msgbox("Translation: " & pt.x & ", " & pt.y & ", " & pt.z)
'msgbox("Rotation: " & vbcrlf & _
'	RotMat.xx & ", " & RotMat.xy & ", " & RotMat.xz & vbcrlf & _
'	RotMat.yx & ", " & RotMat.yy & ", " & RotMat.yz & vbcrlf & _
'	RotMat.zx & ", " & RotMat.zy & ", " & RotMat.zz)

'no translation of component on first pass
pt2.x = 0
pt2.y = 0
pt2.z = 0

'transpose of the rotation matrix, undo any rotations on the component
RotMat2.xx = RotMat.xx
RotMat2.xy = RotMat.yx
RotMat2.xz = RotMat.zx
RotMat2.yx = RotMat.xy
RotMat2.yy = RotMat.yy
RotMat2.yz = RotMat.zy
RotMat2.zx = RotMat.xz
RotMat2.zy = RotMat.yz
RotMat2.zz = RotMat.zz

'move the component back to the original rotation
workPart.ComponentAssembly.MoveComponent(SelComp(0), pt2, RotMat2)

'get the translation information again, now that the component has been rotated back to absolute
SelComp(0).GetPosition(pt, RotMat)

'negate the translations that have been applied to the component
pt2.x = -pt.x
pt2.y = -pt.y
pt2.z = -pt.z

'set rotation matrix to identity matrix, we want no new rotations on the component
RotMat2.xx = 1
RotMat2.xy = 0
RotMat2.xz = 0
RotMat2.yx = 0
RotMat2.yy = 1
RotMat2.yz = 0
RotMat2.zx = 0
RotMat2.zy = 0
RotMat2.zz = 1

'translate component back to 0,0,0
workPart.ComponentAssembly.MoveComponent(SelComp(0), pt2, RotMat2)

End Sub

'' The following routine is from GTAC
' ----------------------------------------------
' sub to select component
' ----------------------------------------------
Sub SelectComponent(ByRef selectedObjects As NXObject())
  Dim ui As UI = NXOpen.UI.GetUI
  Dim message As String = "Select Component"
  Dim title As String = "Selection"
  Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
  Dim keepHighlighted As Boolean = False
  Dim includeFeatures As Boolean = False
  Dim response As Selection.Response
  Dim selectionAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
  Dim selectionMask_array(1) As Selection.MaskTriple

  With selectionMask_array(0)
    .Type = UFConstants.UF_component_type
    .Subtype = 0
  End With

  response = ui.SelectionManager.SelectObjects(message, title, scope, selectionAction, includeFeatures, _
    keepHighlighted, selectionMask_array, selectedObjects)

  If response = Selection.Response.Cancel Or response = Selection.Response.Back Then
    Return
  End If

End Sub

'******************
Public Function GetUnloadOption(ByVal dummy As String) As Integer
  GetUnloadOption = NXOpen.UF.UFConstants.UF_UNLOAD_IMMEDIATELY
End Function

End Module 

www.nxjournaling.com

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