cad二次开发-在vs编译软件环境下使用c#语言编写dll文件-添加单行文本

    //调用时-方法参数列表填写文字写入位置,以及要写的文字,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();
        }
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值