Convert point position from Absolute to WCS.

Hi, I am trying to get 07 point positions as per WCS orientation in an MS Excel template.

But every time I am getting those positions as per the absolute coordinate system.

I have tried converting the position from Abs to WCS, but nothing seems to be working.

Kindly refer following code and please let me know what I am doing wrong.

Thanks in Advance....

Any improvement feedback is most welcome.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.BlockStyler
Imports NXOpen.UF

'------------------------------------------------------------------------------
'Represents Block Styler application class
'------------------------------------------------------------------------------
Public Class Setup_Sheet1
'class members
Private Shared theSession As Session
Private Shared theUI As UI
Private theDlxFileName As String
Private theDialog As NXOpen.BlockStyler.BlockDialog
Private group0 As NXOpen.BlockStyler.Group' Block type: Group
Private point0 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
Private point01 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
Private point02 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
Private group01 As NXOpen.BlockStyler.Group' Block type: Group
Private point03 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
Private point04 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
Private point05 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
Private point06 As NXOpen.BlockStyler.SpecifyPoint' Block type: Specify Point
'------------------------------------------------------------------------------
'Bit Option for Property: SnapPointTypesEnabled
'------------------------------------------------------------------------------
Public Shared ReadOnly Dim SnapPointTypesEnabled_UserDefined As Integer = 1
Public Shared ReadOnly Dim SnapPointTypesEnabled_Inferred As Integer = 2
Public Shared ReadOnly Dim SnapPointTypesEnabled_ScreenPosition As Integer = 4
Public Shared ReadOnly Dim SnapPointTypesEnabled_EndPoint As Integer = 8
Public Shared ReadOnly Dim SnapPointTypesEnabled_MidPoint As Integer = 16
Public Shared ReadOnly Dim SnapPointTypesEnabled_ControlPoint As Integer = 32
Public Shared ReadOnly Dim SnapPointTypesEnabled_Intersection As Integer = 64
Public Shared ReadOnly Dim SnapPointTypesEnabled_ArcCenter As Integer = 128
Public Shared ReadOnly Dim SnapPointTypesEnabled_QuadrantPoint As Integer = 256
Public Shared ReadOnly Dim SnapPointTypesEnabled_ExistingPoint As Integer = 512
Public Shared ReadOnly Dim SnapPointTypesEnabled_PointonCurve As Integer = 1024
Public Shared ReadOnly Dim SnapPointTypesEnabled_PointonSurface As Integer = 2048
Public Shared ReadOnly Dim SnapPointTypesEnabled_PointConstructor As Integer = 4096
Public Shared ReadOnly Dim SnapPointTypesEnabled_TwocurveIntersection As Integer = 8192
Public Shared ReadOnly Dim SnapPointTypesEnabled_TangentPoint As Integer = 16384
Public Shared ReadOnly Dim SnapPointTypesEnabled_Poles As Integer = 32768
Public Shared ReadOnly Dim SnapPointTypesEnabled_BoundedGridPoint As Integer = 65536
Public Shared ReadOnly Dim SnapPointTypesEnabled_FacetVertexPoint As Integer = 131072
Public Shared ReadOnly Dim SnapPointTypesEnabled_DefiningPoint As Integer = 262144
'------------------------------------------------------------------------------
'Bit Option for Property: SnapPointTypesOnByDefault
'------------------------------------------------------------------------------
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_UserDefined As Integer = 1
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_Inferred As Integer = 2
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_ScreenPosition As Integer = 4
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_EndPoint As Integer = 8
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_MidPoint As Integer = 16
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_ControlPoint As Integer = 32
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_Intersection As Integer = 64
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_ArcCenter As Integer = 128
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_QuadrantPoint As Integer = 256
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_ExistingPoint As Integer = 512
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_PointonCurve As Integer = 1024
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_PointonSurface As Integer = 2048
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_PointConstructor As Integer = 4096
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_TwocurveIntersection As Integer = 8192
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_TangentPoint As Integer = 16384
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_Poles As Integer = 32768
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_BoundedGridPoint As Integer = 65536
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_FacetVertexPoint As Integer = 131072
Public Shared ReadOnly Dim SnapPointTypesOnByDefault_DefiningPoint As Integer = 262144

Dim positionX As New System.Collections.ArrayList
Dim positionY As New System.Collections.ArrayList
Dim positionZ As New System.Collections.ArrayList
Dim x As Integer
Dim excelApp = Microsoft.VisualBasic.Interaction.CreateObject("Excel.Application") '&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim f As Integer
Dim g As Integer
Dim ufs As UFSession = Nothing

#Region "Block Styler Dialog Designer generator code"
'------------------------------------------------------------------------------
'Constructor for NX Styler class
'------------------------------------------------------------------------------
Public Sub New()
Try

theSession = Session.GetSession()
theUI = UI.GetUI()
theDlxFileName = "Setup_Sheet1.dlx"
theDialog = theUI.CreateDialog(theDlxFileName)
theDialog.AddApplyHandler(AddressOf apply_cb)
theDialog.AddOkHandler(AddressOf ok_cb)
theDialog.AddUpdateHandler(AddressOf update_cb)
theDialog.AddInitializeHandler(AddressOf initialize_cb)
theDialog.AddDialogShownHandler(AddressOf dialogShown_cb)
ufs = NXOpen.UF.UFSession.GetUFSession()

Catch ex As Exception

'---- Enter your exception handling code here -----
Throw ex
End Try
End Sub
#End Region

'------------------------------- DIALOG LAUNCHING ---------------------------------
'
' Before invoking this application one needs to open any part/empty part in NX
' because of the behavior of the blocks.
'
' Make sure the dlx file is in one of the following locations:
' 1.) From where NX session is launched
' 2.) $UGII_USER_DIR/application
' 3.) For released applications, using UGII_CUSTOM_DIRECTORY_FILE is highly
' recommended. This variable is set to a full directory path to a file
' containing a list of root directories for all custom applications.
' e.g., UGII_CUSTOM_DIRECTORY_FILE=$UGII_BASE_DIR\ugii\menus\custom_dirs.dat
'
' You can create the dialog using one of the following way:
'
' 1. Journal Replay
'
' 1) Replay this file through Tool->Journal->Play Menu.
'
' 2. USER EXIT
'
' 1) Create the Shared Library -- Refer "Block UI Styler programmer's guide"
' 2) Invoke the Shared Library through File->Execute->NX Open menu.
'
'------------------------------------------------------------------------------
Public Shared Sub Main()
Dim theSetup_Sheet1 As Setup_Sheet1 = Nothing
Try

theSetup_Sheet1 = New Setup_Sheet1()
' The following method shows the dialog immediately
theSetup_Sheet1.Show()

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
Finally
If theSetup_Sheet1 IsNot Nothing Then
theSetup_Sheet1.Dispose()
theSetup_Sheet1 = Nothing
End If
End Try
End Sub
'------------------------------------------------------------------------------
' This method specifies how a shared image is unloaded from memory
' within NX. This method gives you the capability to unload an
' internal NX Open application or user exit from NX. Specify any
' one of the three constants as a return value to determine the type
' of unload to perform:
'
'
' Immediately : unload the library as soon as the automation program has completed
' Explicitly : unload the library from the "Unload Shared Image" dialog
' AtTermination : unload the library when the NX session terminates
'
'
' NOTE: A program which associates NX Open applications with the menubar
' MUST NOT use this option since it will UNLOAD your NX Open application image
' from the menubar.
'------------------------------------------------------------------------------
Public Shared Function GetUnloadOption(ByVal arg As String) As Integer
'Return CType(Session.LibraryUnloadOption.Explicitly, Integer)
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
' Return CType(Session.LibraryUnloadOption.AtTermination, Integer)
End Function
'------------------------------------------------------------------------------
' Following method cleanup any housekeeping chores that may be needed.
' This method is automatically called by NX.
'------------------------------------------------------------------------------
Public Shared Sub UnloadLibrary(ByVal arg As String)
Try

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'This method shows the dialog on the screen
'------------------------------------------------------------------------------
Public Sub Show()
Try

theDialog.Show

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'Method Name: Dispose
'------------------------------------------------------------------------------
Public Sub Dispose()
If theDialog IsNot Nothing Then
theDialog.Dispose()
theDialog = Nothing
End If
End Sub

'------------------------------------------------------------------------------
'---------------------Block UI Styler Callback Functions--------------------------
'------------------------------------------------------------------------------

'------------------------------------------------------------------------------
'Callback Name: initialize_cb
'------------------------------------------------------------------------------
Public Sub initialize_cb()
Try

group0 = CType(theDialog.TopBlock.FindBlock("group0"), NXOpen.BlockStyler.Group)
point0 = CType(theDialog.TopBlock.FindBlock("point0"), NXOpen.BlockStyler.SpecifyPoint)
point01 = CType(theDialog.TopBlock.FindBlock("point01"), NXOpen.BlockStyler.SpecifyPoint)
point02 = CType(theDialog.TopBlock.FindBlock("point02"), NXOpen.BlockStyler.SpecifyPoint)
group01 = CType(theDialog.TopBlock.FindBlock("group01"), NXOpen.BlockStyler.Group)
point03 = CType(theDialog.TopBlock.FindBlock("point03"), NXOpen.BlockStyler.SpecifyPoint)
point04 = CType(theDialog.TopBlock.FindBlock("point04"), NXOpen.BlockStyler.SpecifyPoint)
point05 = CType(theDialog.TopBlock.FindBlock("point05"), NXOpen.BlockStyler.SpecifyPoint)
point06 = CType(theDialog.TopBlock.FindBlock("point06"), NXOpen.BlockStyler.SpecifyPoint)

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

'------------------------------------------------------------------------------
'Callback Name: dialogShown_cb
'This callback is executed just before the dialog launch. Thus any value set
'here will take precedence and dialog will be launched showing that value.
'------------------------------------------------------------------------------
Public Sub dialogShown_cb()
Try

'---- Enter your callback code here -----

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Sub

Public 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

'------------------------------------------------------------------------------
'Callback Name: apply_cb
'------------------------------------------------------------------------------
Public Function apply_cb() As Integer
Dim errorCode as Integer = 0
Try
'Snap.InfoWindow.WriteLine("positionX.Count is " & positionX.Count)
'---- Enter your callback code here -----
MiniSnap.InfoWindow.WriteLine("CoordinateX" & vbTab & "CoordinateY" & vbTab & "CoordinateZ")

For a = 0 To positionX.Count - 1
MiniSnap.InfoWindow.WriteLine(positionX(a) & vbTab & positionY(a) & vbTab & positionZ(a))
Next

excelApp.Workbooks.Open("D:\Open\application\Setup_Sheet_TRD.xltx")
excelApp.Visible = True
excelApp.UserControl = True

For a = 0 To positionX.Count - 7
excelApp.Cells(6, "D") = positionX(a)
excelApp.Cells(6, "E") = positionY(a)
excelApp.Cells(6, "F") = positionZ(a)
Next

For b = 0 To positionX.Count - 6
excelApp.Cells(7, "D") = positionX(b)
excelApp.Cells(7, "E") = positionY(b)
excelApp.Cells(7, "F") = positionZ(b)
Next

For c = 0 To positionX.Count - 5
excelApp.Cells(8, "D") = positionX(c)
excelApp.Cells(8, "E") = positionY(c)
excelApp.Cells(8, "F") = positionZ(c)
Next

For d = 0 To positionX.Count - 4
excelApp.Cells(6, "H") = positionX(d)
excelApp.Cells(6, "I") = positionY(d)
excelApp.Cells(6, "J") = positionZ(d)
Next

