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!

NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute

Status
Not open for further replies.

jmarkus

Mechanical
Jul 11, 2001
377
Okay, I've read many threads on related topics, but I haven't seen something that addresses the problem I am having.

I have a part attribute, defined as a real number (i.e. with decimals) and I want to display it in a note on a drawing. So I use:
Code:
<W@MVALUE>
and it displays the value as 999.999. That's good!

Now I try to automate some tasks and I assign the value to the attribute in a journal (reference from thread using:
Code:
Dim MVALUE As NXObject.AttributeInformation
MVALUE.Title = "MY_VALUE"
MVALUE.Type = NXObject.AttributeType.Real
MVALUE.RealValue = 999.999
workPart.SetUserAttribute(MVALUE), Update.Option.Now)
Which correctly assigns the value (I verfied by adding a MsgBox to report the value).

Then I revise an existing note on a drawing to change the text from whatever was there before to:
Code:
<W@MVALUE>
using the DraftingNoteBuilder method.

but on my drawing I see 1000. It is as if the real value was converted to an integer value.

What I find even stranger, is now if I manually add a note to the drawing <W@MVALUE>, it still shows 1000, and the old manual note which was assigned to the same part attribute before I ran the journal (which is still <W@MVALUE> in the text) still shows 999.999

So how can the part attribute displayed on the drawing "format itself" differently when the notes are exactly the same...and as far as I know the annotation function has no settings to control decimal places which would explain the difference!?

I even tried manually adding a different part attribute also with a value of 999.999 in the same note, in the same way and side-by-side one shows 999.999 and one shows 1000!

[I know I can use the <X0.2 expression formatting, but this is a part attribute, not an expression and if I were to have to add an expression it would introduce additional complexity to the problem I am trying to address since the part attributes are already assigned in a certain way.]

Stumped as always.

Thanks,
Jeff
 
Replies continue below

Recommended for you

jmarkus said:
Then I revise an existing note on a drawing to change the text from whatever was there before to:
Code:
<W@MVALUE>
using the DraftingNoteBuilder method.

Can you post the relevant portion of your code?

www.nxjournaling.com
 
Sure:

Below the string att="MVALUE", and the mySelectedObject is an existing note that has been selected by the user. I made a mistake in my code above and should have indicated:
Code:
MVALUE.Title = "MVALUE"
since I've been changing some variable names in my post to make it more simple.

The code using DraftingNoteBuilder is:
Code:
Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(mySelectedObject)
draftingNoteBuilder1.Origin.SetInferRelativeToGeometry(True)

Dim text1(0) As String
text1(0) = "<W@" + att + ">"
draftingNoteBuilder1.Text.TextBlock.SetText(text1)

Dim nXObject1 As NXObject
nXObject1 = draftingNoteBuilder1.Commit()

Again, the resulting text in the annotation looks correct (<W@MVALUE>) when I click on edit note on the drawing.

Jeff
 
You have to use CreateAssociativeText function.

Code:
        Dim text1 As String = ""

        Dim associativeText1 As Annotations.AssociativeText
        associativeText1 = workPart.Annotations.CreateAssociativeText()

        text1 = associativeText1.GetObjectAttributeText(theObj, attrTitle)

        associativeText1.Dispose()

Suresh
 
Suresh,

Wouldn't the code you are suggesting extract the attribute from the selected object and assign it to the text1 string?

That doesn't seem to be what I am trying to do here. Could you elaborate more on why you this this would help with my integer vs real number problem?

Thanks,
Jeff
 
I think from NX9 onward, this is the recommended way of setting associative text. Use the string returned from associativetext and use it to set your text. See if it fixes your problem.

Suresh
 
Suresh,

I tried your method, but perhaps I am implementing it wrong. Since I am trying to assign part attributes to the notes, I assumed "theObj" should be my workpart. I even tried to put a MsgBox to show me what was assigned, but nothing popped up:

Code:
Dim associativeText1 As Annotations.AssociativeText
associativeText1 = workPart.Annotations.CreateAssociativeText()
text1(0) = associativeText1.GetObjectAttributeText(workPart, att)
associativeText1.Dispose()
MsgBox(text1(0))

Thanks,
Jeff
 
Jeff,

You should be using GetPartAttributeText..

Below is the code.
Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    '  Explicit Activation
    '      This entry point is used to activate the application explicitly
    Sub Main()

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

        ' TODO: Add your application code here 

        Dim attrTitle As String = "MY_VALUE"

        wp.SetUserAttribute(attrTitle, -1, 99.99, NXOpen.Update.Option.Now)

        Dim draftingNoteBuilder1 As NXOpen.Annotations.DraftingNoteBuilder = wp.Annotations.CreateDraftingNoteBuilder(Nothing)

        Dim assocText(0) As String

        assocText(0) = Get_associative_part_attribute_text(wp, attrTitle)

        Dim originPt As Point3d = New Point3d(50, 50, 0)
        draftingNoteBuilder1.Text.TextBlock.SetText(assocText)
        draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, Nothing, originPt)
        draftingNoteBuilder1.Commit()
        draftingNoteBuilder1.Destroy()


    End Sub


    Function Get_associative_part_attribute_text(ByVal wp As Part, ByVal attrTitle As String) As String


        Dim text1 As String = ""

        Dim associativeText1 As Annotations.AssociativeText
        associativeText1 = wp.Annotations.CreateAssociativeText()

        text1 = associativeText1.GetPartAttributeText(attrTitle)

        associativeText1.Dispose()

        Return text1

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        '----Other unload options-------
        'Unloads the image immediately after execution within NX
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

Suresh
 
Suresh,

Thank you for clarifying about using GetPartAttributeText. Unfortunately that doesn't seem to solve my issue with respect to decimal places (or integer vs real numbers). I guess I need to add some more information which might help, which I discovered by chance:

[ol 1]
[li]When my part attribute is linked to the correct measurement expression before I run the journal, I get the value of expression shown on the drawing to the current system precision (15 significant digits)after I run the journal.[/li]
[li]When my part attribute is assigned a dummy value of 999.999 first and I run the journal, the value shown is 999.999 (3 decimals). If I then (after running the journal) link the part attribute to the measurement expression, the value of the expression updates on the drawing note but is shown as an integer (no decimal places).[/li]
[li]I noticed that if I go into the edit note function and I revise the <WRef1*0@MYVALUE> to <W@MYVALUE> in the text input box in case #1 above, the number of decimal places goes back to zero once I have edited the text, but before I close the dialog box. Once I close the dialog box it reverts to system precision.
Note: this also happens for case #2 if I try to edit before linking to the measurement expression (999.999 changes to 1000)[/li]
[li]If I go into the edit note function and I revise the <WRef1*0@MYVALUE> to <W@MYVALUE> for case #2 after the attribute has been linked it then reverts back to system precision (from zero decimals) after I close the dialog box.[/li]
[/ol]

So, as before I am at a loss to figure out how to control the display of the decimal places consistently for this journal application.

Thanks,
Jeff



 
Hi Jeff,

Looks like there is no way to control the display of decimal place precision of a part attribute. Work around is to create an expression referencing the part attribute and use that expression in your associative text.


Suresh
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor