Well I figured out something that works for this. I found other code that did something similar and I axed my way through it to make it do what I needed. I know it could be a ton cleaner and it would have been preferable if it didn't make it into an expression, but the end results were good enough.
I did not remove the lines I blocked out for the purpose of someone who knows code better might have an easier time seeing what it was meant to do before I butchered it. lol
----------------------------
'Build a new part attribute from existing part attributes.
'When run on a part with string part attributes named "first" and "second", this journal will create a new part attribute ("new") that combines the existing attributes.
'new = TOOL_ID & "-" & second
Option Strict Off
Imports System
Imports NXOpen
Module new_attribute_from_attributes
Dim theSession As Session = Session.GetSession()
Dim lw As ListingWindow = theSession.ListingWindow
' Dim workPart As NXOpen.Part = theSession.Parts.Work
Sub Tool ID Attr()
If IsNothing(theSession.Parts.BaseWork) Then
'active part required
Return
End If
lw.Open()
Const undoMarkName As String = "new attribute"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder = Nothing
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, {theSession.Parts.Work}, NXOpen.AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Category = "VALIANT"
attributePropertiesBuilder1.Title = "NPM"
Dim expression1 As NXOpen.Expression = Nothing
expression1 = theSession.Parts.Work.Expressions.CreateSystemExpression("String", """""")
Dim expression2 As NXOpen.Expression = Nothing
expression2 = theSession.Parts.Work.Expressions.GetAttributeExpression(theSession.Parts.Work, "TOOL_ID", NXOpen.NXObject.AttributeType.String, -1)
Dim expression3 As NXOpen.Expression = Nothing
expression3 = theSession.Parts.Work.Expressions.GetAttributeExpression(theSession.Parts.Work, "second", NXOpen.NXObject.AttributeType.String, -1)
lw.WriteLine("NPM rhs: " & expression2.Name & " + """"")
expression1.RightHandSide = expression2.Name & " + """""
' lw.WriteLine("NPM rhs: " & expression2.Name & " + ""-"" + " & expression3.Name)
' expression1.RightHandSide = expression2.Name & " + ""-"" + " & expression3.Name
attributePropertiesBuilder1.Expression = expression1
' Dim expression4 As NXOpen.Expression = CType(workPart.Expressions.FindObject("p19"), NXOpen.Expression)
' attributePropertiesBuilder1.Expression = expression1
' attributePropertiesBuilder1.IsArray = False
' attributePropertiesBuilder1.IsArray = False
' Dim markId2 As NXOpen.Session.UndoMarkId = Nothing
' markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Break Expression Link")
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = attributePropertiesBuilder1.Commit()
Dim id1 As NXOpen.Session.UndoMarkId = Nothing
id1 = theSession.GetNewestUndoMark(NXOpen.Session.MarkVisibility.Visible)
Dim nErrs1 As Integer = Nothing
nErrs1 = theSession.UpdateManager.DoUpdate(id1)
attributePropertiesBuilder1.Destroy()
lw.Close()
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