.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do i change fonts using .Net?

7 REPLIES 7
Reply
Message 1 of 8
nehmaiz
690 Views, 7 Replies

How do i change fonts using .Net?

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
7 REPLIES 7
Message 2 of 8
pavlos.katsonis
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.
Message 3 of 8
nehmaiz
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
Message 4 of 8
pavlos.katsonis
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.
Message 5 of 8
nehmaiz
in reply to: nehmaiz

it's not part of Autocad 2006 😞

any alternatives?

Thanks anyways. Message was edited by: nehmaiz
Message 6 of 8
Anonymous
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.
Message 7 of 8
nehmaiz
in reply to: nehmaiz

The Code Works fine 🙂 just have to commit the transaction in the end 😉

Thanks for the help guys.
Message 8 of 8
Anonymous
in reply to: nehmaiz

See atached file.
It works for me.
tp


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

Thanks for the help guys.



I'm protected by SpamBrave
http://www.spambrave.com/

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost