cgn 发表于 2005-6-17 14:51:00

与大家探讨如何用c#标住尺寸

感谢斑竹提供c#开发autocad的方法,本人刚开始学习,现在兴趣很大,就学习中的一些问题和大家交流一下,不正确处请指教.


认真看了斑竹的学习资料后决定用AlignedDimension和LineAngularDimension2画个尺寸,开始用如下方法尝试:


Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();        <BR>                        AlignedDimension dd1=new AlignedDimension();<BR>                        dd1.XLine1Point=new Point3d(10,10,0);<BR>                        dd1.XLine2Point=new Point3d(200,200,0);<BR>                        dd1.DimLinePoint=new Point3d(100,100,0);<BR>                        dd1.Oblique=120.00;<BR>                        LineAngularDimension2 ll2=new LineAngularDimension2();<BR>                        ll2.XLine1Start=new Point3d(10,10,0);<BR>                        ll2.XLine1End=new Point3d(10,15,0);<BR>                        ll2.XLine2Start=new Point3d(10,10,0);<BR>                        ll2.XLine2End=new Point3d(20,15,0);<BR>trans.AddNewlyCreatedDBObject(dd1,true);<BR>trans.AddNewlyCreatedDBObject(ll2,true);<BR>trans.Commit();<BR>trans.Dispose();


可是调试错误,后来通过学习发现,在实体构造上出现问题(不明白line,circle如何就可以),需要重新构建,做如下修改就可:


构件实体函数:


public static ObjectId AddEntity(Entity ent)<BR>{Transaction trans = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction();        <BR>Database Db1=HostApplicationServices.WorkingDatabase;


try<BR>{<BR>BlockTable bt = <BR>(BlockTable)trans.GetObject(Db.BlockTableId, OpenMode.ForWrite, false);<BR>BlockTableRecord btr = <BR>BlockTableRecord)trans.GetObject(bt, <BR>OpenMode.ForWrite, false);<BR>btr.AppendEntity(ent);<BR>trans.AddNewlyCreatedDBObject(ent, true);<BR>trans.Commit();<BR>return ent.ObjectId;<BR>}<BR><BR>}<BR>catch (System.Exception e)<BR>{<BR>throw e;<BR>}<BR>}


将原计算方法修改为:


        AlignedDimension dd1=new AlignedDimension();<BR>                        dd1.XLine1Point=new Point3d(10,10,0);<BR>                        dd1.XLine2Point=new Point3d(200,200,0);<BR>                        dd1.DimLinePoint=new Point3d(100,100,0);<BR>                        dd1.Oblique=120.00;<BR>                        LineAngularDimension2 ll2=new LineAngularDimension2();<BR>                        ll2.XLine1Start=new Point3d(10,10,0);<BR>                        ll2.XLine1End=new Point3d(10,15,0);<BR>                        ll2.XLine2Start=new Point3d(10,10,0);<BR>                        ll2.XLine2End=new Point3d(20,15,0);<BR>ObjectId id = AddEntity(dd1);<BR>                        ObjectId id1 = AddEntity(ll2);


就可以成功了.


真不明白autodesk公司为什么设计这么复杂,希望大家一起探讨.
页: [1]
查看完整版本: 与大家探讨如何用c#标住尺寸