|
感谢斑竹提供c#开发的方法,本人刚开始学习,现在兴趣很大,就学习中的一些问题和大家交流一下,不正确处请指教.
认真看了斑竹的学习资料后决定用AlignedDimension和LineAngularDimension2画个尺寸,开始用如下方法尝试:
Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
AlignedDimension dd1=new AlignedDimension();
dd1.XLine1Point=new Point3d(10,10,0);
dd1.XLine2Point=new Point3d(200,200,0);
dd1.DimLinePoint=new Point3d(100,100,0);
dd1.Oblique=120.00;
LineAngularDimension2 ll2=new LineAngularDimension2();
ll2.XLine1Start=new Point3d(10,10,0);
ll2.XLine1End=new Point3d(10,15,0);
ll2.XLine2Start=new Point3d(10,10,0);
ll2.XLine2End=new Point3d(20,15,0);
trans.AddNewlyCreatedDBObject(dd1,true);
trans.AddNewlyCreatedDBObject(ll2,true);
trans.Commit();
trans.Dispose();
可是调试错误,后来通过学习发现,在实体构造上出现问题(不明白line,circle如何就可以),需要重新构建,做如下修改就可:
构件实体函数:
public static ObjectId AddEntity(Entity ent)
{Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();
Database Db1=HostApplicationServices.WorkingDatabase;
try
{
BlockTable bt =
(BlockTable)trans.GetObject(Db.BlockTableId, OpenMode.ForWrite, false);
BlockTableRecord btr =
BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],
OpenMode.ForWrite, false);
btr.AppendEntity(ent);
trans.AddNewlyCreatedDBObject(ent, true);
trans.Commit();
return ent.ObjectId;
}
}
catch (System.Exception e)
{
throw e;
}
}
将原计算方法修改为:
AlignedDimension dd1=new AlignedDimension();
dd1.XLine1Point=new Point3d(10,10,0);
dd1.XLine2Point=new Point3d(200,200,0);
dd1.DimLinePoint=new Point3d(100,100,0);
dd1.Oblique=120.00;
LineAngularDimension2 ll2=new LineAngularDimension2();
ll2.XLine1Start=new Point3d(10,10,0);
ll2.XLine1End=new Point3d(10,15,0);
ll2.XLine2Start=new Point3d(10,10,0);
ll2.XLine2End=new Point3d(20,15,0);
ObjectId id = AddEntity(dd1);
ObjectId id1 = AddEntity(ll2);
就可以成功了.
真不明白autodesk公司为什么设计这么复杂,希望大家一起探讨. |
|