本帖最后由 cdinten 于 2010-12-30 19:01 编辑
貌似AutoCAD2006中实体没有Mirror方法,这让人很纠结,写了个程序演示实体的镜像,代码如下:
- [CommandMethod("MP")]//Mirror Entity
- public void MirrorEntity()
- {
- Database db = Application.DocumentManager.MdiActiveDocument.Database;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- //对称平面
- Plane mp = new Plane(new Point3d(1, 0, 0), new Point3d(0, 1, 0), new Point3d(0, 0, 1));
- double x = mp.Normal.X;
- double y = mp.Normal.Y;
- double z = mp.Normal.Z;
- double[] dm = new double[16];
- dm[0] = 1 - 2 * x * x;
- dm[5] = 1 - 2 * y * y;
- dm[10] = 1 - 2 * z * z;
- dm[15]=1;
- dm[1] = dm[4] = -2*x * y;
- dm[2] = dm[8] = -2*x * z;
- dm[6] = dm[9] = -2*y * z;
- Matrix3d Tm = new Matrix3d(dm);
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- Solid3d sld = new Solid3d();
- sld.SetDatabaseDefaults();
- sld.CreateBox(100, 150, 200);
- sld.ColorIndex = 1;//red
- btr.AppendEntity(sld);
- trans.AddNewlyCreatedDBObject(sld, true);
- Solid3d sldClone = sld.Clone() as Solid3d;
- sldClone.ColorIndex = 3;//green
- sldClone.TransformBy(Tm);
- btr.AppendEntity(sldClone);
- trans.AddNewlyCreatedDBObject(sldClone, true);
- trans.Commit();
- }
- }
|