.NET

Reply
Member
nehmaiz
Posts: 4
Registered: ‎09-17-2006
Message 1 of 8 (193 Views)

How do i change fonts using .Net?

193 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
pavlos.katsonis
Posts: 67
Registered: ‎09-12-2006
Message 2 of 8 (193 Views)

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
nehmaiz
Posts: 4
Registered: ‎09-17-2006
Message 3 of 8 (193 Views)

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
pavlos.katsonis
Posts: 67
Registered: ‎09-12-2006
Message 4 of 8 (193 Views)

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
nehmaiz
Posts: 4
Registered: ‎09-17-2006
Message 5 of 8 (193 Views)

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
Message 6 of 8 (193 Views)

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
nehmaiz
Posts: 4
Registered: ‎09-17-2006
Message 7 of 8 (193 Views)

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.
*tp
Message 8 of 8 (193 Views)

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/
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.