×
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

Reset components to absolute?

Reset components to absolute?

Reset components to absolute?

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

RE: Reset components to absolute?

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

RE: Reset components to absolute?

Thanks for the feedback. I'll add that line into my code.

www.nxjournaling.com

RE: Reset components to absolute?

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

RE: Reset components to absolute?

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

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