Edit part attribute in catagory

Dear all,

I'm trying to edit the text in one of the attributes of the part. However, I am unable to do so when the attribute is in a catagory. I don't think I am the first one who tries to do something like this. There is probably some code out there. Sadly enough I am not able to find it.

Any help would be greatly appriciated!

Kind regards,

Frank

What version of NX are you using? Can you post the code that you have so far?

I'm currently using NX 10 for production parts (but have other versions installed for testing), I've not run into a problem with attributes in a category (yet).

My apologies for the rather limited amount of information. I am using NX10.

I have been able to solve my problem with the following code. This seems to work beautifully.

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)
Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work

'Undo mogelijk maken
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim objects1(0) As NXOpen.NXObject
objects1(0) = workPart
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, NXOpen.AttributePropertiesBuilder.OperationType.None)

'Attribute invullen
attributePropertiesBuilder1.Category = "COMPANY"
attributePropertiesBuilder1.Title = "Drafted"
attributePropertiesBuilder1.StringValue = "FF"

'Waarde opslaan in property builder
Dim nXObject1 As NXOpen.NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

attributePropertiesBuilder1.Destroy()

End Sub
End Module

However. I ran into another problem. I also would like to modify a date attribute. This is more difficult. My recorded journal looks like this.

attributePropertiesBuilder1.Category = "COMPANY"
attributePropertiesBuilder1.Title = "Drawing date"
attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.Date
attributePropertiesBuilder1.DateValue.DateItem.Day = NXOpen.DateItemBuilder.DayOfMonth.Day20
attributePropertiesBuilder1.DateValue.DateItem.Month = NXOpen.DateItemBuilder.MonthOfYear.Mar
attributePropertiesBuilder1.DateValue.DateItem.Year = "2008"
attributePropertiesBuilder1.DateValue.DateItem.Time = "01:00:00"

I am able to determine the current date en change its appereance to something NX should accept. Sadly enough I haven't been able to get the current date into the attribute. Any help on that part will be greatly appriciated.

Dim TimeNote As DateTime

TimeNote = System.DateTime.Now()
Dim TimeNoteString as String() = TimeNote.GetDateTimeFormats()

'Datum omschrijven naar een formaat dat NX pikt
Dim InputTimeForNX as string
InputTimeForNX = TimeNoteString(1) 'format "19 sep 2019"
InputTimeForNX = InputTimeForNX.Replace(" ","-") 'Format "19-sep-2019"
InputTimeForNX = InputTimeForNX & " 01:00:00"

Below is a code snippet that I have used to set a date/time attribute in NX. I was working in the US english date/time format when I wrote the code; but I think the date information will work in any regional setting (NX stores the day, month, and year info separately). You might need to adjust the time format string to your preferences.

'add time attribute
Dim myDateTime As DateTime = Now

Dim attributePropertiesBuilder2 As AttributePropertiesBuilder
attributePropertiesBuilder2 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
With attributePropertiesBuilder2
.IsArray = False
.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.Date
.Category = "YourCategory"
.Title = "YourTitle"
.DateValue.DateItem.Day = myDateTime.Day - 1
.DateValue.DateItem.Month = myDateTime.Month - 1
.DateValue.DateItem.Year = myDateTime.Year.ToString
.DateValue.DateItem.Time = myDateTime.ToString("HH:mm:ss")
Dim nXObject7 As NXObject
nXObject7 = .Commit()
.Destroy()
End With

wanted to create a new part and as soon as it opens already run a journal to add the information in the attributes, ex: question: who did it? and a field to type, as soon as pressing "enter" another question, description? and a field to describe the item ....
so when the questionnaire ends, all items will be filled in the attributes.

NX has certain "user exits" that can be used to run your code when a specific event happens in NX.

https://docs.plm.automation.siemens.com/tdoc/nx/1899/nx_api/#uid:user_exits

One way to do what you want would be to write the code that shows the form and assigns the attributes and use the "new part" user exit to run the code at the appropriate time.

If you have a block styler license, you can create a dialog box with the look and feel of the NX dialogs. If you do not have a block styler license, you can make use of a Windows form (assuming you are running on a Windows computer); I suggest getting a version of Microsoft Visual Studio to help with the form design and overall coding.

There is an example of creating a winform for use with NX here:
http://nxjournaling.com/content/using-winforms-journals

That is a nice piece of code. Works like a charm!
Thanks again for all your help.