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 :)
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
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 Modulewww.nxjournaling.com