CAD二次開發——在CAD中建立直線

qq_43451782發表於2020-09-30
[CommandMethod("TestDemo")]
        public void TestDemo()
        {
            //Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            Line line = new Line();
            line.StartPoint = new Point3d(1000,200,0);
            line.EndPoint = new Point3d(800,300,0);
            //宣告圖形資料庫物件
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            //開啟事務
            Transaction trans = db.TransactionManager.StartTransaction();
            //開啟塊表
            BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
            //開啟塊表記錄
            BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
            //加直線到塊表記錄
            btr.AppendEntity(line);
            //更新資料
            trans.AddNewlyCreatedDBObject(line,true);
            //事務提交
            trans.Commit();                             
        }

使用的類庫:1.acmgd.dll 2.acdbmgd.dll 3.accoremgd.dll

 

相關文章