Option Strict Off
Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports NXOpen
Imports NXOpen.UF
Module vector_dir_to_clipboard
Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow
Sub Main()
lw.Open()
Dim myDatumAxis As DatumAxis
If SelectDatumAxis("select datum axis", myDatumAxis) = Selection.Response.Cancel Then
Return
End If
Dim ptDir As New Point3d(myDatumAxis.Direction.X, myDatumAxis.Direction.Y, myDatumAxis.Direction.Z)
ptDir.X += theSession.Parts.Work.WCS.Origin.X
ptDir.Y += theSession.Parts.Work.WCS.Origin.Y
ptDir.Z += theSession.Parts.Work.WCS.Origin.Z
Dim newPt As Point3d
newPt = Abs2WCS(ptDir)
'lw.WriteLine("absolute dir:")
'lw.WriteLine(myDatumAxis.Direction.ToString)
'lw.WriteLine("")
'lw.WriteLine("WCS dir:")
'lw.WriteLine(newPt.ToString)
Clipboard.SetText(myDatumAxis.Direction.ToString)
lw.Close()
End Sub
Function WCS2Abs(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
theUfSession.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt1, UFConstants.UF_CSYS_ROOT_COORDS, pt2)
WCS2Abs.X = pt2(0)
WCS2Abs.Y = pt2(1)
WCS2Abs.Z = pt2(2)
End Function
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
theUfSession.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
Function SelectDatumAxis(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a datum axis"
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.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = UFConstants.UF_datum_axis_type
.Subtype = 0
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
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
'----Other unload options-------
'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------
End Function
End Module