.NET

Reply
Member
4 Posts
0 Kudos
Registered: ‎09-17-2006
Post 1 of 8

How do i change fonts using .Net?

202 Views, 7 Replies
09-27-2006 09:57 PM
hello, does anyone know how to change fonts on drawings using the .Net classes?

I've tried using the "DB.Textstyle" property and the "Autodesk.AutoCAD.GraphicsInterface.FontDescriptor" class, but to no avail.

any example would be appreciated.

regards,

Nehme
Valued Contributor
67 Posts
0 Kudos
Registered: ‎09-12-2006
Post 2 of 8

Re: How do i change fonts using .Net?

09-28-2006 01:16 AM in reply to: nehmaiz
Well, first you have to find the text style whose font you want to change:

Database dataBase = Application.DocumentManager.MdiActiveDocument.Database;

Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = dataBase.TransactionManager;

Transaction txtTR = tm.StartTransaction();

// Get the text styles table
TextStyleTable textStyles = (TextStyleTable)txtTR.GetObject(dataBase.TextStyleTableId, OpenMode.ForRead);

// Search for the text style you want to change
if (textStyles.Has("myTextStyle"))
{
SymbolTableEnumerator textStylesEnum = textStyles.GetEnumerator();
TextStyleTableRecord textStyle;
while (textStylesEnum.MoveNext())
if ((textStyle = (TextStyleTableRecord)(textStylesEnum.Current.GetObject(OpenMode.ForRead))).Name.Equals("myTextStyle"))
{
// Now that you have found it, change its font
textStyle.UpgradeOpen();
textStyle.FileName = "ARIALUNI.TTF";
break;
}
textStylesEnum.Dispose();
}
txtTR.Commit();


Obviously, this is the case when you want to change a specific text style, not just the current.
Member
4 Posts
0 Kudos
Registered: ‎09-17-2006
Post 3 of 8

Re: How do i change fonts using .Net?

09-29-2006 10:39 PM in reply to: nehmaiz
Hi,

Thanks for the post, however i'm having a tiny problem, the enumerator you are using, "SymbolTableEnumerator", seems to be an enumerator developed by you.
so i tried replacing that class with the base class "IEnumerator" but i got an error while trying to access "textStylesEnum.Current.GetObject(..)", the error says:

'object' does not contain a definition for 'GetObject'

any suggestions?

afkharesto poly

Nehme Message was edited by: nehmaiz
Valued Contributor
67 Posts
0 Kudos
Registered: ‎09-12-2006
Post 4 of 8

Re: How do i change fonts using .Net?

09-29-2006 11:27 PM in reply to: nehmaiz
You're wellcome.

SymbolTableEnumerator isn't developed by me. It resides in Autodesk.AutoCAD.DatabaseServices. At least in ACAD 2007 that I'm using.
Member
4 Posts
0 Kudos
Registered: ‎09-17-2006
Post 5 of 8

Re: How do i change fonts using .Net?

09-30-2006 01:14 AM in reply to: nehmaiz
it's not part of Autocad 2006 :smileysad:

any alternatives?

Thanks anyways. Message was edited by: nehmaiz
*Alexander Rivilis
Post 6 of 8

Re: How do i change fonts using .Net?

09-30-2006 03:05 AM in reply to: nehmaiz
Hi, nehmaiz!
For AutoCAD 2006 but without testing:
[code]
static public void ChangeFont()
{
Database dataBase = Application.DocumentManager.MdiActiveDocument.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = dataBase.TransactionManager;
using (Transaction txtTR = tm.StartTransaction())
{
// Get the text styles table
TextStyleTable textStyles = (TextStyleTable)txtTR.GetObject(dataBase.TextStyleTableId, OpenMode.ForRead);
// Search for the text style you want to change
if (textStyles.Has("myTextStyle"))
{
IEnumerator textStylesEnum = textStyles.GetEnumerator();
TextStyleTableRecord textStyle;
while (textStylesEnum.MoveNext())
{
textStyle = (TextStyleTableRecord)txtTR.GetObject((ObjectId)textStylesEnum.Current,OpenMode.ForRead);
if (textStyle.Name.Equals("myTextStyle"))
{
// Now that you have found it, change its font
textStyle.UpgradeOpen();
textStyle.FileName = "ARIALUNI.TTF";
break;
}
}
}
}
}
[/code]

Best Regards,
Alexander Rivilis.
Member
4 Posts
0 Kudos
Registered: ‎09-17-2006
Post 7 of 8

Re: How do i change fonts using .Net?

09-30-2006 09:36 PM in reply to: nehmaiz
The Code Works fine :smileyhappy: just have to commit the transaction in the end :smileywink:

Thanks for the help guys.

Re: How do i change fonts using .Net?

10-01-2006 12:18 PM in reply to: nehmaiz
See atached file.
It works for me.
tp


escreveu na mensagem news:5346514@discussion.autodesk.com...
The Code Works fine :smileyhappy: just have to commit the transaction in the end :smileywink:

Thanks for the help guys.



I'm protected by SpamBrave
http://www.spambrave.com/
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post