.NET

.NET

Reply
Contributor
waterharbin
Posts: 14
Registered: ‎07-17-2011
Message 1 of 5 (260 Views)

How to new a TextStyle? And then set it current?

260 Views, 4 Replies
07-30-2011 04:22 AM

Hello.I want to set a TestStyle,so I can control the fontsize,fontname,etc.Is there anyone who have done that before,Can your code be shared with us? Thank you.

Valued Mentor
cadMeUp
Posts: 331
Registered: ‎05-11-2006
Message 2 of 5 (257 Views)

Re: How to new a TextStyle? And then set it current?

07-30-2011 08:00 AM in reply to: waterharbin

Here is one way you can go about it:

 

Document curDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = curDoc.Database;
Editor ed = curDoc.Editor;

TextStyleTableRecord txtStyle = new TextStyleTableRecord();
txtStyle.Name = "My Style";
txtStyle.Font = new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("Symbol", false, false, 0, 0);
txtStyle.Annotative = AnnotativeStates.True;
txtStyle.TextSize = 0.125;

using (Transaction trans = db.TransactionManager.StartTransaction())
{
 TextStyleTable tab = (TextStyleTable)db.TextStyleTableId.GetObject(OpenMode.ForWrite);
 tab.Add(txtStyle);
 trans.AddNewlyCreatedDBObject(txtStyle, true);
 db.Textstyle = txtStyle.Id;
 trans.Commit();
}

Active Contributor
ZK_BUDiKOM
Posts: 30
Registered: ‎09-13-2012
Message 3 of 5 (180 Views)

Re: How to new a TextStyle? And then set it current?

12-19-2012 04:56 AM in reply to: cadMeUp

Hi,

 

how can I show what is the current TextStyle ??

 

this show me my style, but I know what is this name:

textStyleId = textStyleTable["MyTextStyle"];
TextStyleTableRecord style = tr.GetObject(textStyleId, OpenMode.ForRead) as TextStyleTableRecord;
string sTx = style.Name;

ed.WrittenMessage("\nCurrent Text Style: {0}", sTx);

 

but If I don't??

textStyleId = textStyleTable[??];  // - I want to know name current TextStyle
TextStyleTableRecord style = tr.GetObject(textStyleId, OpenMode.ForRead) as TextStyleTableRecord;
string sTx = style.Name;
 
ed.WrittenMessage("\nCurrent Text Style: {0}", sTx);

 

regards

*Expert Elite*
Alfred.NESWADBA
Posts: 9,608
Registered: ‎06-29-2007
Message 4 of 5 (177 Views)

Re: How to new a TextStyle? And then set it current?

12-19-2012 05:13 AM in reply to: ZK_BUDiKOM

Hi,

 

if you have access to your database you also have access to the property .Textstyle (e.g. AcadDocDB.Textstyle) which gives you the ObjectID for the TextStyleTableRecord.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
ZK_BUDiKOM
Posts: 30
Registered: ‎09-13-2012
Message 5 of 5 (176 Views)

Re: How to new a TextStyle? And then set it current?

12-19-2012 05:50 AM in reply to: Alfred.NESWADBA

Hi Alfred,

 

thank you it's work :smileyhappy:

 

TextStyleTableRecord style = tr.GetObject(db.Textstyle, OpenMode.ForRead) as TextStyleTableRecord;
string sTx = style.Name;

 

regards

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.