一、插入文字实体,下面两段文字根据文字插入基点的位置不同,第一个插入基点位置是中间,第二个是插入在左下角
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord modelspace = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
TextStyleTable st = trans.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
DBText txt_xjm_gc1_jdianqiming1 = new DBText();
//插入内容
txt_xjm_gc1_jdianqiming1.TextString = “abc”;
//插入内容
txt_xjm_gc1_jdianqiming1.Position = new Point3d(0, 0, 0);
//文字高度
txt_xjm_gc1_jdianqiming1.Height = 2.5;
//文字长宽比
txt_xjm_gc1_jdianqiming1.WidthFactor = 0.75;
//对齐方式为居中
txt_xjm_gc1_jdianqiming1.Justify = AttachmentPoint.MiddleCenter;
//居中方式必须有下面一句
txt_xjm_gc1_jdianqiming1.AlignmentPoint = txt_xjm_gc1_jdianqiming1.Position;
//文字样式
txt_xjm_gc1_jdianqiming1.TextStyle = st["gbc"];
//文字颜色
txt_xjm_gc1_jdianqiming1.ColorIndex = 200;
DBText txt_xjm_gc1_jieidan52 = new DBText();
txt_xjm_gc1_jieidan52.TextString = “abc”;
txt_xjm_gc1_jieidan52.Position = new Point3d(0, 0, 0);
txt_xjm_gc1_jieidan52.Height = 1.8;
txt_xjm_gc1_jieidan52.WidthFactor = 0.75;
txt_xjm_gc1_jieidan52.Justify = AttachmentPoint.BaseLeft;
txt_xjm_gc1_jieidan52.TextStyle = st["gbc"];
txt_xjm_gc1_jieidan52.ColorIndex = 200;
modelspace.AppendEntity(txt_xjm_gc1_jdianqiming1);
modelspace.AppendEntity(txt_xjm_gc1_jieidan52);
trans.AddNewlyCreatedDBObject(txt_xjm_gc1_jdianqiming1, true);
trans.AddNewlyCreatedDBObject(txt_xjm_gc1_jieidan52, true);
trans.Commit();
}//using end
二、插入线段实体
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord modelspace = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
TextStyleTable st = trans.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
//创建线实体,并设置线段颜色
Line line_4 = new Line(new Point3d(0, 297, 0), new Point3d(0, 0, 0));
line_4.ColorIndex = 200;
modelspace.AppendEntity(line_4);
trans.AddNewlyCreatedDBObject(line_4, true);
trans.Commit();
}//using end
三、插入外部块参照
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord modelspace = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
TextStyleTable st = trans.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
//创建外部块参照实体
ObjectId refid = db.OverlayXref(Environment.CurrentDirectory + @"\八面城电码化08\原件\xjm_fsq.dwg", "XJM_fsq");
//返回快参照,参照位置为该元件的左下角
BlockReference br = new BlockReference(new Point3d(xjmxfinal, 292, 0), refid);
modelspace.AppendEntity(br);
trans.AddNewlyCreatedDBObject(br, true);
trans.Commit();
}//using end