Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations SSS148 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset components to absolute?

Status
Not open for further replies.

KhimaniMohiki

Automotive
May 14, 2013
134
CATIA has a function whereby it displays the translation and rotation of a component from absolute also allowing you to edit its position and reset to absolute.

I cant find anything similar in NX which will allow me to quickly reset a component back to absolute in both translation and rotation.

I currently use either move component Csys to Csys or insert a new instance at absolute.

Does anyone know of a quicker way or perhaps a journal which could rest a component back to the displayed part Absolute?

Regards,

Khimani.


Khimani Mohiki
Design Engineer - Aston Martin
NX8.5
 
Replies continue below

Recommended for you

There's a link to a journal that will reset the component position in the last post of the following thread:

thread561-311299

www.nxjournaling.com
 
The above code works great, however if the component to be reset to ABS contains WAVE links or any other inperpart data and the Interpart delay is OFF the script will fail. To resolve this I have added the following code at line 67 to set interpart delay ON.

theSession.UpdateManager.InterpartDelay = True

Khimani Mohiki
Design Engineer - Aston Martin
NX8.5
 
I sometimes work with Interpart update turned off, would there be any way in the code to check the status of interpart update and return it to that condition once the rest to absolute had completed?

Khimani Mohiki
Design Engineer - Aston Martin
NX8.5
 
The following version should do it. Post back if you have any problems with it.

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 selectedComponent As NXObject
		If SelectComponent(selectedComponent) = Selection.Response.Cancel Then
			Exit Sub
		End If

        Dim myInterpartDelay As Boolean = theSession.UpdateManager.InterpartDelay

		Dim pt As Point3d
		Dim RotMat As Matrix3x3

		Dim pt2 As Vector3d
		Dim RotMat2 As Matrix3x3

		Dim SelComp As NXOpen.Assemblies.Component
		SelComp = selectedComponent

		SelComp.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

        'avoid problems if the part contains wave links or other interpart data
        theSession.UpdateManager.InterpartDelay = True

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

		'get the translation information again, now that the component has been rotated back to absolute
		SelComp.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
		'or simply use RotMat returned from GetPosition, as it will be the identity matrix
		'after the component has been rotated back to its original position
		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, pt2, RotMat2)

        'reset interpart delay to original value
        theSession.UpdateManager.InterpartDelay = myInterpartDelay

	End Sub

	Function SelectComponent(ByRef selObj As NXObject) As Selection.Response

		Dim theUI As UI = UI.GetUI
		Dim message As String = "Select Component"
		Dim title As String = "Select an object"
		Dim includeFeatures As Boolean = False
		Dim keepHighlighted As Boolean = False
		Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
		Dim cursor As Point3d
		Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
		Dim selectionMask_array(0) As Selection.MaskTriple

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

		Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(message, _
   title, scope, selAction, _
   includeFeatures, keepHighlighted, selectionMask_array, _
   selObj, cursor)
		If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
			Return Selection.Response.Ok
		Else
			Return Selection.Response.Cancel
		End If

	End Function


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

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor