c# cad 二次开发 类库 块的操作
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _14块操作
{
public class Class1
{
//简单块
[CommandMethod(“BlockDemo”)]
public void BlockDemo()
{
Database db = HostApplicationServices.WorkingDatabase;
//using (Transaction trans = db.TransactionManager.StartTransaction())
//{
// BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
// foreach ( var item in bt)
// {
// BlockTableRecord btr = (BlockTableRecord)item.GetObject(OpenMode.ForRead);
// }
//}
MyBlockTableRecord.Block1Id = db.AddBlockTableRecord(MyBlockTableRecord.Block1Name, MyBlockTableRecord.Block1Ents);
}
[CommandMethod("InsertBlockDemo")]
public void InsertBlockDemo()
{
Database db = HostApplicationServices.WorkingDatabase;
db.InsertBlockBlockReference(MyBlockTableRecord.Block1Id, new Point3d(10, 10, 0));
db.InsertBlockBlockReference(MyBlockTableRecord.Block1Id, new Point3d(40, 10, 0),Math.PI/4,new Scale3d(2));
db.InsertBlockBlockReference(MyBlockTableRecord.Block1Id, new Point3d(100, 10, 0), Math.PI / 4, new Scale3d(2,1.5,1));
}
//注释样式的箭头
[CommandMethod("ModifyDimDemo")]
public void ModifyDimDemo()
{
Database db = HostApplicationServices.WorkingDatabase;
MyBlockTableRecord.DimBlock1Id = db.AddBlockTableRecord(MyBlockTableRecord.DimBlock1Name, MyBlockTableRecord.DimBlock1Ents);
using (Transaction trans = db.TransactionManager.StartTransaction())
{
DimStyleTable dst = (DimStyleTable)trans.GetObject(db.DimStyleTableId, OpenMode.ForRead);
if (dst.Has("Standard"))
{
DimStyleTableRecord dstr = (DimStyleTableRecord)dst["Standard"].GetObject(OpenMode.ForRead);
if (MyBlockTableRecord.DimBlock1Id != ObjectId.Null)
{
dstr.UpgradeOpen();
dstr.Dimblk = MyBlockTableRecord.DimBlock1Id;
dstr.Dimasz = 1;
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删