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

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

Anonymous
Not applicable
2,390 Views
5 Replies
Message 1 of 6

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

Anonymous
Not applicable

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?

0 Likes
Accepted solutions (1)
2,391 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Accepted solution

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.


0 Likes
Message 3 of 6

Anonymous
Not applicable

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!

0 Likes
Message 4 of 6

Alexander.Rivilis
Mentor
Mentor

@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

0 Likes
Message 5 of 6

Anonymous
Not applicable

How do I do that?

0 Likes
Message 6 of 6

Alexander.Rivilis
Mentor
Mentor

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

0 Likes