Renaming NX feature

To rename datum features I've been trying to write a journal based upon information I've found on this forum.
I'm trying to rename a datum feature only when it has a specific attribute1 and rename it using an attribute2 that this datumplane already has.

This is the code I have until now:

Option Strict Off
Imports System
Imports NXOpen

Module Module1

Sub Main()

Const attributeTitle As String = "GSDDIR"
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each temp As TaggedObject In workPart.Datums
If TypeOf (temp) Is DatumPlane Then
Dim dPlane As DatumPlane = temp
'check for attribute
If dPlane.HasUserAttribute(attributeTitle,NXObject.AttributeType.String, -1) Then
dPlane.SetName("TEST")
End If
End If

Next
lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

I'm not so experienced with writing journals so any help is very much appreciated.

One thing to keep in mind is the difference between objects and features; the two are closely related, yet distinct. The datum plane object, in this case, is the rectangular depiction of a plane that you see in the graphics window; the datum plane feature is the entry in the part navigator. For simplicity, you can think of the datum plane feature as a container for the datum plane object that manages the associativities and updates the datum plane accordingly. Distinguishing between the object and feature is important because each is an object in its own right and can be assigned a name or other attributes independently of the other.

The title of your post indicates that you want to rename the feature, but the code searches for and renames the object itself. If you want to rename the object based on an object attribute - congratulations, your code works (assuming the "GSDDIR" attribute has been assigned to the datum plane object and not the feature)! To see the object name, turn on object name display (menu -> preferences -> visualization -> names/borders -> show object names = all views) or check the object properties (right click the datum plane in the graphics window -> properties -> general). On the object properties "general" tab, you will see the "name" and "feature name" entries; the name that you have assigned ("TEST"), will appear in the "name" entry box.

If you are looking for attributes that have been assigned to the feature, you can iterate through the part's feature collection, querying each datum plane feature until you find the one you need.

If the attribute has been assigned to the object and you want to rename the corresponding feature, you can use the datum plane's .Feature property to get the associated datum plane feature. Similarly, if you have a reference to the datum plane feature and want to get the datum plane object, you can use the feature's .DatumPlane property.

Thanks a lot for your reply, I understand what you mean but don't know how to rewrite the code. I want to use the value of a userattribute to rename the datumfeature, but this can't be done in the NXOpen.datumPlane. Any suggestions on how I should approach this?
Thanks in advance for your help!

If the "GSDDIR" attribute has been applied to the datum plane object, it only takes a small change to your code to rename the datum plane feature:

Option Strict Off
Imports System
Imports NXOpen

Module Module82

Sub Main()

Const attributeTitle As String = "GSDDIR"
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each temp As TaggedObject In workPart.Datums
If TypeOf (temp) Is DatumPlane Then
Dim dPlane As DatumPlane = temp
'check for attribute
If dPlane.HasUserAttribute(attributeTitle, NXObject.AttributeType.String, -1) Then
'dPlane.SetName("TEST")
dPlane.Feature.SetName("TEST")
End If
End If

Next
lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

Great, thanks a lot! so the last hurdle for me is to change "TEST" into the attributeValue that is attached to the datum object with attributeTitle GSDDIR
Kan I use this value directly or do I need to write it to a variable first?

You can use the value directly or write it to a variable first, it is a matter of your preference.

Option Strict Off
Imports System
Imports NXOpen

Module Module82

Sub Main()

Const attributeTitle As String = "GSDDIR"
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()

For Each temp As TaggedObject In workPart.Datums
If TypeOf (temp) Is DatumPlane Then
Dim dPlane As DatumPlane = temp
'check for attribute
If dPlane.HasUserAttribute(attributeTitle, NXObject.AttributeType.String, -1) Then
Dim strValue As String = dPlane.GetUserAttributeAsString(attributeTitle, NXObject.AttributeType.Any, -1)
dPlane.Feature.SetName(strValue)

'or combine into one line of code
'dPlane.Feature.SetName(dPlane.GetUserAttributeAsString(attributeTitle, NXObject.AttributeType.Any, -1))
End If
End If

Next
lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

Great, it works!! thank you so much!

Hi NX Journaling, i have a requirement to rename the point Objects to have same name as that of the point feature. Could you please help with that..??

Balaji