NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
(OP)
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:
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 http://www.eng-tips.com/viewthread.cfm?qid=420924) using:
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:
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
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>
Now I try to automate some tasks and I assign the value to the attribute in a journal (reference from thread http://www.eng-tips.com/viewthread.cfm?qid=420924) 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)
Then I revise an existing note on a drawing to change the text from whatever was there before to:
CODE
<W@MVALUE>
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





RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
Can you post the relevant portion of your code?
www.nxjournaling.com
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
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
The code using DraftingNoteBuilder is:
CODE
Again, the resulting text in the annotation looks correct (<W@MVALUE>) when I click on edit note on the drawing.
Jeff
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
CODE --> VB
Dim text1 As String = "" Dim associativeText1 As Annotations.AssociativeText associativeText1 = workPart.Annotations.CreateAssociativeText() text1 = associativeText1.GetObjectAttributeText(theObj, attrTitle) associativeText1.Dispose()Suresh
www.technisites.com.au
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
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
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
Suresh
www.technisites.com.au
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
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
Thanks,
Jeff
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
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 ModuleSuresh
www.technisites.com.au
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
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:
- 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.
- 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).
- 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.
- 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.
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.Note: this also happens for case #2 if I try to edit before linking to the measurement expression (999.999 changes to 1000)
Thanks,
Jeff
RE: NX9 Drafting Annoations - Part Attributes & Journal Using SetUserAttribute
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
www.technisites.com.au