Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module Module1
Dim idSymbolBuilder1 As Annotations.IdSymbolBuilder
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 myScreenPos(2) As Double
Dim theViewTag As Tag = theSession.Parts.Display.Views.WorkView.Tag
Dim theResponse As Integer
Dim myIdSymbol As Annotations.IdSymbol
If SelectIdSymbol("select ID Symbol", myIdSymbol) = Selection.Response.Cancel Then
Exit Sub
End If
idSymbolBuilder1 = workPart.Annotations.IdSymbols.CreateIdSymbolBuilder(myIdSymbol)
'lw.WriteLine("symbol type: " & idSymbolBuilder1.Type.ToString)
'lw.WriteLine("symbol size: " & idSymbolBuilder1.Size.ToString)
'lw.WriteLine("symbol text: " & idSymbolBuilder1.UpperText)
'lw.WriteLine("symbol origin: " & idSymbolBuilder1.Origin.OriginPoint.ToString)
theUfSession.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
theUfSession.Ui.SpecifyScreenPosition("pick a point", AddressOf MotionCallback, Nothing, myScreenPos, theViewTag, theResponse)
theUfSession.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
idSymbolBuilder1.Destroy()
End Sub
Function SelectIdSymbol(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response
Dim theUI As UI = UI.GetUI
Dim title As String = "Select an ID Symbol"
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_drafting_entity_type
.Subtype = UFConstants.UF_draft_id_symbol_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
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If
End Function
Sub MotionCallback(ByVal pos() As Double, _
ByRef motion_cb_data As UFUi.MotionCbData, _
ByVal client_data As System.IntPtr)
Dim point1 As Point3d = New Point3d(pos(0), pos(1), pos(2))
idSymbolBuilder1.Origin.Origin.SetValue(Nothing, Nothing, point1)
idSymbolBuilder1.Commit()
End Sub
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