Hy all,
I've to create a journal that fill's up all loaded Parts in the Session with a couple of expressions and attributes.
If I do this without a journal, I've to create the attribute, in the next step the expression and at least I’ve to connect the attribute with the command “reference part attribute” that can be found in the expressions editor.
I’ve recorded these steps with the journal recorder so you can see that NX creates for the connection to the attribute a String like “p1”. The problem is that this String changes from part to part so it can be “p1; p260” or any other integer behind the “p”.
So my question is how can I call the attribute while setting the formula of the expression without the changing “px” value?
i.e.
AWEBA_Positionsnummer_expression = part1.Expressions.CreateExpression("String", AWEBA_Positionsnummer_Value & "=" & "p1")
AWEBA_Positionsnummer_expression = part1.Expressions.CreateExpression("String", AWEBA_Positionsnummer_Value & "=" & %here I need the attribute connection%)
Thanks for your help
Best regards
'Part - Attribute
Dim objects1(0) As NXObject
objects1(0) = part1
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder = theSession.AttributeManager.CreateAttributePropertiesBuilder(part1, objects1, AttributePropertiesBuilder.OperationType.None)
Dim changed1 As Boolean
''AWEBA_Startpartversion
'**********
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Category = "BM_BoM"
attributePropertiesBuilder1.Title = "item_number"
attributePropertiesBuilder1.StringValue = "xx_xx_xxx"
changed1 = attributePropertiesBuilder1.CreateAttribute()
attributePropertiesBuilder1.Destroy
'**********
'Part - Expressions
''AWEBA_Positionsnummer
'**********
Dim AWEBA_Positionsnummer_Value As String = "AWEBA_Positionsnummer"
Dim AWEBA_Positionsnummer_expression As Expression
Try
'Versuch - Schreibe Expression
AWEBA_Positionsnummer_expression = part1.Expressions.CreateExpression("String", AWEBA_Positionsnummer_Value & "=" & "p1")
AWEBA_Positionsnummer_expression.IsNoEdit = True
Catch
'Versuch - Verändere Wert der Expression
AWEBA_Positionsnummer_expression = CType(part1.Expressions.FindObject(AWEBA_Positionsnummer_Value), Expression)
AWEBA_Positionsnummer_expression.IsNoEdit = False
part1.Expressions.EditWithUnits(AWEBA_Positionsnummer_expression, NullUnit, "p1")
AWEBA_Positionsnummer_expression.IsNoEdit = True
End Try
re: create expression that references part attribute
What version of NX are you using? The code below assumes NX 9, other versions will probably be similar.
The code below will create a part attribute named "test" then it will create an expression that references the part attribute value.
'NXJournaling.com
'April 2, 2015
'Journal to create a part attribute (type: string) then create an expression
'(type: string) that references the part attribute value.
Option Strict Off
Imports System
Imports NXOpen
Module find_attribute_expression
Sub Main()
Dim theSession As Session = Session.GetSession()
Dim theUISession As UI = UI.GetUI
If IsNothing(theSession.Parts.Work) Then
'active part required
Return
End If
Dim workPart As Part = theSession.Parts.Work
Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Const attrTitle As String = "test"
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Part attribute")
Dim objects1(0) As NXObject
objects1(0) = workPart
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.IsArray = False
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String
attributePropertiesBuilder1.Title = attrTitle
attributePropertiesBuilder1.StringValue = "test value"
Dim nXObject1 As NXObject
nXObject1 = attributePropertiesBuilder1.Commit()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
attributePropertiesBuilder1.Destroy()
'find part attribute expression
Dim attrExp As Expression = Nothing
attrExp = workPart.Expressions.GetAttributeExpression(workPart, attrTitle, NXObject.AttributeType.String, -1)
'create new expression referencing the part attribute expression
Dim newExp As Expression
newExp = workPart.Expressions.CreateExpression("String", "myexp = " & attrExp.Name)
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