Rename a point feature after selecting the point object.

I'm hoping this is an easy question. I'm a bit new to nxopen and have been beating my head against the wall trying to figure this out.

I want to rename a point feature after selecting the point object.

I'm having a problem getting from the object to the object's features.

Dim pt1 As Point = CType(Start_Pt.GetSelectedObjects()(0), Point)

pt1.SetName("Start_Point") 'This sets the name of the point object

What I want to do is set the name of the feature for the point. I'm not sure how to access the features of an object.

Thanks,
Dennis

Actually, I figured it out. I'm using the Block UI styler which generates a lot of code, so I'm not posting all of it. The relevant code looks something like this:

'This line is generated by the Block UI Styler
Private Start_Pt As NXOpen.BlockStyler.SelectObject

'This is my code
Dim pt1 As Point = CType(Start_Pt.GetSelectedObjects()(0), Point)
Dim StartPtFt As Features.PointFeature = Nothing
Dim lw As ListingWindow = theSession.ListingWindow

StartPt3d = CType(pt1.Coordinates, Point3d)
pt1.SetName("Start_Point")

Dim GetPtSrc() As NXObject = pt1.GetUserAttributeSourceObjects

For Each obj As NXObject In GetPtSrc
If obj.GetType.Name = "PointFeature" Then
StartPtFt = obj
End If
Next

StartPtFt.SetName("Start_Point_Feature")

crashkey

The .AskObjectFeat method is a more direct way to get the feature given an object.

Thanks! I hadn't come across that method yet. I definitely have a lot to learn still.

crashkey

hi Crash Key,

I have a similar requirement as yours. I want to assign feature name to the object after selecting the object. But i'm unable to get the feature associated / referenced by the object.

Below is the code which i have:
what i want to do is,
1.Get the feature name after selecting the point object
2.Assign Name to the object from the variable

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 = Nothing

Dim objPoint As NXObject = SelectAnObject("Report Object ID")

Do While objPoint IsNot Nothing
Dim objPointName As String = objPoint.GetFeatureName 'Getting Error "GetFeatureName is not a member of NXopen.NXObject
Dim fPoint As NXOpen.Features.PointFeature = CType(workPart.Features.FindObject(objPointName), NXOpen.Features.PointFeature)
Dim fName = fPoint.Name
objPoint.SetName(fName)

objPoint = SelectAnObject("Report Object ID")

Loop
End Sub

Function SelectAnObject(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

Balaji

The code below shows how to get the parent feature from a point object, if it has one.

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 myPoint As Point

Do Until SelectPointObject("select point", myPoint) = Selection.Response.Cancel
Dim featureTag As Tag
theUfSession.Modl.AskObjectFeat(myPoint.Tag, featureTag)
Dim pointFeature As Features.Feature

If featureTag = Tag.Null Then
'point does not belong to feature
lw.WriteLine("unassociative point: " & myPoint.Coordinates.ToString)
lw.WriteLine("")
Else
'point associated to feature
pointFeature = Utilities.NXObjectManager.Get(featureTag)
'lw.WriteLine("feature type: " & pointFeature.GetType.ToString)
lw.WriteLine("point associated to: " & pointFeature.GetFeatureName)
lw.WriteLine(myPoint.Coordinates.ToString)
lw.WriteLine("")
End If

Loop

lw.Close()

End Sub

Function SelectPointObject(ByVal prompt As String, ByRef selPoint As Point) As Selection.Response

Dim selObj As TaggedObject
Dim theUI As UI = UI.GetUI
Dim title As String = "Select a Point"
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_point_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
selPoint = 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

'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

hi NX Journaling, thanks for the code to get the associated parent feature. Your code gives the associated point. In my case i have the point feature renamed in the part navigator. For instance your code returns: point assoicated to point(5). but i have the assigned feature name as "A". How can i get this feature name..??

i want to get this point name and assign to the selected object.
Thanks, B

Balaji

Instead of .GetFeatureName, use .Name; this will return the custom name assigned to the feature (if it has one).

hi, i've tried using .Name instead of the .GetFeatureName in your code. But i'm getting an error message: 'GetName' is not a member of 'NXOpen.FEatures.Feature
Thanks, B

Balaji

Not .GetName, just .Name. There is no .GetName method associated with features.

sorry, my bad. I'm gone dumb. It's working fine now. i Will update my code to rename the object by getting the feature name. Will post my code after updating.
Thanks

Balaji