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

Issues with FormattedText

gilsdorf_e
Collaborator

Issues with FormattedText

gilsdorf_e
Collaborator
Collaborator

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

0 Likes
Reply
Accepted solutions (1)
567 Views
4 Replies
Replies (4)

Anonymous
Not applicable

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... 

0 Likes

gilsdorf_e
Collaborator
Collaborator

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

 

0 Likes

gilsdorf_e
Collaborator
Collaborator
Accepted solution

Solved it.

 

I forgot to enter edit mode for the titleblock sketch

 

tBlock.Definition.Edit(out sketch);

 

That did the trick.

 

Best regards

Erik

rossano_praderi
Collaborator
Collaborator

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!
---------------
0 Likes