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

Issues with FormattedText

Hello all,

 

I wanted to remove style overrides from our titleblock. As there are many, many textboxes, I wanted to do this in an automated way.

There seems to be an issue with writing to FormattedText property.

 

The code is like

 Inventor.Application invApp;
            invApp = (Inventor.Application)System.Activator.CreateInstance(System.Type.GetTypeFromProgID("Inventor.Application"));
            
            DrawingDocument drawDoc = (DrawingDocument)invApp.Documents.Open(@"Z:\_pdm\flg\Administration\Inventor\2014\Templates\Drawing_DE_EN.dwg");

            TitleBlock tBlock = drawDoc.ActiveSheet.TitleBlock;

            DrawingSketch sketch = tBlock.Definition.Sketch;

            TextBoxes tboxes = sketch.TextBoxes;

            foreach(TextBox tbox in tboxes)
            {
                
                tbox.Style = drawDoc.StylesManager.TextStyles["Iso"];

                String text = tbox.FormattedText;
                tbox.FormattedText=tbox.FormattedText.Replace("ISOCPEUR", "ISOCP");
                

            }

            drawDoc.SaveAsInventorDWG(@"c:\temp\test.dwg",true);

even if I say

tbox.FormattedText = tbox.FormattedText 

without changing anything, this still causes an exception.

 

Best regards

Erik

Anonymous
in reply to: gilsdorf_e

Try

 

String text = tbox.FormattedText;
tbox.FormattedText=text.Replace("ISOCPEUR", "ISOCP");

Or even:

 

String text = tbox.Text;
tbox.Text=text.Replace("ISOCPEUR", "ISOCP");

That's what I would try... 

gilsdorf_e
in reply to: Anonymous

Hello,

 

that has been my first try. Somewhere on the internet it says there might be problems with custom iProperties.

 

tbox.Text cannot be used in my opinion, as I do not want to change the text but the formatting.

 

Best regards

Erik

 

gilsdorf_e
in reply to: gilsdorf_e

Solved it.

 

I forgot to enter edit mode for the titleblock sketch

 

tBlock.Definition.Edit(out sketch);

 

That did the trick.

 

Best regards

Erik

Hi Erik,

I had the same problem some time ago, I tried to change the formatted text with the "Replace" function and something went wrong.

 

Then I've tried the following solution and it started working properly

http://forums.autodesk.com/t5/inventor-customization/changing-text-in-description-column-of-a-holeta...

 

 

Bregs

Rossano Praderi



--------------------------------------
If my post answers your question, please click the "Accept as Solution"
button. This helps everyone find answers more quickly!
---------------