private MassElement[] GetSelectedMassElement() { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; PromptSelectionOptions Opts = new PromptSelectionOptions(); PromptSelectionResult psr = ed.GetSelection(Opts); if (psr.Status == PromptStatus.OK) { Autodesk.AutoCAD.EditorInput.SelectionSet ss = psr.Value; Autodesk.AutoCAD.DatabaseServices.ObjectId[] oids = ss.GetObjectIds(); int count = oids.Length; MassElement[] result = new MassElement[count]; Database db = Application.DocumentManager.MdiActiveDocument.Database; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; Transaction trans = tm.StartTransaction(); MassElement me = new MassElement(); for (int i = 0; i < count; i++) { Autodesk.AutoCAD.DatabaseServices.Entity ety = tm.GetObject(oids[i], OpenMode.ForWrite, true) as Autodesk.AutoCAD.DatabaseServices.Entity; result[i] = ety as MassElement; } trans.Commit(); trans.Dispose(); return(result); } return(null); }
void StreamCollectClipBodiesSample() { Database db = GetDatabase(); Editor editor = GetEditor(); editor.WriteMessage("* StreamCollectClipBodies *\n"); editor.WriteMessage("StreamCollectClipBodies clips all geometry pushed in against the supplied body.\n"); editor.WriteMessage("Pick some objects in the current drawing and then pick an mass element to define the clipping boundary. The collected graphics will be highlighted in the current view.\n"); ObjectIdCollection ids = PickObjectSet("Please pick the objects to be clipped"); if (ids.Count == 0) { editor.WriteMessage("No object is picked\n"); return; } ObjectId massElemId = PickObject(typeof(MassElement), true, "Please pick a mass element to define the clipping boundary"); if (massElemId.IsNull) { editor.WriteMessage("A mass element is needed to define the clipping boundary.\n"); return; } StreamCollectClipBodies stream = new StreamCollectClipBodies(db); // You may tell the stream to retain bodies instead of turning bodies into shells. // stream.SetRetainBodies(true); // But now we use the default setting, which uses shell as output. TransactionManager tm = db.TransactionManager; using (Transaction trans = tm.StartTransaction()) { MassElement masselem = trans.GetObject(massElemId, OpenMode.ForRead) as MassElement; AecModeler.Body body = masselem.Body.Transform(masselem.Ecs); stream.SetBodyClipVolume(body); stream.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans); foreach (ObjectId id in ids) { Entity entity = trans.GetObject(id, OpenMode.ForRead) as Entity; stream.Stream(entity); } stream.PopDisplayParameters(); trans.Commit(); } GraphicsStorage[] gsCollection = stream.GetCollectedGraphics(); foreach (GraphicsStorage gs in gsCollection) { HighlightGraphics(gs); } }
private void ListBody(MassElement me) { Autodesk.Aec.Modeler.Body b = me.Body; int faceNumber = b.Faces.Count; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + faceNumber + " faces.\n"); int index = 0; foreach (Autodesk.Aec.Modeler.Face f in b.Faces) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + f.Edges.Count + " edges in face" + index + "\n"); index++; } int surfaceNumber = b.Surfaces.Count; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + surfaceNumber + " surfaces.\n"); index = 0; foreach (Autodesk.Aec.Modeler.Surface s in b.Surfaces) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Surface " + index + " is a " + s.Type + "\n"); index++; } int curveNumber = b.Curves.Count; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + curveNumber + " curves.\n"); index = 0; foreach (Autodesk.Aec.Modeler.Curve c in b.Curves) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Curve " + index + " is a " + c.Type + "\n"); index++; } int vertexNumber = b.Vertices.Count; Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + vertexNumber + " vertices.\n"); index = 0; foreach (Autodesk.Aec.Modeler.Vertex v in b.Vertices) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Vertices " + index + " : " + v.Point + "\n"); index++; } Autodesk.Aec.Modeler.Vertex vMin = b.GetVertexMin(new Vector3d(0, 0, 1)); Autodesk.Aec.Modeler.Vertex vMax = b.GetVertexMax(new Vector3d(0, 0, 1)); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The Lowest Vertex is " + vMin.Point + "\n"); Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The Hightest Vertex is " + vMax.Point + "\n"); }
private void Clear() { Database db = HostApplicationServices.WorkingDatabase; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; Transaction t = tm.StartTransaction(); BlockTable bt = tm.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable; BlockTableRecord btr = tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord; foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId id in btr) { MassElement me = tm.GetObject(id, OpenMode.ForWrite) as MassElement; if (null != me) { me.Erase(); } } t.Commit(); t.Dispose(); }
private bool commandExec(string cmdString) { if (cmdString.ToLower() == "initsample") { InitSample(); return(true); } if (cmdString.ToLower() == "clear") { Clear(); return(true); } if (cmdString.ToLower() == "quit") { return(false); } bool result = true; Database db = HostApplicationServices.WorkingDatabase; Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager; Transaction t = tm.StartTransaction(); BlockTable bt = tm.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable; BlockTableRecord btr = tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false) as BlockTableRecord; foreach (Autodesk.AutoCAD.DatabaseServices.ObjectId id in btr) { MassElement me = tm.GetObject(id, OpenMode.ForWrite) as MassElement; if (me == null) { continue; } Autodesk.Aec.Modeler.Body b = me.Body; Autodesk.Aec.Modeler.Body b2 = null; if (cmdString.ToLower() == "subbody") { Autodesk.Aec.Modeler.Body subB = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 5)), 1, 1.5, 10); b2 = b - subB; me.SetBody(b2, true); } else if (cmdString.ToLower() == "multiplybody") { Autodesk.Aec.Modeler.Body bb = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 5)), 1, 1.5, 10); b2 = b * bb; me.SetBody(b2, true); } else if (cmdString.ToLower() == "sectionbody") { b.Section(new Plane(new Point3d(0, 0, 0), new Vector3d(0, 1, 1)), true); me.SetBody(b, false); } else if (cmdString.ToLower() == "listbody") { ListBody(me); } else if (cmdString.ToLower() == "addbody") { Autodesk.Aec.Modeler.Body bb = Autodesk.Aec.Modeler.Body.Cylinder(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(10, 0, 0)), 5, 20); b2 = b + bb; me.SetBody(b2, true); } else if (cmdString.ToLower() == "stretchbody") { b.Stretch(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 10, 0))); me.SetBody(b, false); } else if (cmdString.ToLower() == "booleanop") { Autodesk.Aec.Modeler.Body bb = Autodesk.Aec.Modeler.Body.Cylinder(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(10, 0, 0)), 5, 20); b2 = b.BooleanOperation(bb, BooleanOperatorType.Intersect); me.SetBody(b2, false); } else if (cmdString.ToLower() == "combinebody") { Autodesk.Aec.Modeler.Body bb = Autodesk.Aec.Modeler.Body.Box(new Point3d(0, 0, 0), new Vector3d(11, 11, 11)); b2 = bb.Combine(b); me.SetBody(b2, false); } else if (cmdString.ToLower() == "translatebody") { b2 = b.Translate(new Vector3d(0, 10, 0)); me.SetBody(b2, false); } else if (cmdString.ToLower() == "rotatebody") { b2 = b.Rotate(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(1, 1, 1)), 30); me.SetBody(b2, false); } else if (cmdString.ToLower() == "scalebody") { b2 = b.Scale(new Point3d(0, 0, 0), 2); me.SetBody(b2, true); } else if (cmdString.ToLower() == "listpickbody") { MassElement[] ms = GetSelectedMassElement(); if (null != ms) { foreach (MassElement m in ms) { ListBody(m); } } } else { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Wrong command!\n"); result = false; } } t.Commit(); t.Dispose(); return(result); }