Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations MintJulep on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB.NET To create part attributes

Status
Not open for further replies.

NXJockey

Automotive
Feb 9, 2009
104
I need to create a lot of part attributes. I am trying to use 'setattribute' within a journal to create the variable and the value, but can't seem to set the category. Is it possible with 'setattribute' or should I use something else?

I would like to separate the attributes into logical groups 'Design, Manufacture, Inspection' ect

Thanks in advance,

NX Jockey
 
Replies continue below

Recommended for you

I did what you are looking for with the “attributePropertiesBuilder” function. I am very new at programing, so there is probably a better way to do this. The sample code below takes the DB_Part_Name and brakes it down into separate attributes.


Code:
'Created By Jeremy Shooks
'Create attributes from DB_part_name
'6-23-2017

Option Strict Off
Imports System
Imports NXOpen
Imports System.Collections.Generic  
Imports System.Windows.Forms

Imports NXOpenUI

Module NXJournal
Sub Main (ByVal args() As String) 

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

' ----------------------------------------------
'   Menu: Tools->Expressions...
' ----------------------------------------------
theSession.Preferences.Modeling.UpdatePending = False

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Expression")

Dim expressionDBPartName As Expression
expressionDBPartName = workPart.Expressions.CreateExpression("String", "TCeName=ug_askPartAttrValue(""DB_part_name"")")


Dim expressionTCeName As Expression
expressionTCeName = workPart.Expressions.CreateExpression("List", "TCeNameList=splitstring(TCeName, ""-"")")

Dim expressionLength As Expression
expressionLength = workPart.Expressions.CreateExpression("Integer", "TCeNameListLength=length(TCeNameList)")

Dim expressionMMProjectNumber As Expression
expressionMMProjectNumber = workPart.Expressions.CreateExpression("String", "MM_ProjectNumber=nth(1, TCeNameList)")

Dim expressionMMPartNumber As Expression
expressionMMPartNumber = workPart.Expressions.CreateExpression("String", "MM_partNumber=nth(2, TCeNameList)")

Dim expressionMMName As Expression
expressionMMName = workPart.Expressions.CreateExpression("String", "MM_NAME=nth(3, TCeNameList)")

Dim expressionMMHand As Expression
expressionMMHand = workPart.Expressions.CreateExpression("String", "MM_Hand=nth(4, TCeNameList)")

Dim expressionMMType As Expression
expressionMMType = workPart.Expressions.CreateExpression("String", "MM_Type =nth(5, TCeNameList)")

' ----------------------------------------------
'   Expressions to attribute link
' ----------------------------------------------
Dim objects1(0) As NXObject
objects1(0) = workPart
Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, objects1, AttributePropertiesBuilder.OperationType.None)
attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String


Dim objectsEXP(0) As NXObject
objectsEXP(0) = workPart
attributePropertiesBuilder1.SetAttributeObjects(objectsEXP)

Dim changed1 As Boolean
'------------MM_Hand-------

attributePropertiesBuilder1.Category = "MM"

attributePropertiesBuilder1.Title = "MM_Hand"

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsReferenceType = False

attributePropertiesBuilder1.Expression = expressionMMHand

changed1 = attributePropertiesBuilder1.CreateAttribute()

'------------MM_Type-------

attributePropertiesBuilder1.Category = "MM"

attributePropertiesBuilder1.Title = "MM_Type"

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsReferenceType = False

attributePropertiesBuilder1.Expression = expressionMMType

changed1 = attributePropertiesBuilder1.CreateAttribute()

'------------MM_Name-------
attributePropertiesBuilder1.Category = "MM"

attributePropertiesBuilder1.Title = "MM_PART_DESCRIPTION"

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsReferenceType = False

attributePropertiesBuilder1.Expression = expressionMMName

changed1 = attributePropertiesBuilder1.CreateAttribute()

'------------MM_PartNumber-------

attributePropertiesBuilder1.Category = "MM"

attributePropertiesBuilder1.Title = "MM_Part_Number"

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsReferenceType = False

attributePropertiesBuilder1.Expression = expressionMMPartNumber

changed1 = attributePropertiesBuilder1.CreateAttribute()

'------------MM_ProjectNumber------

attributePropertiesBuilder1.Category = "MM"

attributePropertiesBuilder1.Title = "MM_Project_Number"

attributePropertiesBuilder1.StringValue = ""

attributePropertiesBuilder1.IsReferenceType = False

attributePropertiesBuilder1.Expression = expressionMMProjectNumber

changed1 = attributePropertiesBuilder1.CreateAttribute()






End Sub
End Module



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor