Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Attributing: How to pass solid attributes to component attributes 1

Status
Not open for further replies.

electracomplex

Automotive
Jan 17, 2014
42
0
0
US
Hi Y'all,

I found some great information in an old thread here but not exactly what I'm looking to do.

I have a journal that assigns solid attributes but it does not pass them to component attributes so that Parts List can use them.

In other words, if I info>type>solidbody I can see all of the attributes my journal creates in the information window but if I RMB>Properties>Attributes they are not listed under Component Attributes.

Any help here will be most appreciated,

~Felicia H.
NX 12.0.1.7

"Design all things as simple as possible but not simpler."
 
Replies continue below

Recommended for you

Would it make sense to add these attributes to the part itself instead of the individual body in your case?
Part attributes are automatically inherited as component attributes when the part is added to an assembly; body attributes... are not.

www.nxjournaling.com
 
AS cowski says,
if you set the attribute on the part, it will be a component attribute, which is the type that the NX parts lists reads.
- Is there a specific reason you assign the attribute to the solid body ?
( If there is, you can probably create a journal that aids in "moving/ copying" the attribute.)

Regards,
Tomas

 
Hi Cowski,

I honestly don't know how to add the attributes to the part instead of the body. I found a journal (maybe it was from you actually) that adds the attributes and that's what I'm using.

I have very little ability to code for NX so I wouldn't know how to change it :(

~Felicia H.
NX 12.0.1.7

"Design all things as simple as possible but not simpler."
 
Hi Toost,

toost said:
Is there a specific reason you assign the attribute to the solid body ?

That's what the journal I found online does is the short answer.

toost said:
If there is, you can probably create a journal that aids in "moving/ copying" the attribute.)

Exactly what I'm trying to do. I'm guessing it's not very difficult from someone with much better coding skills that I have. Mine are basically non-existent.

I've attached the journal I found and had modified to use NX block styler for the dialog box.

~Felicia H.
NX 12.0.1.7

"Design all things as simple as possible but not simpler."
 
I wonder if it could be as simple as changing NXObject type to 'part' instead of 'body'?

~Felicia H.
NX 12.0.1.7

"Design all things as simple as possible but not simpler."
 
The code currently looks at the bodies in a file deleting certain attributes and adding new ones. If you only want to add/update attributes, you don't need to delete existing attributes. I think some of the code came from a journal where someone wanted to update attribute titles; an easy way to do that is to delete the old one and add a new one.

If you want to add the attributes to the part file, target the part file rather than the bodies. There might be some other changes necessary, but that is the main one.

www.nxjournaling.com
 
Cowski,

I'm trying to find out how to target the part rather than the bodies but it's beyond my coding ability. Would you be able to point me in the right direction? My Google Fu hasn't been enough to find this yet.

~Felicia H.
NX 12.0.1.7

"Design all things as simple as possible but not simpler."
 
The journal recorder is a great way to generate some sample code for an operation that you are interested in. Unfortunately, it often records somewhat related stuff that you are not interested in. The result is often working code hidden among a bunch of weeds. I recorded the operation of adding a part attribute and cleaned up the code, the result is below:

Code:
Option Strict Off
Imports System
Imports NXOpen

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

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

Dim displayPart As NXOpen.Part = theSession.Parts.Display

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

[highlight #FCE94F]Dim objects1(0) As NXOpen.NXObject
objects1(0) = workPart[/highlight]
Dim attributePropertiesBuilder1 As NXOpen.AttributePropertiesBuilder
attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(workPart, [highlight #FCE94F]objects1[/highlight], NXOpen.AttributePropertiesBuilder.OperationType.None)

attributePropertiesBuilder1.IsArray = False

attributePropertiesBuilder1.DataType = NXOpen.AttributePropertiesBaseBuilder.DataTypeOptions.String

theSession.SetUndoMarkName(markId1, "Displayed Part Properties Dialog")

attributePropertiesBuilder1.Title = "test"

attributePropertiesBuilder1.StringValue = "a value"

Dim nXObject1 As NXOpen.NXObject
nXObject1 = attributePropertiesBuilder1.Commit()

Dim id1 As NXOpen.Session.UndoMarkId
id1 = theSession.GetNewestUndoMark(NXOpen.Session.MarkVisibility.Visible)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(id1)

theSession.SetUndoMarkName(id1, "Displayed Part Properties")

attributePropertiesBuilder1.Destroy()

End Sub
End Module

The attributePropertiesBuilder object does all the work. The first parameter passed to the builder is the part that is going to own the builder object, the second parameter is an array of objects that will have the attribute applied. In the case of the journal recorder, it creates a new array and assigns the work part as the only object in the array (shown highlighted in yellow).

In your case, the AddBodyAttribute subroutine could be rewritten like this (assuming you want to add the attribute to the current work part):

Code:
Public Sub AddPartAttribute(ByVal attTitle As String, ByVal attValue As String)
    Dim markId4 As Session.UndoMarkId
    markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "add part attribute")

    Dim attributePropertiesBuilder1 As AttributePropertiesBuilder
    attributePropertiesBuilder1 = theSession.AttributeManager.CreateAttributePropertiesBuilder(theSession.Parts.Work, {theSession.Parts.Work}, AttributePropertiesBuilder.OperationType.None)

    attributePropertiesBuilder1.IsArray = False
    attributePropertiesBuilder1.DataType = AttributePropertiesBaseBuilder.DataTypeOptions.String

    attributePropertiesBuilder1.Title = attTitle
    attributePropertiesBuilder1.StringValue = attValue

    Dim nXObject1 As NXObject
    nXObject1 = attributePropertiesBuilder1.Commit()

    Dim id1 As Session.UndoMarkId
    id1 = theSession.GetNewestUndoMark(Session.MarkVisibility.Visible)

    Dim nErrs1 As Integer
    nErrs1 = theSession.UpdateManager.DoUpdate(id1)

    attributePropertiesBuilder1.Destroy()
End Sub

You might notice that we passed in the work part wrapped in curly braces. This is a feature of the .net framework, it tells the compiler to treat the variable as an array. This satisfies the attribute properties builder object, which demands an array of objects be passed in; while also simplifying the code we need to write and maintain.

Hope this helps.

www.nxjournaling.com
 
Cowski,

Thanks so much. What this makes clear to me is I'm out of my depth and should probably let a real programmer handle it, especially since I want it to work from the assembly level and to also "blank" each detail after it's been attributed.

But thank you again very much!

~Felicia H.
NX 12.0.1.7

"Design all things as simple as possible but not simpler."
 
Status
Not open for further replies.
Back
Top