Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Get Component Rotation Angles 4

Status
Not open for further replies.

ramakrishna90589

Automotive
May 13, 2013
19
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.


 
Replies continue below

Recommended for you

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

                  
        [highlight #FCE94F]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[/highlight]         
        
        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
 
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
 
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
'**************************************************************************************************
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor