Get Component Rotation Angles
Get Component Rotation Angles
(OP)
Hi All,
i have an assembly and i want collect component rotation angles about X, Y & Z.
i searched for this in Eng-tips forum and i got following code to get component rotation matrix.
and i want to is there any way to get component angles rather than rotation matrix.
Thanks in Advance.
i have an assembly and i want collect component rotation angles about X, Y & Z.
i searched for this in Eng-tips forum and i got following code to get component rotation matrix.
CODE -->
Dim RotMat as Matrix3x3
Dim child As Component
Dim LW As ListingWindow = theSession.ListingWindow
LW.Open()
child.GetPosition(pt, RotMat)
lw.WriteLine ( "|" & child.displayname() & "," & _
"" & pt.x & ", " & pt.y & ", " & pt.z & "," & _
"" & "" & _
RotMat.xx & ", " & RotMat.yx & ", " & RotMat.zx & "," & _
RotMat.xy & ", " & RotMat.yy & ", " & RotMat.zy & "," & _
RotMat.xz & ", " & RotMat.yz & ", " & RotMat.zz ) and i want to is there any way to get component angles rather than rotation matrix.
Thanks in Advance.





RE: Get Component Rotation Angles
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
RE: Get Component Rotation Angles
Component angle with respect to absolute co-ordinate system.
for example i have a axle assembly consist one axle and 2 wheels. now i want to get axle angles with respect to absolute co-ordinate system of axle assembly.
Thanks
RE: Get Component Rotation Angles
John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Industry Sector
Cypress, CA
Siemens PLM:
UG/NX Museum:
To an Engineer, the glass is twice as big as it needs to be.
RE: Get Component Rotation Angles
www.nxjournaling.com
RE: Get Component Rotation Angles
Thanks
RE: Get Component Rotation Angles
Thanks
RE: Get Component Rotation Angles
What is your end goal?
www.nxjournaling.com
RE: Get Component Rotation Angles
CODE
I'm still curious what you plan on using the angles for. There might be an easier way to go about it. For instance, if you want to move the component back to the original position, you might be interested in thread561-311299: How can you tell if a component has been moved.. No calculation of angles necessary.
www.nxjournaling.com
RE: Get Component Rotation Angles
actually we got a new project in this project we can't use constrains (as per customer request). Because of this we got a some problems like some components are moved by user accidentally in final design. now we want to make a log file that will record all the assembly component position and orientation so that if any one moved accidentally then we can able to recover those position from log file.
RE: Get Component Rotation Angles
For your application, you would be better off recording the position matrix. If the new matrix is different from the old, you can do a "csys to csys" type move (a csys is easily derived from the matrix) and not have to worry about calculating angles or the order you apply them. It would also avoid some potential rounding errors with the angle calculations.
www.nxjournaling.com
RE: Get Component Rotation Angles
Thanks for your valuable suggestion
RE: Get Component Rotation Angles
that is pretty cool, what you offered
RE: Get Component Rotation Angles
Glad you like it, I hope someone finds it useful.
ramakrishna90589,
Below is a link to some sample code, 2 separate journals, one prompts you to select a component and writes the position information to file (record_pos.vb); the other prompts you to select a component and moves it to the saved position (reset_pos.vb). The code is rudimentary, but I think functional enough to show you a way forward.
Create some way to record the component's original position (extract edge curves, all in body would do nicely) then run record_pos.vb and select the component. Reposition the component (any mix of rotations and translations) then run reset_pos.vb and select the same component. It should move back to its previous position. Do this on a test file, I do not guarantee the code in any way, shape, or form.
https://dl.dropboxusercontent.com/u/80688373/recor...
www.nxjournaling.com
RE: Get Component Rotation Angles
i have a small question, as i described in my previous post some time we are facing a problem in moving components in assembly using CSYS to CSys move command because some components that doesn't consists any csys at absolute. is there any way in unigraphics to show absolute csys?
Thanks
RE: Get Component Rotation Angles
Sometimes we will insert component from library and we want to move this component to specified csys using CSYS to CSYS move command at here we are facing following problem. because component doesn't consists any csys so we can't able to use CSYS to CSYS move command. see attached image, in this image part was inserted using "entire part" as a reference set still it won't show any CSYS. i Want to know is there any way in unigraphics to show absolute co-ordinate system so that we can use CSYS to CSYS Move command very easily while inserting new component in an assembly.
Thanks
Ramakrishna
RE: Get Component Rotation Angles
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
CODE
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.Assemblies Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim myComponents() As TaggedObject If SelectComponents("Select components", myComponents) = Selection.Response.Cancel Then Return End If For Each tempComp As Component In myComponents lw.WriteLine(tempComp.Name) Dim rotX As Double 'rotation about X axis Dim rotY As Double 'rotation about Y axis Dim rotZ As Double 'rotation about Z axis Dim compPt As Point3d = CompPos(tempComp) CompRot(tempComp, rotX, rotY, rotZ) lw.WriteLine(" rotation about X axis: " & rotX) lw.WriteLine(" rotation about Y axis: " & rotY) lw.WriteLine(" rotation about Z axis: " & rotZ) lw.WriteLine(" X" & compPt.X.ToString & " Y" & compPt.Y.ToString & " Z" & compPt.Z.ToString) lw.WriteLine("") Next End Sub Function SelectComponents(ByVal prompt As String, ByRef selObj() As TaggedObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select components" Dim includeFeatures As Boolean = False Dim keepHighlighted As Boolean = False Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific 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_component_subtype End With Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObjects(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selobj) If resp = Selection.Response.Ok Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Sub CompRot(ByVal someComponent As Component, ByRef RX1 As Double, ByRef RY1 As Double, ByRef RZ1 As Double) 'extract euler angles from rotation matrix: 'https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2012/07/euler-angles.pdf Dim pt As Point3d Dim RotMat As Matrix3x3 someComponent.GetPosition(pt, RotMat) Dim c1, c2, s1 As Double RX1 = Math.Atan2(RotMat.Yz, RotMat.Zz) c2 = Math.Sqrt(RotMat.Xx ^ 2 + RotMat.Xy ^ 2) RY1 = Math.Atan2(-RotMat.Xz, c2) s1 = Math.Sin(RX1) c1 = Math.Cos(RX1) RZ1 = Math.Atan2(s1 * RotMat.Zx - c1 * RotMat.Yx, c1 * RotMat.Yy - s1 * RotMat.Zy) 'convert angles from radians to degrees RX1 *= (180 / Math.PI) RY1 *= (180 / Math.PI) RZ1 *= (180 / Math.PI) End Sub Function CompPos(ByVal someComponent As Component) As Point3d Dim pt As Point3d Dim RotMat As Matrix3x3 someComponent.GetPosition(pt, RotMat) Return pt End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Modulewww.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.Assemblies Module Module1 Public s As Session = Session.GetSession() Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = s.Parts.Work Dim wpName As String = workPart.FullPath.ToString() Dim textFileName As String = Nothing Dim myComponents() As TaggedObject If SelectComponents("Select components", myComponents) = Selection.Response.Cancel Then Return End If For Each tempComp As Component In myComponents textFileName = "C:\temp\" & tempComp.Name & ".NC" Dim outFile As IO.StreamWriter outFile = My.Computer.FileSystem.OpenTextFileWriter(textFileName, _ False) outFile.AutoFlush = True outFile.WriteLine("/" & wpname) Dim rotX As Double 'rotation about X axis Dim rotY As Double 'rotation about Y axis Dim rotZ As Double 'rotation about Z axis Dim compPt As Point3d = CompPos(tempComp) CompRot(tempComp, rotX, rotY, rotZ) rotZ = rotZ + 180 outFile.WriteLine() outFile.WriteLine("/" & tempComp.Name) outFile.WriteLine("X" & compPt.X.ToString("F4") & " Y" & compPt.Y.ToString("F4") & " Z" & compPt.Z.ToString("F4") & " C" & rotZ.ToString("F4")) outFile.Close() 'MsgBox("Text File Name: " & textFileName, MsgBoxStyle.Information) Next End Sub Function SelectComponents(ByVal prompt As String, ByRef selObj() As TaggedObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select components" Dim includeFeatures As Boolean = False Dim keepHighlighted As Boolean = False Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific 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_component_subtype End With Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selobj) If resp = Selection.Response.Ok Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Sub CompRot(ByVal someComponent As Component, ByRef RX1 As Double, ByRef RY1 As Double, ByRef RZ1 As Double) 'extract euler angles from rotation matrix: 'https://d3cw3dd2w32x2b.cloudfront.net/wp-content/uploads/2012/07/euler-angles.pdf Dim pt As Point3d Dim RotMat As Matrix3x3 someComponent.GetPosition(pt, RotMat) Dim c1, c2, s1 As Double RX1 = Math.Atan2(RotMat.Yz, RotMat.Zz) c2 = Math.Sqrt(RotMat.Xx ^ 2 + RotMat.Xy ^ 2) RY1 = Math.Atan2(-RotMat.Xz, c2) s1 = Math.Sin(RX1) c1 = Math.Cos(RX1) RZ1 = Math.Atan2(s1 * RotMat.Zx - c1 * RotMat.Yx, c1 * RotMat.Yy - s1 * RotMat.Zy) 'convert angles from radians to degrees RX1 *= (180 / Math.PI) RY1 *= (180 / Math.PI) RZ1 *= (180 / Math.PI) End Sub Function CompPos(ByVal someComponent As Component) As Point3d Dim pt As Point3d Dim RotMat As Matrix3x3 someComponent.GetPosition(pt, RotMat) Return pt End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End ModuleRE: Get Component Rotation Angles
Also, I noticed that you are using the component's .Name property. This will return the custom name assigned by the user; it is possible that 2 identical components have different names. This might never be an issue for you, but if it is, you may want to look into using the .DisplayName or some other mechanism to ensure you are grouping components properly.
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
http://msdn.microsoft.com/en-us/library/aa903372%2...
www.nxjournaling.com
RE: Get Component Rotation Angles
Thanks
RE: Get Component Rotation Angles
If so, my first thought would be to keep a list of component names; if the list contains the component name, skip it - otherwise write the info to your file then add the component name to the list.
CODE --> pseudocode
dim compList as new list (of string) 'process components for each myComp in componentCollection if not compList.contains(myComp.name) then write info to file compList.add(myComp.name) end if nextwww.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
That makes sense. Glad you got it working as you needed.
Thanks for the update.
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
Something like this?
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim theComponent As Assemblies.Component If SelectComponent("Select a component", theComponent) = Selection.Response.Cancel Then Exit Sub End If Const dumbPointName As String = "DUMB_POINT" Const featurePointName As String = "FEATURE_POINT" Dim thePart As Part = theComponent.Prototype.OwningPart For Each temp As Point In thePart.Points If temp.Name = dumbPointName Then lw.WriteLine(dumbPointName & " found, location: " & temp.Coordinates.ToString) End If Next For Each temp As Features.Feature In thePart.Features If temp.FeatureType = "POINT" Then If temp.Name = featurePointName Then Dim thePoint As Point = temp.GetEntities(0) lw.WriteLine(featurePointName & " found, location: " & thePoint.Coordinates.ToString) End If End If Next lw.Close() End Sub Function SelectComponent(ByVal prompt As String, ByRef myComp As Assemblies.Component) As Selection.Response Dim selObj As TaggedObject Dim theUI As UI = UI.GetUI Dim title As String = "Select a component" 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.SelectTaggedObject(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selobj, cursor) If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then myComp = selObj Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Modulewww.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
pt: (0,0,0)
0° rotation about X axis
0° rotation about Y axis
0° rotation about Z axis
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
thread561-349259: Journal Read Attribute
www.nxjournaling.com
RE: Get Component Rotation Angles
CODE -->
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Imports NXOpen.Assemblies Imports System.IO Imports System.Collections.Generic Module Module1 Public s As Session = Session.GetSession() Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = s.Parts.Work Dim wpName As String = workPart.FullPath.ToString() Dim textFileName As String = Nothing Dim myComponents() As TaggedObject Dim lw As ListingWindow = theSession.ListingWindow lw.Open() If SelectComponents("Select components", myComponents) = Selection.Response.Cancel Then Return End If For Each tempComp As Component In myComponents Dim thePart As Part = tempcomp.Prototype.OwningPart Const dumbPointName As String = "DUMB_POINT" Const featurePointName As String = "FEATURE_POINT" For Each temp As Point In thePart.Points 'If temp.Name = dumbPointName Then lw.WriteLine(dumbPointName & " found, location: " & temp.Coordinates.ToString) 'End If Next lw.Close() End Sub Function SelectComponents(ByVal prompt As String, ByRef selObj() As TaggedObject) As Selection.Response Dim theUI As UI = UI.GetUI Dim title As String = "Select components" Dim includeFeatures As Boolean = False Dim keepHighlighted As Boolean = False Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific 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_component_subtype End With Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selobj) If resp = Selection.Response.Ok Then Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function End ModuleRE: Get Component Rotation Angles
www.nxjournaling.com
RE: Get Component Rotation Angles
RE: Get Component Rotation Angles
CODE -->
RE: Get Component Rotation Angles
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim theUfSession As UFSession = UFSession.GetUFSession Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() Dim theComponent As Assemblies.Component If SelectComponent("Select a component", theComponent) = Selection.Response.Cancel Then Exit Sub End If Const dumbPointName As String = "DUMB_POINT" Const featurePointName As String = "FEATURE_POINT" Dim thePart As Part = theComponent.Prototype.OwningPart For Each temp As Point In thePart.Points If temp.Name = dumbPointName Then lw.WriteLine(dumbPointName & " found, location in part: " & temp.Coordinates.ToString) Dim pointLoc() As Double = {temp.Coordinates.X, temp.Coordinates.Y, temp.Coordinates.Z} 'make component the work part Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part") Dim partLoadStatus1 As PartLoadStatus theSession.Parts.SetWorkComponent(theComponent, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus1) workPart = theSession.Parts.Work partLoadStatus1.Dispose() 'map point from component to assembly theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_WORK_COORDS, pointLoc, UFConstants.UF_CSYS_ROOT_COORDS, pointLoc) lw.WriteLine("location in assembly ACS: " & pointLoc(0) & ", " & pointLoc(1) & ", " & pointLoc(2)) lw.WriteLine("") 'make assembly the work part Dim markId2 As Session.UndoMarkId markId2 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Make Work Part") Dim nullAssemblies_Component As Assemblies.Component = Nothing Dim partLoadStatus2 As PartLoadStatus theSession.Parts.SetWorkComponent(nullAssemblies_Component, PartCollection.RefsetOption.Current, PartCollection.WorkComponentOption.Visible, partLoadStatus2) workPart = theSession.Parts.Work partLoadStatus2.Dispose() End If Next For Each temp As Features.Feature In thePart.Features If temp.FeatureType = "POINT" Then If temp.Name = featurePointName Then Dim thePoint As Point = temp.GetEntities(0) lw.WriteLine(featurePointName & " found, location: " & thePoint.Coordinates.ToString) End If End If Next lw.Close() End Sub Function SelectComponent(ByVal prompt As String, ByRef myComp As Assemblies.Component) As Selection.Response Dim selObj As TaggedObject Dim theUI As UI = UI.GetUI Dim title As String = "Select a component" 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.SelectTaggedObject(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selobj, cursor) If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then myComp = selObj Return Selection.Response.Ok Else Return Selection.Response.Cancel End If End Function Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination End Function End Modulewww.nxjournaling.com
RE: Get Component Rotation Angles