Hi.
I would like to do this for mtext:
try { MText mt = new MText(); mt.TextStyleName="ARIAL"; } catch{}
But "TextStyleName" is only for read.
I can use "TextStyleId", so...How can I get the ObjectIdCollection of TextStyle and check which of them is "ARIAL"?
Thanks.
Solved! Go to Solution.
Solved by SENL1362. Go to Solution.
This is to create a new textstyle and make it current:
http://adndevblog.typepad.com/autocad/2012/06/creating-a-text-style-using-vbnet.html
But I want to check if there is a textstyle called "ARIAL" and create mtext with this textsytle.
[CommandMethod("TestTextStyle")] static public void TestTextStyle() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; string textStyleName = "Standard"; try { using (Transaction tr = db.TransactionManager.StartTransaction()) { ed.WriteMessage("\n Default Textsize=={0}", db.Textsize); TextStyleTable textStyleTable = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead); if (!textStyleTable.Has(textStyleName)) throw new System.Exception(string.Format("Error: TextStyle not found: {0}", textStyleName)); ObjectId textStyleId = textStyleTable[textStyleName]; TextStyleTableRecord textStyle = (TextStyleTableRecord)tr.GetObject(textStyleId, OpenMode.ForRead); ed.WriteMessage("\n {0} Size=={1}", textStyleName, textStyle.TextSize); tr.Commit(); } } catch (System.Exception ex) { ed.WriteMessage(ex.Message); } }
Thanks a lot!
It´s just that.
MText mt = new MText(); TextStyleTable TextStyleTable = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead); try { ObjectId textStyleId = TextStyleTable["ARIAL"]; mt.TextStyleId = textStyleId; } catch { } mt.Contents = Contenido; mt.Layer = NombreCapa;