For e = 0 To positionX.Count - 3
excelApp.Cells(7, "H") = positionX(e)
excelApp.Cells(7, "I") = positionY(e)
excelApp.Cells(7, "J") = positionZ(e)
Next

For f = 0 To positionX.Count - 2
excelApp.Cells(8, "H") = positionX(f)
excelApp.Cells(8, "I") = positionY(f)
excelApp.Cells(8, "J") = positionZ(f)
Next

For g = 0 To positionX.Count - 1
excelApp.Cells(9, "H") = positionX(g)
excelApp.Cells(9, "I") = positionY(g)
excelApp.Cells(9, "J") = positionZ(g)
Next

Catch ex As Exception

'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
apply_cb = errorCode
End Function

'------------------------------------------------------------------------------
'Callback Name: update_cb
'------------------------------------------------------------------------------
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try

If block Is point0 Then
'---- Enter your code here -----

positionX.Add(point0.Point.X)
positionY.Add(point0.Point.Y)
positionZ.Add(point0.Point.Z)

ElseIf block Is point01 Then
'---- Enter your code here -----

positionX.Add(point01.Point.X)
positionY.Add(point01.Point.Y)
positionZ.Add(point01.Point.Z)

ElseIf block Is point02 Then
'---- Enter your code here -----

positionX.Add(point02.Point.X)
positionY.Add(point02.Point.Y)
positionZ.Add(point02.Point.Z)

ElseIf block Is point03 Then
'---- Enter your code here -----

positionX.Add(point03.Point.X)
positionY.Add(point03.Point.Y)
positionZ.Add(point03.Point.Z)

ElseIf block Is point04 Then
'---- Enter your code here -----

positionX.Add(point04.Point.X)
positionY.Add(point04.Point.Y)
positionZ.Add(point04.Point.Z)

ElseIf block Is point05 Then
'---- Enter your code here -----

positionX.Add(point05.Point.X)
positionY.Add(point05.Point.Y)
positionZ.Add(point05.Point.Z)

ElseIf block Is point06 Then
'---- Enter your code here -----

positionX.Add(point06.Point.X)
positionY.Add(point06.Point.Y)
positionZ.Add(point06.Point.Z)

End If

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
update_cb = 0
End Function

'------------------------------------------------------------------------------
'Callback Name: ok_cb
'------------------------------------------------------------------------------
Public Function ok_cb() As Integer
Dim errorCode as Integer = 0
Try

'---- Enter your callback code here -----
errorCode = apply_cb()

Catch ex As Exception

'---- Enter your exception handling code here -----
errorCode = 1
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
ok_cb = errorCode
End Function

'------------------------------------------------------------------------------
'Function Name: GetBlockProperties
'Returns the propertylist of the specified BlockID
'------------------------------------------------------------------------------
Public Function GetBlockProperties(ByVal blockID As String) As PropertyList
GetBlockProperties = Nothing
Try

GetBlockProperties = theDialog.GetBlockProperties(blockID)

Catch ex As Exception

'---- Enter your exception handling code here -----
theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
End Try
End Function

End Class

There is a function in your code named Abs2WCS that looks to do what you want. However, your code never calls the function.

Ok. Thank you for pointing out the issue. But how can I call that code(Abs2WCS)? Can you please let me know?

Parthasarathi Nayak

After a quick look at your code, I think you might want to call the function in the update_cb function; but it really depends on your needs.

Perhaps something like below:

'------------------------------------------------------------------------------
'Callback Name: update_cb
'------------------------------------------------------------------------------
Public Function update_cb(ByVal block As NXOpen.BlockStyler.UIBlock) As Integer
Try

Dim newPt as Point3d

If block Is point0 Then
'---- Enter your code here -----
newPt = Abs2WCS(point0.Point)
positionX.Add(newPt.X)
positionY.Add(newPt.Y)
positionZ.Add(newPt.Z)
.
.
.

now the code is Working. Thank you very much for the help.

Parthasarathi Nayak