« on: December 13, 2008, 01:43:50 AM »
Following on from this posted here in answer to a question ..
[CommandMethod("TestText")]
static public void TestDbText()
// CodeHimBelongaKbub@TheSwamp © Dec 2008
{
Database db = HostApplicationServices.WorkingDatabase;
string txtStr = "This is a DbText string.";
string txtStyle = "kbubsComicTextStyle";
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord CurrentSpaceBtr = tr.GetObject(db.CurrentSpaceId,
OpenMode.ForWrite) as BlockTableRecord ;
DBText textObj
= new DBText
(); textObj.TextString = txtStr;
textObj.Height = 500;
textObj
.Position = new Point3d
(0,
0,
0) ;
textObj.HorizontalMode = TextHorizontalMode.TextMid;
textObj.AlignmentPoint = textObj.Position;
TextStyleTable txtTbl = tr.GetObject(db.TextStyleTableId,
OpenMode.ForRead) as TextStyleTable ;
if (txtTbl.Has(txtStyle))
{
TextStyleTableRecord txtTbr = tr.GetObject(txtTbl[txtStyle],
OpenMode.ForRead) as TextStyleTableRecord;
textObj.TextStyle = txtTbr.ObjectId;
}
CurrentSpaceBtr.AppendEntity(textObj);
tr.AddNewlyCreatedDBObject(textObj, true);
tr.Commit();
}
}
I wanted to check if the TextStyle existed ..
[CommandMethod("AOMT")]
static public void AOMT()
// CodeHimBelongaKbub@TheSwamp © Dec 2008
{
AssertOrMakeTextStyle("kbubsISOTextStyle", "isocp.shx");
AssertOrMakeTextStyle("kbubsComicTextStyle", "Comic.ttf");
}
static public void AssertOrMakeTextStyle(string styleName, string styleFileName)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
TextStyleTable tsTable = tr.GetObject(db.TextStyleTableId, OpenMode.ForWrite) as TextStyleTable;
if (!tsTable.Has(styleName))
{
TextStyleTableRecord tsTableRecord
= new TextStyleTableRecord
(); tsTableRecord.Name = styleName;
tsTableRecord.FileName = styleFileName;
tsTableRecord.IsVertical = false;
tsTableRecord.TextSize = 0.0;
tsTable.Add(tsTableRecord);
tr.AddNewlyCreatedDBObject(tsTableRecord, true);
}
tr.Commit();
}
}
.. With these results
« Last Edit: August 07, 2013, 06:32:14 AM by Kerry »
Logged
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.