Пример #1
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);
            }
        }
Пример #2
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++);
            }
        }
Пример #3
0
        private void StreamCurvesSample()
        {
            Editor   editor = GetEditor();
            Database db     = GetDatabase();

            editor.WriteMessage("* StreamCurves *\n");
            editor.WriteMessage("StreamCurves collects curves and lines from the objects passed in.\n");
            editor.WriteMessage("Pick some objects in the current drawing. The collected graphics will be highlighted while the numbers of collected lines and curves will be printed in the output window.\n");

            ObjectIdCollection ids = PickObjectSet();

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

            StreamCurves stream = new StreamCurves(db);

            // collect arcs instead of breaking arcs into line segments
            stream.CollectArcs = true;
            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();
            }

            LineSegment3d[] lines = stream.Lines;
            CircularArc3d[] arcs  = stream.Arcs;
            editor.WriteMessage("Collected " + lines.Length + " lines and " + arcs.Length + " arcs.\n");
            foreach (LineSegment3d line in lines)
            {
                editor.DrawVector(line.StartPoint, line.EndPoint, 1, true);
            }
            foreach (CircularArc3d arc in arcs)
            {
                HighlightArc(arc);
            }
        }
Пример #4
0
        void StreamSliceSample()
        {
            Database db     = GetDatabase();
            Editor   editor = GetEditor();

            editor.WriteMessage("* StreamSlice *\n");
            editor.WriteMessage("StreamSlice slices bodies with a plane.\n");
            editor.WriteMessage("Pick some objects in the current drawing to be sliced and then pick three points to define the plane. The result profile will be highlighted.\n");
            ObjectIdCollection ids = PickObjectSet("Please pick the bodies need to be sliced");

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

            editor.WriteMessage("Now you need to pick 3 points from the screen to define the slicing plane.\n");
            Plane plane = PromptPlane();

            if (plane == null)
            {
                return;
            }

            StreamSlice stream = new StreamSlice(db, plane);

            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();
            }

            HighlightProfile(stream.GetProfile(), plane);
        }
Пример #5
0
        private void StreamVectorSample()
        {
            // intro message
            Editor editor = GetEditor();

            editor.WriteMessage("* StreamVector *\n");
            editor.WriteMessage("StreamVector sample demonstrates the ability of StreamVector that breaks selected entity into primitive lines.\n");
            editor.WriteMessage("Pick an object in the current drawing and the collected lines will be highlighted.\n");

            // pick an object
            ObjectId id = PickObject(typeof(Entity), false);

            if (id.IsNull)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            Database           db     = GetDatabase();
            StreamVector       stream = new StreamVector(db);
            TransactionManager tm     = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;

                // setup the display parameters
                stream.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);

                // stream the object
                stream.Stream(ent);

                stream.PopDisplayParameters();

                trans.Commit(); // for better performance
            }

            // highlights the collected lines
            foreach (LineSegment3d line in stream.Lines)
            {
                editor.DrawVector(line.StartPoint, line.EndPoint, 1, true);
            }
        }
Пример #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");
        }
Пример #7
0
        private void StreamExtentSample()
        {
            // intro message
            Editor editor = GetEditor();

            editor.WriteMessage("* StreamExtent *\n");
            editor.WriteMessage("StreamExtent detects the extents of all the objects in the stream.\n");
            editor.WriteMessage("Pick some objects in the current drawing and the extents will be highlighted.\n");

            // pick multiple objects
            ObjectIdCollection ids = PickObjectSet();

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

            Database     db     = GetDatabase();
            StreamExtent stream = new StreamExtent(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();
            }

            HighlightBoundBox3d(stream.Extents);
        }
Пример #8
0
        private void StreamExplodeSample()
        {
            // intro message
            Editor editor = GetEditor();

            editor.WriteMessage("* StreamExplode *\n");
            editor.WriteMessage("StreamExplode converts all entities to AutoCAD primitive entities.\n");
            editor.WriteMessage("Pick an object in the current drawing. The object you picked will be packaged to an anonymous block and finally referenced in the current space. The block-referenced object will be overlapping with the original one.\n");

            // pick a object to be exploded
            ObjectId id = PickObject(typeof(Entity), false);

            if (id.IsNull)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            Database           db            = GetDatabase();
            DBObjectCollection objects       = new DBObjectCollection();
            StreamExplode      streamExplode = new StreamExplode(db, objects);

            streamExplode.IsVisualExplode = true;
            streamExplode.SetForBoundarySearch(false);

            TransactionManager tm = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                Entity ent = trans.GetObject(id, OpenMode.ForRead) as Entity;

                streamExplode.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);
                streamExplode.PushEntity(ent);
                streamExplode.PushProperties(ent);

                streamExplode.Stream(ent);
                streamExplode.PackageExplodedEntities();

                streamExplode.PopProperties();
                streamExplode.PopEntity();
                streamExplode.PopDisplayParameters();

                trans.Commit();
            }

            BlockReference blockRef = null;

            foreach (DBObject obj in objects)
            {
                if (obj.GetType() == typeof(BlockReference))
                {
                    blockRef = obj as BlockReference;
                }
            }

            if (blockRef == null)
            {
                return;
            }

            blockRef.Position = Point3d.Origin;

            using (Transaction trans = tm.StartTransaction())
            {
                BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                btr.AppendEntity(blockRef);
                trans.AddNewlyCreatedDBObject(blockRef, true);
                trans.Commit();
            }
        }
Пример #9
0
        private void StreamIntersectSample()
        {
            // intro message
            Editor editor = GetEditor();

            editor.WriteMessage("* StreamIntersect *\n");
            editor.WriteMessage("StreamIntersect detects intersections between two streams.\n");
            editor.WriteMessage("Pick two objects in the current drawing. The intersections will be highlighted and printed out in the output window.\n");

            // pick two objects
            ObjectId id1 = PickObject(typeof(Entity), false, "Please pick the first object");

            if (id1.IsNull)
            {
                editor.WriteMessage("No object is picked\n");
                return;
            }

            ObjectId id2;

            do
            {
                id2 = PickObject(typeof(Entity), false, "Please pick the second object");
                if (id2.IsNull)
                {
                    editor.WriteMessage("No object is picked\n");
                    return;
                }
            } while (id2 == id1);

            Database          db      = GetDatabase();
            IntPtr            ptr     = new IntPtr();
            StreamIntersect   stream1 = new StreamIntersect(db, ptr);
            StreamIntersect   stream2 = new StreamIntersect(db, ptr);
            Point3dCollection points  = new Point3dCollection();

            TransactionManager tm = db.TransactionManager;

            using (Transaction trans = tm.StartTransaction())
            {
                Entity ent1 = trans.GetObject(id1, OpenMode.ForRead) as Entity;
                Entity ent2 = trans.GetObject(id2, OpenMode.ForRead) as Entity;

                // put the entities in the streams respectively
                stream1.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);
                stream2.PushDisplayParameters(DictionaryDisplayConfiguration.GetStandardDisplayConfiguration(db), trans);
                stream1.Stream(ent1);
                stream2.Stream(ent2);

                // detect intersections
                int count = stream1.IntersectWith(stream2, points);

                stream1.PopDisplayParameters();
                stream2.PopDisplayParameters();

                trans.Commit();
            }

            // print and highlight the results
            editor.WriteMessage("\nHere are the intersections: " + points.Count + " in total\n");
            foreach (Point3d point in points)
            {
                editor.DrawVector(point, point, 1, true);
                editor.WriteMessage("(" + point.X + ", " + point.Y + ", " + point.Z + ")\n");
            }
        }