.NET

Reply
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 1 of 11 (1,422 Views)
Accepted Solution

MText Style

1422 Views, 10 Replies
11-17-2011 03:29 AM
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

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 -

*Expert Elite*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 2 of 11 (1,419 Views)

Re: MText Style

11-17-2011 03:57 AM in reply to: muthineni

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 3 of 11 (1,418 Views)

Re: MText Style

11-17-2011 04:08 AM in reply to: Alfred.NESWADBA
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
*Expert Elite*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 4 of 11 (1,408 Views)

Re: MText Style

11-17-2011 04:19 AM in reply to: muthineni

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 5 of 11 (1,407 Views)

Re: MText Style

11-17-2011 04:24 AM in reply to: Alfred.NESWADBA
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).
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 6 of 11 (1,402 Views)

Re: MText Style

11-17-2011 04:34 AM in reply to: muthineni
Sorry, now i gave that special code, style is getting changed. I gave the below code, mytext.Contents = "{\Fromans|C0;" & txt & "}". Thank you
*Expert Elite*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 7 of 11 (1,400 Views)

Re: MText Style

11-17-2011 04:37 AM in reply to: muthineni

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Mentor
SENL1362
Posts: 174
Registered: ‎07-20-2011
Message 8 of 11 (1,399 Views)

Re: MText Style

11-17-2011 04:42 AM in reply to: muthineni

 

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();
            }
        }

Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 9 of 11 (1,375 Views)

Re: MText Style

11-17-2011 08:19 PM in reply to: SENL1362
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.
*Expert Elite*
Alfred.NESWADBA
Posts: 9,071
Registered: ‎06-29-2007
Message 10 of 11 (1,370 Views)

Re: MText Style

11-17-2011 09:12 PM in reply to: muthineni

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
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.