Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal read Attribute from Stock (routing) 1

Status
Not open for further replies.

HagenT

Mechanical
Dec 1, 2015
14
Hy all together,

I´m new with NX Journaling and got a Problem by reading an Attribute from a part.
All the part attributes i can read with my Journal. But there are some attributes assingned to the stock (extrude) in the part.
I tried to read the Material Attribute (string) but it didn´t work.
Can sombody help me?

Code:
Const aTitle As String = "MATERIAL"
 
        Dim aInfo As NXObject.AttributeInformation
        Dim aStrValue As String = "default value"

 
        If workPart.HasUserAttribute(aTitle, NXObject.AttributeType.Any, -1) Then
            'attribute exists, retrieve information
            aInfo = workPart.GetUserAttribute(aTitle, NXObject.AttributeType.Any, -1)
            Select Case aInfo.Type
                Case Is = NXObject.AttributeType.Boolean
                    aStrValue = aInfo.BooleanValue.ToString
                Case Is = NXObject.AttributeType.Integer
                    aStrValue = aInfo.IntegerValue.ToString
                Case Is = NXObject.AttributeType.Real
                    aStrValue = aInfo.RealValue.ToString
                Case Is = NXObject.AttributeType.String
                   aStrValue = aInfo.StringValue

                Case Else
                    'add other cases as necessary
            End Select
				lw.WriteLine(ainfo.Title.tostring & "  -  " & aStrValue)
        Else
            'attribute does not exist
            lw.WriteLine("attribute does not exist, creating it...")
            'create string attribute
            'workPart.SetUserAttribute(aTitle, -1, aStrValue, Update.Option.Now)	
       End If

Thanks for helping me.

I´m using NX 9 with TC 10
 
Replies continue below

Recommended for you

Attributes can be stored against many different types of objects including:
Part
Body (Sheet or solid)
Face
Edge
etc
etc

Your code is only looking at the attributes attached to the part file hence the
workpart.getuserattribute function.

if you wanted to check the attribute of a body you could get all the bodies of the workpart:
Code:
For Each my_body As Body In theSession.Parts.Work.Bodies
aInfo = my_body.GetUserAttribute(aTitle, NXObject.AttributeType.Any, -1)
etc etc


Next

I've not dealt with stock so I'm not sure what type of object you need but if it is an extrude it may be you need to replace
Code:
For Each my_body As Body In theSession.Parts.Work.Bodies
with
Code:
For Each my_feat As Features.feature In theSession.Parts.Work.features
in my little snippet above.


Mark Benson
Aerodynamic Model Designer

To a Designer, the glass was right on CAD.
 
Hy Mark,

thank you a lot.
Seems to be very easy but it´s not so easy to find in net.ref.

I will test this tomorrow in the mornig.

Hagen
 
You will first need to determine where the attribute has been applied. In the case of an extrude, the attribute may be applied to the feature itself or the resulting body. I'm not familiar with the routing application, so I don't know where it applies attributes. You can check by right clicking on the feature/body, choosing properties, and checking the attributes tab.

www.nxjournaling.com
 
Hy Mark and cowski,

thank you very much.

I change my code this morning and it works well.
I know where attributes could be applied. It somethimes not easy using german Version of NX and Journal.
I will switch to english version.

Some attributes of routing mechnical parts are stored in configuration files of NX routing and set to the component by using routing function.

Hagen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor