Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

FontSize of GeneralNotes on a Drawing

mowag
Enthusiast

FontSize of GeneralNotes on a Drawing

mowag
Enthusiast
Enthusiast

Hi,

 

Apperantly the FonttSize of GeneralNotes affects everything on a drawing ? is this correct?

But the Color only affects the GeneralNote ???

Sheet activesheet = oDrawDoc.ActiveSheet;
GeneralNotes oGeneralNotes = activesheet.DrawingNotes.GeneralNotes;
TransientGeometry oTG = _inventordataService.invApp.TransientGeometry;
                        string sText = "Dikte :";

GeneralNote oGeneralNote1 = oGeneralNotes.AddFitted(oTG.CreatePoint2d(1, 3), sText);

oGeneralNotes[1].TextStyle.FontSize = 1;
oGeneralNotes[1].TextStyle.Bold = true;
oGeneralNotes[1].Color = _inventordataService.invApp.TransientObjects.CreateColor(255, 0, 0);                   

oDrawDoc.Close(true);

 

Screenshot_Drawing.png

0 Likes
Reply
Accepted solutions (1)
510 Views
5 Replies
Replies (5)

JelteDeJong
Mentor
Mentor
Accepted solution

the property

oGeneralNotes[1].TextStyle

is the global drawing style. If you want to change text styles then you should edit the formatted text property. Something like this:

Sheet activesheet = oDrawDoc.ActiveSheet;
GeneralNotes oGeneralNotes = activesheet.DrawingNotes.GeneralNotes;
TransientGeometry oTG = invApp.TransientGeometry;
string sText = "<StyleOverride FontSize='0,5' Bold='True'>Dikte :15</StyleOverride>";

GeneralNote oGeneralNote1 = oGeneralNotes.AddFitted(oTG.CreatePoint2d(1, 3), sText);
oGeneralNote1.FormattedText = sText;
oGeneralNote1.Color = invApp.TransientObjects.CreateColor(255, 0, 0);

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes

mowag
Enthusiast
Enthusiast

Hi Jelte,

 

Thanks for pointing that out to me.

I slightly altered it to be able to show a parameter.

string sText = $"<StyleOverride FontSize='0,7' Bold='True'>Dikte : {Part.Thickness} </StyleOverride>";
0 Likes

mowag
Enthusiast
Enthusiast

 

Hi,

I encounter difficulties to add general notes to a drawing.

 

With this formatted i get an exception  0x80070057 (E_INVALIDARG) on the GeneralNotes.AddFitted method ??

 

i added several general notes sucessfully on other drawings  in my assembly with the same code !! no problems.

In other assembies, one out of ten gives an error ??

 

Screenshot_7.png

 

 

0 Likes

gustavo.cassel
Advocate
Advocate

Hello mowag! I'm currently having the same issue. This line of code works in 90% of his requests. But eventually it will throw an error.

The solution i created is to create a new textstyle on the DrawingDocument.

            GeneralNotes generalNotes = drawingDocument.ActiveSheet.DrawingNotes.GeneralNotes;
            TransientGeometry oTG = ((Inventor.Application)drawingDocument.Parent).TransientGeometry;

            TextStyle oStyle;
            try
            {
                oStyle = drawingDocument.StylesManager.TextStyles["Note Localizador"];
            }
            catch
            {
                oStyle = drawingDocument.StylesManager.TextStyles[1].Copy("Note Localizador") as TextStyle;
            }
            oStyle.Font = "Arial";
            oStyle.FontSize = 0.75f;
            oStyle.Rotation = 0;
            oStyle.Bold = false;
            oStyle.Italic = false;
            oStyle.Underline = false;
            oStyle.LineSpacing = (double)LineSpacingEnum.kSingleLineSpacing;
            oStyle.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextLeft;
            oStyle.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextUpper;
            oStyle.Comments = "Estilo criado para formatar a TextBox Localizador";

            TextStyle oStyle2;
            try
            {
                oStyle2 = drawingDocument.StylesManager.TextStyles["Note Pedido"];
            }
            catch
            {
                oStyle2 = oStyle.Copy("Note Pedido") as TextStyle;
            }
            oStyle2.FontSize = 0.5f;
            oStyle.Comments = "Estilo criado para formatar a TextBox Pedido";

            if (formPrint.Localizador != string.Empty)
            {
                //string TextBoxLocalizador = "<StyleOverride Font='Arial' FontSize='" + Convert.ToString("0,75", CultureInfo.CurrentCulture) + "'>" + formPrint.Localizador + "</StyleOverride>";
                _ = generalNotes.AddFitted(oTG.CreatePoint2d(drawingDocument.ActiveSheet.Width - 9.25, 6.2), formPrint.Localizador, oStyle);
            }
            if (formPrint.Pedido != string.Empty)
            {
                //string TextBoxPedido = "<StyleOverride Font='Arial' FontSize='" + Convert.ToString("0,5", CultureInfo.CurrentCulture) + "'> PED" + formPrint.Pedido + "</StyleOverride>";
                _ = generalNotes.AddFitted(oTG.CreatePoint2d(drawingDocument.ActiveSheet.Width - 4.25, 6.05), "PED" + formPrint.Pedido, oStyle2);
            }

 In my case, i won't save the document when the code is running, it's only to print a custom textbox on the activesheet. But i put a try and catch statement to create the textstyle if not exists.

If not exists, copy the first one (can be any) and make sure to format all the styles, to not bring together wrong styles from the one you copy.

mowag
Enthusiast
Enthusiast

Hi Gustavo,

 

I've solved it by explicitly adding a .ToString()  on the Part.Thickness (who is a double).

But thanks for the exemple to create a new textStyle on a DrawingDocument, i'll keep it in my 'Resource Folder' !!

 

Screenshot_101.png