//调用时-方法参数列表填写文字写入位置,以及要写的文字,sx、sy填写0(sx和sy代表文字对齐坐标),或填写文字对齐坐标-单行文字-角度填写1~360度
public void addText(double x,double y,double z,String str,double angle, double sx, double sy)
{//调用时-方法参数列表填写文字写入位置,以及要写的文字
Document doc = Application.DocumentManager.MdiActiveDocument;
Database dbba = HostApplicationServices.WorkingDatabase;
using (Transaction trans = doc.TransactionManager.StartTransaction())
{
DBText db = new DBText();
db.Position = new Point3d(x, y, z);//设置文字显示位置
db.Height = 1.75;//设置文字高度
db.WidthFactor = 0.7;
db.TextString = str;//设置文字
db.Rotation = angle/57.3;///57.3
db.Layer = "土建文字标注";
db.HorizontalMode = TextHorizontalMode.TextCenter;
if (angle < 0)
{
sx = sx + 1.5;//1.1
sy = sy + 1.5;//1.1
}
else if(angle > 0){
sx = sx - 1.5;//1.1
sy = sy + 1.5;//1.1
}
if (sx!=0)
{
db.AlignmentPoint = new Point3d(sx, sy, 0);//此代码要放到db.HorizontalMode = TextHorizontalMode.TextCenter;之后
}
BlockTable acBlkTbl;
acBlkTbl = trans.GetObject(dbba.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord acBlkTblRec;
acBlkTblRec = trans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
acBlkTblRec.AppendEntity(db);
trans.AddNewlyCreatedDBObject(db, true);
trans.Commit();
}
}
cad二次开发-在vs编译软件环境下使用c#语言编写dll文件-添加单行文本
于 2020-11-20 17:18:30 首次发布