extracting object attributes

Hi,

New to this forum, need help. We use team center and i want to link object attributes to the bom table comes along with template. I basically want to click a cell in the table and run the journal by which it will assign the required attribute by selecting the part from the list of parts in the assembly.

As of now, we are adding the attribute by right click on cell---> edit text----> relationships---->link object attribute.

Please help me out.

It sounds like you want to add component attributes to the parts list. If this is the case, you should check out the following thread on eng-tips.com:
http://www.eng-tips.com/viewthread.cfm?qid=366031

If the attributes need to be listed for all new files going forward, you should update your parts list template to include them. Once in the template, they will show up in the new part and you won't need to write any code.

Hi thank you so much for the reply,

I am aware of what you are talking about, but my problem is not with the part list. We have a bom table which comes default with drawing template and we add the required attributes of required parts under the master assembly using relationships from text editor. I just want to run a journal to extract the attributes and assign the required values into the existing table in the template.

Thank you

Thank you,
Sravan

Is the BOM table a plain tabular note (not a parts list)?

Also, what version of NX are you using?

Yes it is a plain tabular note and not a part list. We are using nx8.

Thank you,

Thank you,
Sravan

Any help?

Thank you,
Sravan

I plan on looking at this, but I've been caught up in other projects.

Thank you so much. I can wait, please let me kmow once you figured it out.

Thank you,
Sravan

The code below illustrates how to associatively extract an attribute value and add it to a tabular note. It will prompt you to select the tabular note, then it will prompt you to select a component. The component display name will be written in the first column (starting in the second row, the first row is assumed to contain header information) and the "Material" attribute value will be written in the 2nd column. It will continue to prompt for a component until you select the "cancel" button.

The code was written for NX 8.

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

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

Sub Main()

If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If

lw.Open()

Const undoMarkName As String = "NXJ journal"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

Dim theTabNote As Annotations.TableSection
If SelectTabNoteSection("Select a tabular note", theTabNote) = Selection.Response.Cancel Then
Return
End If

Dim theComponent As Assemblies.Component
'starting row number of tabular note
Dim row As Integer = 1
Dim attTitle As String = "Material"

Do Until SelectComponent("select a component", theComponent) = Selection.Response.Cancel
'does material attribute exist?
If theComponent.HasUserAttribute(attTitle, NXObject.AttributeType.String, 0) Then
'lw.WriteLine("has material attribute")
AddComponentInfo(theComponent, attTitle, row, theTabNote)
row += 1
Else
lw.WriteLine("component, " & theComponent.DisplayName & ", does not have the attribute: " & attTitle)
End If
Loop

lw.Close()

End Sub

Function SelectTabNoteSection(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a tabular note"
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_tabular_note_type
.Subtype = UFConstants.UF_tabular_note_section_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

Function SelectComponent(ByVal prompt As String, ByRef selObj As TaggedObject) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a component"
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.AnyInAssembly
Dim selectionMask_array(0) As Selection.MaskTriple

With selectionMask_array(0)
.Type = UFConstants.UF_component_type
.Subtype = UFConstants.UF_all_subtype
End With

theUfSession.Ui.SetCursorView(0)

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 AddComponentInfo(ByVal tempComp As Assemblies.Component,
ByVal attributeTitle As String,
ByVal row As Integer,
ByRef tableNote As Annotations.TableSection)

Dim tabularNoteTag As Tag
theUfSession.Tabnot.AskTabularNoteOfSection(tableNote.Tag, tabularNoteTag)

Dim numRows As Integer
theUfSession.Tabnot.AskNmRowsInSection(tableNote.Tag, numRows)

If row > numRows Then
'add code to create new row

'for this example code, we'll just exit the sub
Return
End If

Dim numCols As Integer
theUfSession.Tabnot.AskNmColumns(tabularNoteTag, numCols)

Dim rowTag As Tag
theUfSession.Tabnot.AskNthRowInSection(tableNote.Tag, row, rowTag)

Dim colTag As Tag
theUfSession.Tabnot.AskNthColumn(tabularNoteTag, 0, colTag)

Dim cellTag As Tag
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)

'add component name to first column
theUfSession.Tabnot.SetCellText(cellTag, tempComp.DisplayName)

'get associative text for attribute
Dim associativeText1 As Annotations.AssociativeText
associativeText1 = workPart.Annotations.CreateAssociativeText()

Dim text1 As String
text1 = associativeText1.GetObjectAttributeText(tempComp, attributeTitle)

associativeText1.Dispose()

'add attribute text to column 2
theUfSession.Tabnot.AskNthColumn(tabularNoteTag, 1, colTag)
theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)

theUfSession.Tabnot.SetCellText(cellTag, text1)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

End Function

End Module

Thank you so much for helping, I will try in NX 8 and learn something out of this. You mentioned that the code is written for NX8 that means it wont work in before versions? As I tried in NX7.5 and getting some errors. Anyways I will try in NX8 and will get back to you for help if still there are errors. Thanks a lot.

Thank you,
Sravan

This particular journal will only work in NX 8 or later.

Unfortunately right now NX8 is not available for me at work. Is it a trouble for you to write the code for NX7.5? Sorry.

And i understood we can call all attributes with the same method, is this applicable for calling mass of the part also? Because I dont see any mass attribute directly under object attributes. We generally edit part number attribute to get mass of the part.

Thank you,
Sravan

I was working off the information that you gave on Wed, 05/27/2015 - 10:01

"Yes it is a plain tabular note and not a part list. We are using nx8."

A re-write for NX 7.5 is not a trivial task. I don't think that I'll have time to look at it today.
I'll have to fire up 7.5 and re-familiarize myself on how the mass is handled. Can you give an example of how you currently handle the mass attribute? Do you create it yourself or is it handled automatically?

We generally link object attribute for part now by right click --> text editor---> object attributes under relationships---> select target object--->select DB_PART_NO ---> edit it by replacing DB_PART_NO with $mass in text editor. This will show the mass of the part in the tabular cell.

Thank you,
Sravan

Hello,

Is it possible to get the real string text of

in order to check if the attribute is "".

Thank you and best regards

Robert

real string text of WRef4*0@DF_LIEFERANT

If the annotation contains a reference as above, you can use the .GetEvaluatedText method to see what the annotation evaluates to (the text seen by the user). The function below will take a note object and return the string as seen on the drawing.

Function EvaluateText(ByVal someNote As Annotations.Note) As String

Dim aT As Annotations.AssociativeText = theSession.Parts.Work.Annotations.CreateAssociativeText()
Dim cData As Annotations.ComponentData = theSession.Parts.Work.Annotations.CreateComponentData(someNote)

For Each tC As Annotations.TextComponent In cData.GetTextComponents
Return aT.GetEvaluatedText(someNote, tC.GetText(0))
Next

Return Nothing

End Function

This function was taken from a larger journal on the site:
http://nxjournaling.com/comment/4805#comment-4805

If you are dealing with a tabular note, there is another (similar) method called: .AskEvaluatedCellText