MText Style

MText Style

Anonymous
Not applicable
9,079 Views
10 Replies
Message 1 of 11

MText Style

Anonymous
Not applicable
Can anyone please tell me how to change the MText style to Romans in vb.net. At present the text style is Standard. Thank you
0 Likes
Accepted solutions (1)
9,080 Views
10 Replies
Replies (10)
Message 2 of 11

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

create a MTEXT-object, set whatever you want to individually re-format, then open your property-windows, click the MTEXT-object to get selected and then look to the content of the text within the property-window ==> there you see the special-codes for formatting. That is what you have to set.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 11

Anonymous
Not applicable
Sorry i am new to vb.net and autocad, can you please explain me again. I need to create a MTEXT object in autocad and change the properties manually? THank you
0 Likes
Message 4 of 11

Alfred.NESWADBA
Consultant
Consultant
Accepted solution

Hi,

 

I understood your question in the way you want to change parts of a text within MTEXT to another font, .... or globally change any formating for parts of your text.

The way AutoCAD does modifying e.g. that the 3rd char within the text to be Arial-Black is to put control-characters within the text. And that is what you have to do: take the text-context in your vb-app, place the control characters into the text and save it back.

So you can learn the special chars AutoCAD uses within a MTEXT you can create a MTEXT-object by just drawing it, modify it in the way you like and look into the property-window how the special-formatting is saved.

 

 

Hope that was more clear now (and I understood your question correctly).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 11

Anonymous
Not applicable
Thanks for the clear explanation, but i am creating some Mtext objects in autocad from vb.net and while creating those those MText objects i need to change the Style to Romans (Entire text in MText object).
0 Likes
Message 6 of 11

Anonymous
Not applicable
Sorry, now i gave that special code, style is getting changed. I gave the below code, mytext.Contents = "{\Fromans|C0;" & txt & "}". Thank you
0 Likes
Message 7 of 11

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

that is the minimum-code to set one textstyle to the whole MTEXT-object.

Dim tMTextObj As DatabaseServices.MText = New DatabaseServices.MText()
tMTextObj.TextStyleId = myTextStyleObjectID

And what you need for that to come to:

>> change the Style to Romans

You first have either to define a textstyle that is called "Romans" or at least have the font "Romans" assigned to it ... or you have to seek through the list of textstyles within you current drawing, it a style is defined in the way you want and take this ObjectID to assign this to the MTEXT.TextStyleID-property

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 8 of 11

SENL1362
Advisor
Advisor

 

Can't speak VB anymore, but maybe this C# sample may help you

 

            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;

            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                BlockTableRecord ms = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                TextStyleTable ts = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
                ObjectId mtStyleid = db.Textstyle;
                if (ts.Has("Romans"))
                {
                    mtStyleid = ts["Romans"];
                }
                MText mt = new MText();
                mt.SetDatabaseDefaults();
                mt.Location = new Point3d(100, 150, 0);
                mt.TextStyleId = mtStyleid;
                mt.TextHeight = 2.5;
                mt.Rotation = 30 * Math.PI / 180.0;
                mt.Contents = "Hello World!";
                mt.Width = 0;

                ms.AppendEntity(mt);
                tr.AddNewlyCreatedDBObject(mt, true);
                tr.Commit();
            }
        }

0 Likes
Message 9 of 11

Anonymous
Not applicable
Hi alfred and SENL, I am using Autocad 2007, if i use textstyleid property , it is showing an error like Method is invalid. If i run the dll in 2010, it is not showing any error but Romans Font is not there. My dll should run in both 2007 and 2010 versions and how to change the textstyleid? I have downloaded ObjectARX for AutoCAD 2010 (32-bit and 64-bit): and used those dll as reference in project.
0 Likes
Message 10 of 11

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

out of reasons I don't know between 2007- and 2010-API the propertyname for modifying the TextStyle-ObjectID changed.

  • In 2007-API it's called .TextStyle (also valid before 2007 up to 2009)
  • in 2010-API it's called .TextStyleID (valid beginning with 2010 up to now)

 

Said that you have to check what AutoCAD-version call's your code, either by doing this with flags like #IF (conditional compiling, see also >>>here<<<) or you have different projects for 2007 and 2010.

I prefere different projects and codeparts (most code is in same source-files, the version-specific code is placed in small source files that handles issues like this where signatures changed dependign on version) ... the additional advantage is that you have different Windows Frameworks for 2007 (version 2) and 2010 (Framework 3.5 if I'm right now), imho it's more stable to have the DLL compiled with the correct Framework.

 

Good luck, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 11 of 11

Anonymous
Not applicable
Sorry as i am new to Autocad and .net, i am having so many doubts. I am writing my code in Microsoft visual studio 2008 (framework 3.5). But i need to use the dll in Autocad 2007 and 2010 also. Can you explain me now how should i proceed?
0 Likes