Hi NX Journaling,
I want to assign the feature name to the object. I understand that to access the feature of the object, i need to do type casting or get the name of the feature by checking the associated / referenced feature of the object.
I tried doing type casting, but i get an error, "Object reference not set to an instance of an Object"
while using Ctype i get other error, "Unable to cast object of type NXOpen.Point to NXopen.Features.PointFeature"
Could you please help and modify the below code so that,
1.) i can pick the object from 3D space and get the feature name associated with the object to rename the selected object
2.) also as a next step i want to make this journal for multiple selections
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Module RenameObj
Sub Main()
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display
'Dim ufs As UFSession = Nothing
Dim lw As ListingWindow = theSession.ListingWindow
Dim objPoint As NXObject = SelectPoint("Report Object ID")
Do While objPoint IsNot Nothing
lw.Open()
Dim objName As String = Nothing
Dim fName As String = Nothing
'lw.WriteLine(".Name: "& fPoint.Name)
'Dim objPoint As NXOpen.TaggedObject = SelectPoint("Report Object ID")
Dim fPoint As NXOpen.Features.PointFeature = TryCast(objPoint, NXOpen.Features.PointFeature)
'Dim fPoint As NXOpen.Features.PointFeature = CType(objPoint, NXOpen.Features.PointFeature)
lw.Close()
fName = fPoint.GetFeatureName ' comment this line and uncomment the next line
'fName = fPoint.Name
lw.WriteLine(".Name: "& fName)
objPoint.SetName(fName)
'objPoint.SetName(objName & 2)
objPoint = SelectPoint("Report Object ID")
Loop
End Sub
Function SelectPoint(ByVal prompt As String) As NXObject
Dim selobj As NXObject = Nothing
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType =
{Selection.SelectionType.All,
Selection.SelectionType.Faces,
Selection.SelectionType.Edges}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject(
prompt, "Select an object",
Selection.SelectionScope.AnyInAssembly,
False, typeArray, selobj, cursor)
Return selobj
End Function
End Module