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

How to create a "TextStyles" using the font "romans.shx"?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Anonymous
1487 Views, 5 Replies

How to create a "TextStyles" using the font "romans.shx"?

I'm having problems to create "TextStyles" with the sources of AutoCad.

 

I am using the following methods:

 

 public static ObjectId CreateTexstyle(Configuration conf)
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable textStyleTable = (TextStyleTable)acTrans.GetObject(acCurDb.TextStyleTableId, OpenMode.ForRead);
                TextStyleTableRecord textStyleTableRecord = null;
                if (textStyleTable.Has(conf.EXTTEXTStyleName) == false)
                {

                    if (textStyleTable.IsWriteEnabled == false)
                        textStyleTable.UpgradeOpen();
                    textStyleTableRecord = new TextStyleTableRecord();
                    textStyleTableRecord.Name = conf.EXTTEXTStyleName;
                    textStyleTable.Add(textStyleTableRecord);
                    acTrans.AddNewlyCreatedDBObject(textStyleTableRecord, true);
                }
                else
                {
                    textStyleTableRecord = acTrans.GetObject(textStyleTable[conf.EXTTEXTStyleName],
                        OpenMode.ForWrite) as TextStyleTableRecord;
                }

                textStyleTableRecord.XScale = conf.EXTTEXTFactor;
                textStyleTableRecord.TextSize = conf.EXTTEXTSize;
                textStyleTableRecord.Font = UpdateTextFont(conf.EXTTEXTFont, conf.EXTTEXTFontItalico, conf.EXTTEXTFontNegrito);
                acTrans.Commit();
                return textStyleTableRecord.ObjectId;
            }
        }

 

        public static Autodesk.AutoCAD.GraphicsInterface.FontDescriptor UpdateTextFont(string font, bool italic, bool negrito)
        {
            return new Autodesk.AutoCAD.GraphicsInterface.FontDescriptor(font, negrito, italic, 0, 0);
        }

 

In the example font = "romans", italic = false end bold = false.

 

In AutoCad the source is "romans.shx" but is a little different from when it is configured manually.

 

Programmatically

Image1

 

 

manually

image2

 

 

Note that the text becomes thicker.

And a little change settings window TextStyles. What can be?

5 REPLIES 5
Message 2 of 6
Anonymous
in reply to: Anonymous

I managed to solve the problem.

 

Add the following line in the code:

 

textStyleTableRecord.FileName = conf.EXTTEXTFont + ".shx";

 

 public static ObjectId CreateTexstyle(Configuration conf)
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Database acCurDb = acDoc.Database;
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                TextStyleTable textStyleTable = (TextStyleTable)acTrans.GetObject(acCurDb.TextStyleTableId, OpenMode.ForRead);
                TextStyleTableRecord textStyleTableRecord = null;
                if (textStyleTable.Has(conf.EXTTEXTStyleName) == false)
                {

                    if (textStyleTable.IsWriteEnabled == false)
                        textStyleTable.UpgradeOpen();
                    textStyleTableRecord = new TextStyleTableRecord();
                    textStyleTableRecord.Name = conf.EXTTEXTStyleName;
                    textStyleTable.Add(textStyleTableRecord);
                    acTrans.AddNewlyCreatedDBObject(textStyleTableRecord, true);
                }
                else
                {
                    textStyleTableRecord = acTrans.GetObject(textStyleTable[conf.EXTTEXTStyleName],
                        OpenMode.ForWrite) as TextStyleTableRecord;
                }

                textStyleTableRecord.XScale = conf.EXTTEXTFactor;
                textStyleTableRecord.TextSize = conf.EXTTEXTSize;
                textStyleTableRecord.Font = UpdateTextFont(conf.EXTTEXTFont, conf.EXTTEXTFontItalico, conf.EXTTEXTFontNegrito);
                textStyleTableRecord.FileName = conf.EXTTEXTFont + ".shx";
                acTrans.Commit();
                return textStyleTableRecord.ObjectId;
            }
        }

 Now I have another problem.

 

Sem título.png

My program offers options for Windows font, I believe it has not equivalent for all sources in the autocad file extension "*. shx", then how could verify this?
If there is "*. shx" to use that font "*. shx", if not use defaut.


Message 3 of 6
Anonymous
in reply to: Anonymous

That way it worked, I do not know if it is guaranteed: Smiley Indifferent

 

                if(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Fonts\\" + conf.EXTTEXTFont + ".shx"))
                    textStyleTableRecord.FileName = conf.EXTTEXTFont + ".shx";

 

Thank you!

Message 4 of 6
Alexander.Rivilis
in reply to: Anonymous


@Anonymous wrote:

... I do not know if it is guaranteed: ...


It will be guaranteed if you check directory of dwg-file and AutoCAD support pathes.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 5 of 6
Anonymous
in reply to: Alexander.Rivilis

How do I do that?

Message 6 of 6
Alexander.Rivilis
in reply to: Anonymous

With help of HostApplicationServices.FindFile method

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

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