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
manually
Note that the text becomes thicker.
And a little change settings window TextStyles. What can be?
Solved! Go to 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.
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.
That way it worked, I do not know if it is guaranteed:
if(File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Fonts\\" + conf.EXTTEXTFont + ".shx"))
textStyleTableRecord.FileName = conf.EXTTEXTFont + ".shx";
Thank you!
@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
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