×
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

Get Component Rotation Angles
4

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.

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

Angles relative to what?

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

(OP)
Hi John R. Baker,

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

Relative to a coordinate system still does not tell us anything. What 'feature' of a component is going to be used as the reference? Not all objects have readily recognizable 'features' which could used when measuring angles. Take for instance something which is basically rectangular or spherical.

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

You have added a component to the assembly and moved it around to position it in the assembly; now you want to know the rotation angles to get it from the initial position to the assembled position, is this correct?

www.nxjournaling.com

RE: Get Component Rotation Angles

(OP)
Cowski Your right. That is what i want. But i want component rotation angle (About X,Y & Z) in Degrees not as a rotation matrix.

Thanks

RE: Get Component Rotation Angles

(OP)
What i need is, i have a component in an assembly and i want to get this component absolute co-ordinate system (Component Reference Feature is component absolute co-ordinate system) rotation angles (in degrees about X,Y & Z) with respect to assembly absolute co-ordinate system.

Thanks

RE: Get Component Rotation Angles

What do you plan on doing with these angles once you know them?
What is your end goal?

www.nxjournaling.com

RE: Get Component Rotation Angles

3
I had a chance to do some coding this afternoon; this isn't heavily tested, but seems to work.

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

        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  
    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 Module 

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

(OP)
cowski, This program worked perfectly for me. thanks for your support.

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

I should mention that the journal reports the rotations as if the component were rotated about the X axis then the Y axis and finally the Z axis (order is important). If you want to recreate the position, you will need to follow XYZ order, otherwise you will end up with a different orientation.

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

(OP)
Yes, this is better way. i want to how to create a CSys using Vb journal (Rotation matrix). We have one problem at here, generally we will insert parts from Customer library and many of these part does not contains CSYS (at absolute) in this case how to use CSYS to Csys move command (we don't have write access to this file so we can't create a CSYS in the part) . please help me in this regards.

Thanks for your valuable suggestion

RE: Get Component Rotation Angles

@cowski,
that is pretty cool, what you offered

RE: Get Component Rotation Angles

uwam2ie,
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. smile

https://dl.dropboxusercontent.com/u/80688373/recor...

www.nxjournaling.com

RE: Get Component Rotation Angles

(OP)
cowski i have tested two programs and those working very perfectly. this programs are really good for us. thanks a lot.

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

(OP)
elaborating my previous post ,

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

When you add the component, if you use the "Absolute origin" positioning option, the absolute csys of the part will align to the absolute csys of the assembly. If you want a visual indication of the absolute part csys, make it the display part and move the WCS to absolute. Now create a datum csys or save the WCS (this will create a visible csys object), you will be able to reference one of these while working in the assembly. Even if you do not have write access to the part, you will be able to save a csys and reference it while it is in session.

www.nxjournaling.com

RE: Get Component Rotation Angles

(OP)
Thanks cowski.

RE: Get Component Rotation Angles

I really like the journal posted on 14 May 13 16:16 in this thread. Is it possible to add the xyz locations of the components that I pick in the assembly to this journal? This is exactly what we are looking for. Thanks for posting.

RE: Get Component Rotation Angles

The following code will also report the component position.

CODE

'NXJournaling
'May 14, 2013
'Select a component, report the rotations about the X, Y, and Z axes
'that orient the component from its initial position to its current position.

'ref: eng-tips thread561-344785: Get Component Rotation Angles: Get Component Rotation Angles

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
            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(" " & CompPos(tempComp).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 Module 

www.nxjournaling.com

RE: Get Component Rotation Angles

Thanks for the quick reply. Is there a way to get this [X=6.52,Y=10.35,Z=0.625] which is the result from your journal to look like this X6.52 Y10.35 Z0.625 . No Brackets, commas or equals signs. Thanks

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 Module 

www.nxjournaling.com

RE: Get Component Rotation Angles

Absolutely Brilliant.

RE: Get Component Rotation Angles

I have revised the journal file to create a separate file for each component. Is it possible if there are identical components to send that group to a file. For example component1 has 3 locations which would get written to file 1 and component2 has only 1 location which would get written to file 2. Thanks

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 Module 

RE: Get Component Rotation Angles

I'd suggest using the .AppendText method of the stream writer; see http://msdn.microsoft.com/en-us/library/3zc0w663.a... for some example code.

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

Thanks. I think I will go through the list of chosen components and create the files. Then I will go through the list of components again and append the information to the existing files.

RE: Get Component Rotation Angles

You should be able to use the Append mode and go through the components just once. If the file doesn't exist, Append mode will create it; if it does exist, it will append to it.

www.nxjournaling.com

RE: Get Component Rotation Angles

I found a good example on the Microsoft webpage for appending files. Thanks. Do you know where I can look at a sample for manipulating strings. I have strings like this 1234abcd1 and 1234abcd10 sometimes the text in between is longer. I need to end up with just the right end number 1 and 10. Thanks

RE: Get Component Rotation Angles

In the above NX journal is there a way to filter the selection of components to supply me with only the unique components. I am looking for a way to append text only once to the bottom of each file I created.

Thanks

RE: Get Component Rotation Angles

If you have multiples of a component, each one can be positioned independently. You only need the position of 1?

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
next 

www.nxjournaling.com

RE: Get Component Rotation Angles

I needed the positions of all of the components. For example Part 4 had 6 locations which were appended to the file. At the end of the file I needed to add some NC code but only once not one time for every part location. So I had it go through the components one more time leaving out the duplicate parts just to add the NC code. Everything worked out great. Thanks for the help on this project.

RE: Get Component Rotation Angles

Quote (Derwood785)

I needed to add some NC code but only once not one time for every part location

That makes sense. Glad you got it working as you needed.

Thanks for the update.

www.nxjournaling.com

RE: Get Component Rotation Angles

Is it possible to get XYZ values of a named point within a component just by selecting the component as we do in the above journals.

RE: Get Component Rotation Angles

It is possible. Are you looking for a named point object, or a named point feature?

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 Module 

www.nxjournaling.com

RE: Get Component Rotation Angles

I am trying to get a location of a named 3D point per component. Also I am trying to make this work with the above journal. Thanks

RE: Get Component Rotation Angles

In the original journal that we created I pick the component and it writes a file with the xyz and rotation angles. Consider this as the finish location of the component. I want to add start location for the component within the same journal. The start location of the component would be straight up in the +Z direction an amount ex. Z1.0 or in a direction based on an amount and a given angle which would modify the xyz values. I need all of this to write to the file all at the same time. I thought that if we just created a point in the component we could report on the component(finish location) and its point(start location) at the same time but the journal you gave me recently doesn't seen to mesh well with the one we created earlier. Any help would be greatly appreciated. Thank-you very much.

RE: Get Component Rotation Angles

If all you need is the component start position, that's easy:
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

wasn't really what I was looking for. How about this? Can I read attributes from a component and have them set to variables in my journal?

RE: Get Component Rotation Angles

This is what I was trying to figure out before. For a group of selected components in an assembly I would like to be able to get a location for a named point. The location being within the assembly. Right now the area highlighted in yellow gets me the location of the point relative to the owning components csys. Could you help me try to maintain the structure of the code that is not highlighted and modify the yellow highlighted code to achieve this. Thanks

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 Module 

RE: Get Component Rotation Angles

Once you find the point of interest, you need to convert it from "component space" to "assembly space"; search the API reference for the MapPoint function to get headed in the right direction.

www.nxjournaling.com

RE: Get Component Rotation Angles

Thanks I will check this out

RE: Get Component Rotation Angles

I found an example of Mappoint but it keeps returning the same values. Do you have any examples for "component space" to "assembly Space" This is the example I found.

CODE -->

'**************************************************************************************************
'function taken from GTAC example
Function Abs2WCS(ByVal inPt As Point3d) As Point3d
	Dim pt1(2), pt2(2) As Double
	
	pt1(0) = inPt.X
	pt1(1) = inPt.Y
	pt1(2) = inPt.Z
	
	ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)
  
	
	Abs2WCS.X = pt2(0)
	Abs2WCS.Y = pt2(1)
	Abs2WCS.Z = pt2(2)
	
End Function
'************************************************************************************************** 

RE: Get Component Rotation Angles

The below code is a modification of my last code post; it will report the location of a dumb point in the part space and the assembly space (absolute csys).

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 Module 

www.nxjournaling.com

RE: Get Component Rotation Angles

Works AWESOME!!!!!!! Thanks

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

White Paper - Guide to Integrate Large-Format Additive
As with any new technology, getting into large-format 3D printing begins with investigation. The first question may be a simple one: what does “large-format” mean? For 3D printers, “large” is a relative term. Many extrusion-based (FFF) 3D printers are referred to as desktop machines, because they fit on table space. Some of these have very respectable build volumes – but when it comes to “large-format,” the machines will need their own dedicated floor space. Large-format 3D printers have significant build volumes and are most often found in professional settings, like manufacturing facilities and R&D centers. Download Now
eBook - Efficient and Effective Production Support with 3D Printed Jigs and Fixtures
Jigs and fixtures offer manufacturers a reliable process for delivering accurate, high-quality outcomes, whether for a specific part or feature, or for consistency across multiples of parts. Although the methodologies and materials for producing jigs and fixtures have evolved beyond the conventional metal tooling of years past, their position as a manufacturing staple remains constant due to the benefits they offer. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close