×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

VB.NET To create part attributes

VB.NET To create part attributes

VB.NET To create part attributes

(OP)
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

RE: VB.NET To create part attributes

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 --> vb.net

'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 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members! Already a Member? Login


Resources

White Paper - Implementing a Multi-Domain System
IoT systems are multi-domain designs that often require AMS, Digital, RF, photonics and MEMS elements within the system. Tanner EDA provides an integrated, top-down design flow for IoT design that supports all these design domains. Learn more about key solutions that the Tanner design flow offers for successful IoT system design and verification. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close