Ejemplo n.º 1
0
        void HighlightBody(AecModeler.Body body, int color)
        {
            Editor editor = GetEditor();

            foreach (AecModeler.Edge edge in body.PhysicalEdges)
            {
                editor.DrawVector(edge.Line.StartPoint, edge.Line.EndPoint, color, true);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        void StreamCollectMaterialsSample()
        {
            Database db     = GetDatabase();
            Editor   editor = GetEditor();

            editor.WriteMessage("* StreamCollectMaterials *\n");
            editor.WriteMessage("StreamCollectMaterials collects bodies of the specified materials from the entities pushed into the stream.\n");
            editor.WriteMessage("Pick some objects in the current drawing. The bodies with materials specifed will be highlighted. And bodies with the same material are displayed in one color.\n");

            StreamCollectMaterials stream = new StreamCollectMaterials(db);
            // StreamCollectMaterials needs the users to specify the materials they're interested in by setting the MaterialFilter property.
            // Here we add all the material ids in the current drawing to the filter collection.
            DictionaryMaterialDefinition dictMaterials = new DictionaryMaterialDefinition(db);

            stream.MaterialFilter = dictMaterials.Records;
            // To combine the bodies with the same material instead of traversing the body chain
            stream.CombineBodies = true;

            ObjectIdCollection ids = PickObjectSet();

            if (ids.Count == 0)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            TransactionManager tm = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                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();
            }

            ids = stream.MaterialIds;
            int color = 1;

            foreach (ObjectId id in ids)
            {
                AecModeler.Body body = stream.GetBody(id);
                HighlightBody(body, color++);
            }
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 5
0
        private void Init()
        {
            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;

            Autodesk.Aec.DatabaseServices.MassElement temp = Autodesk.Aec.DatabaseServices.MassElement.Create(ShapeType.BoundaryRepresentation);
            Autodesk.Aec.Modeler.Body body = Autodesk.Aec.Modeler.Body.Cone(new LineSegment3d(new Point3d(0, 0, 0), new Point3d(0, 0, 10)), 3, 3, 10);
            temp.SetBody(body, false);
            btr.AppendEntity(temp);
            tm.AddNewlyCreatedDBObject(temp, true);

            t.Commit();
            t.Dispose();
        }
Ejemplo n.º 6
0
        private void StreamCollectBodiesSample()
        {
            Database db     = GetDatabase();
            Editor   editor = GetEditor();

            editor.WriteMessage("* StreamCollectBodies *\n");
            editor.WriteMessage("StreamCollectBodies collects bodies from the objects passed in.\n");
            editor.WriteMessage("Pick some objects in the current drawing. The collected bodies will be highlighted in the current view. And the volume of the bodies will be printed out in the output window.\n");

            ObjectIdCollection ids = PickObjectSet();

            if (ids.Count == 0)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            StreamCollectBodies stream = new StreamCollectBodies(db);
            TransactionManager  tm     = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                stream.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);

                foreach (ObjectId id in ids)
                {
                    Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;
                    stream.Stream(ent);
                }

                stream.PopDisplayParameters();
                trans.Commit();
            }

            // draw the collected body and output the volume of the body
            AecModeler.Body body = stream.GetBodyCopy();
            HighlightBody(body);

            editor.WriteMessage("Body volume = " + body.Volume.ToString() + "\n");
        }
Ejemplo n.º 7
0
 void HighlightBody(AecModeler.Body body)
 {
     HighlightBody(body, 1);
 }
Ejemplo n.º 8
0
        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);
        }