Error when adding note with ComponentIdentifier to drawing via API

Error when adding note with ComponentIdentifier to drawing via API

batuhanozmen98
Enthusiast Enthusiast
227 Views
5 Replies
Message 1 of 6

Error when adding note with ComponentIdentifier to drawing via API

batuhanozmen98
Enthusiast
Enthusiast

Im getting error while adding general note to the drawing.

 

DrawingNotes drawingNotes = oSheet.DrawingNotes;
GeneralNotes generalNotes = drawingNotes.GeneralNotes;
string formattedTextString = "<StyleOverride FontSize='0,4'><Parameter Resolved='True' ComponentIdentifier='"+oPartDoc.FullFileName+"' Name='Thickness' Precision='2'></Parameter></StyleOverride>";
generalNotes.AddFitted(app.TransientGeometry.CreatePoint2d(5, 3), formattedTextString);

 

batuhanozmen98_0-1788439577060.png

 

 

I created the text and parameter manually in a drawing and with a debug session I find this exact string at formatted text.

"<StyleOverride FontSize='0,4'><Parameter Resolved='True' ComponentIdentifier='C:\\Users\\...\\Workspace\\sdabfgngfgn.ipt' Name='Thickness' Precision='2'>3,00</Parameter></StyleOverride>"

I am not sure where is the problem.

I Also tried:

"<StyleOverride FontSize='0,4'><Parameter Resolved='False' ComponentIdentifier='"+oPartDoc.FullFileName+"' Name='Thickness' Precision='2'>1,50</Parameter></StyleOverride>"

and

"<StyleOverride FontSize='0,4'><Parameter Resolved='False' ComponentIdentifier='"+oPartDoc.FullFileName+"' Name='Thickness' Precision='2'></Parameter></StyleOverride>"

and

"<StyleOverride FontSize='0,4'><Parameter Resolved='True' ComponentIdentifier='"+oPartDoc.FullFileName+"' Name='Thickness' Precision='2'>1,50</Parameter></StyleOverride>"

and also tried just occurrence name for the component identifier but none of them worked.

 

and just to be safe I tried code at the below with and It worked.

"<StyleOverride FontSize='0,25'> <Property Document='drawing' PropertySet='Inventor Summary Information' Property='Author' FormatID='' PropertyID=''>AUTHOR</Property> </StyleOverride>"

the drawing is opened in background with false statement(DrawingDocument drawingdoc = (DrawingDocument)app.Documents.Open(oDrawingName, false);)

and the error is "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" happening at generalNotes.AddFitted method

Inventor vers.2021 and API netframework 4.7.2

0 Likes
Accepted solutions (1)
228 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @batuhanozmen98.  If you try the same code while the target drawing is visible, and the true active document, does it work then?  I suspect that placement of notes into drawings requires the target drawing to not only be visible, but the target Sheet object to also be that drawing's active Sheet.  Selection is the same way...only possible within Inventor's active document, not within invisible background documents.  Interaction with the model browser tree is similar, because we can 'read' it from a background document, but can not modify it in a background document.  I am not sure about the proper use of the 'Resolved' spec of Parameters within FormattedText though.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

batuhanozmen98
Enthusiast
Enthusiast

Hi @WCrihfield Thanks for the reply. I tried with visible document and drawing but unfortunately get the same error. Also tried to give Thickness parameter export and key options but did not work. 

0 Likes
Message 4 of 6

Ivan_Sinicyn
Collaborator
Collaborator
Accepted solution

Hi,

DrawingNotes drawingNotes = oSheet.DrawingNotes;
GeneralNotes generalNotes = drawingNotes.GeneralNotes;
string formattedTextString = "<StyleOverride FontSize='0,4'><Parameter Resolved='True' ComponentIdentifier='"+oPartDoc.FullFileName+"' Name='Thickness' Precision='2'></Parameter></StyleOverride>";
// the <Parameter> tag is rejected by AddFitted's FormattedText argument (E_INVALIDARG);
// create the note with a plain placeholder and assign the markup afterwards
GeneralNote generalNote = generalNotes.AddFitted(app.TransientGeometry.CreatePoint2d(5, 3), " ", Type.Missing);
generalNote.FormattedText = formattedTextString;
INV 2026.4
Message 5 of 6

josebaqueror
Advocate
Advocate
The error is almost certainly the ComponentIdentifier value. You're passing oPartDoc.FullFileName, but ComponentIdentifier isn't the file name or path, it's an internal reference token that ties the note to how the drawing view references that model. A file path there won't resolve, so the formatted-text parse or the parameter lookup fails. Two ways forward: 1. Simplest and robust: resolve the parameter value in code and drop it in as literal text. Read the Thickness parameter from the model (oPartDoc.ComponentDefinition.Parameters), get its value, and build the note string with that value. You lose the live link, but it never errors and it's a couple of lines. 2. If you need a live parameter link that updates with the model, get the correct ComponentIdentifier from the drawing's reference to that model rather than FullFileName. The note has to bind to the referenced document the view already points at, not to an arbitrary path. What's the exact error text on the Add call? If it's a parse error it's the formatted string; if it's on resolving the parameter it's the identifier. That says which of the two you're hitting.
Jose Luis Baquero Rivera
Mechanical Engineer
Open to projects, feel free to contact me
josebaqueror.com
https://www.linkedin.com/in/joseluisbaquerorivera/
Message 6 of 6

batuhanozmen98
Enthusiast
Enthusiast

Hi, @Ivan_Sinicyn It worked ! Thank you for the solution and also the explanation.