- 积分
- 24557
- 明经币
- 个
- 注册时间
- 2004-3-17
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2010-12-4 21:37:06
|
显示全部楼层
本帖最后由 lzh741206 于 2010-12-5 17:58 编辑
你的代码,哎,惨不忍睹
- public static ObjectId CreateBlockDef(string blockname, DBObjectCollection objs)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite, false);
- if (bt.Has(blockname))
- {
- return bt[blockname];
- }
- else
- {
- BlockTableRecord btr = new BlockTableRecord();
- btr.Name = blockname;
- ObjectId id = bt.Add(btr);
- tr.AddNewlyCreatedDBObject(btr, true);
- foreach (Entity ent in objs)
- {
- btr.AppendEntity(ent);
- tr.AddNewlyCreatedDBObject(ent, true);
- }
- tr.Commit();
- return id;
- }
- }
- }
- public static ObjectId CreateBlockRef(string blockname, Point3d position, double rotateAngle, double scale)
- {
- Database db = HostApplicationServices.WorkingDatabase;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
- BlockReference blockRef = new BlockReference(position, bt[blockname]);
- blockRef.ScaleFactors = new Scale3d(scale, scale, scale);
- blockRef.Rotation = rotateAngle;
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- ObjectId id = btr.AppendEntity(blockRef);
- tr.AddNewlyCreatedDBObject(blockRef, true);
- tr.Commit();
- return id;
- }
- }
-
- [CommandMethod("t8")]
- public static void Test8()
- {
- Circle c1 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 10);
- Circle c2 = new Circle(new Point3d(0, 0, 0), Vector3d.ZAxis, 15);
- DBObjectCollection objs = new DBObjectCollection();
- objs.Add(c1);
- objs.Add(c2);
- CreateBlockDef("Test", objs);
- CreateBlockRef("Test", Point3d.Origin, 0, 1);
- }
-
|
|