Пример #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
    //  create a display config with a little more information filled.
    private DisplayConfiguration CreateDisplayConfig()
    {
        Database    db    = Application.DocumentManager.MdiActiveDocument.Database;
        Transaction trans = db.TransactionManager.StartTransaction();

        DisplayRepresentationManager drm      = new DisplayRepresentationManager(db);
        ObjectId             currentDisConfId = drm.DisplayConfigurationIdForCurrentViewport;
        DisplayConfiguration currentDisConf   = trans.GetObject(currentDisConfId, OpenMode.ForRead) as DisplayConfiguration;

        DisplayConfiguration dc = new DisplayConfiguration();

        try
        {
            DisplaySet ds = new DisplaySet();
            ds.SetToStandard(db);
            ds.SubSetDatabaseDefaults(db);

            //  top
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 0, 1), DictionaryDisplaySet.GetStandardPlanId(db)));
            //  for bottom. No DictionaryDisplaySet.GetStandardXxxId for Plan Diagnostic, so get it from the name.
            ObjectId id = DictionaryDisplaySet.GetStandardSet("Plan Diagnostic", db);
            if (id != ObjectId.Null)
            {
                dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 0, -1), id));
            }
            else  // if not found, let's use Reflected.
            {
                dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 0, -1), DictionaryDisplaySet.GetStandardReflectedId(db)));  //buttom
            }
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(-1, 0, 0), DictionaryDisplaySet.GetStandardSectionElevId(db))); // left
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(1, 0, 0), DictionaryDisplaySet.GetStandardSectionElevId(db)));  // right
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, -1, 0), DictionaryDisplaySet.GetStandardSectionElevId(db))); //  front
            dc.ViewDependentCombinations.Add(new ViewDependentCombination(new Vector3d(0, 1, 0), DictionaryDisplaySet.GetStandardSectionElevId(db)));  // back

            //  try adding DefaultViewDependentViewSet here.
            dc.DefaultViewDependentViewSet = DictionaryDisplaySet.GetStandardModelId(db);

            DictionaryDisplayConfiguration dictDisplayConfigs = new DictionaryDisplayConfiguration(db);
            string newName = GetNewName();
            dictDisplayConfigs.AddNewRecord(newName, dc);
            trans.AddNewlyCreatedDBObject(dc, true);
            trans.Commit();
        }
        catch (System.Exception)
        {
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
        return(dc);
    }
Пример #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++);
            }
        }
Пример #4
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);
            }
        }
Пример #5
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);
        }
Пример #6
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);
            }
        }
Пример #7
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");
        }
Пример #8
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);
        }
Пример #9
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();
            }
        }
Пример #10
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");
            }
        }
Пример #11
0
    ////////////////////////////
    //// Display Configuration
    ////////////////////////////

    private void DisplayConfigs()
    {
        //' access the display system from the database object

        Database    db    = Application.DocumentManager.MdiActiveDocument.Database;
        Transaction trans = db.TransactionManager.StartTransaction();

        try
        {
            // Access the display system from the document object
            DictionaryDisplayConfiguration dictDisplayConfigs = new DictionaryDisplayConfiguration(db);

            // The total number of display configurations registered.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + dictDisplayConfigs.Records.Count + " display configs:\n");

            // List them
            foreach (ObjectId dcId in dictDisplayConfigs.Records)
            {
                DisplayConfiguration dc = trans.GetObject(dcId, OpenMode.ForWrite) as DisplayConfiguration;
                Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Name : " + dc.Name + "\n" +
                                                                                  "Description :  " + dc.Description + "\n");
            }

            // Add a new config with the name "MyConfig" with a description in it.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLet's add a new DisplayConfiguration:\n");
            DisplayConfiguration displayconfig = new DisplayConfiguration();
            displayconfig.Description = "This is MyConfig";
            if (!dictDisplayConfigs.Has("MyConfig", trans))
            {
                dictDisplayConfigs.AddNewRecord("MyConfig", displayconfig);
                trans.AddNewlyCreatedDBObject(displayconfig, true);
            }

            // Add another one "FORUSE1"
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(displayconfig.Name + " : " + displayconfig.Description + "\n");
            DisplayConfiguration displayconfig1 = new DisplayConfiguration();
            displayconfig1.Description = "This is for use";
            if (!dictDisplayConfigs.Has("FORUSE1", trans))
            {
                dictDisplayConfigs.AddNewRecord("FORUSE1", displayconfig1);
                trans.AddNewlyCreatedDBObject(displayconfig1, true);
            }

            //    rename MyConfig to a new name MyNewConfigureXxx
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLet's rename this new DisplayConfiguration:\n");
            string newName = GetNewName();
            dictDisplayConfigs.Rename("MyConfig", newName, trans);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("After Renamed:\nName: " + displayconfig.Name + "\nDescription: " + displayconfig.Description + "\n");


            //    report the total number of display config again.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("There are " + dictDisplayConfigs.Records.Count + " display configurations now.\n");

            //    the ObjectId of the new disp config?
            ObjectId nid = dictDisplayConfigs.GetAt(newName);
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The current ObjectId for new display configuration is:" + nid.ToString() + "\n");

            //    the current active config?
            DisplayRepresentationManager drm      = new DisplayRepresentationManager(db);
            ObjectId             currentDisConfId = drm.DisplayConfigurationIdForCurrentViewport;
            DisplayConfiguration currentDisConf   = trans.GetObject(currentDisConfId, OpenMode.ForRead) as DisplayConfiguration;
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("The Current DisplayConfiguration is " + currentDisConf.Name + "\n");
            ListDisplayConfig(currentDisConf);

            //    create a new disp config with more detailed information.
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Let's create a new DisplayConfiguration for detail:\n");
            DisplayConfiguration newDc = CreateDisplayConfig();

            //    print it out
            ListDisplayConfig(newDc);

            trans.Commit();
        }
        catch (System.Exception e)
        {
            Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Exception: " + e.Message + "\n");
            trans.Abort();
        }
        finally
        {
            trans.Dispose();
        }
    }