示例#1
0
        Stream(ArrayList data, PromptNestedEntityResult res)
        {
            data.Add(new Snoop.Data.ClassSeparator(typeof(PromptNestedEntityResult)));

            data.Add(new Snoop.Data.Object("Transform", res.Transform));
            data.Add(new Snoop.Data.ObjectIdCollection("Containers", res.GetContainers()));
        }
 internal PromptNestedEntityThroughViewportResult(PromptNestedEntityResult pneResult, ObjectId viewport)
 {
     m_status       = pneResult.Status;
     m_stringResult = pneResult.StringResult;
     m_pickPoint    = pneResult.PickedPoint;
     m_value        = pneResult.ObjectId;
     m_containers   = pneResult.GetContainers();
     m_mat          = pneResult.Transform;
     m_viewport     = viewport;
 }
 internal PromptNestedEntityThroughViewportResult(PromptNestedEntityResult pneResult)
 {
     m_status       = pneResult.Status;
     m_stringResult = pneResult.StringResult;
     m_pickPoint    = pneResult.PickedPoint;
     m_value        = pneResult.ObjectId;
     m_containers   = pneResult.GetContainers();
     m_mat          = pneResult.Transform;
     m_viewport     = Autodesk.AutoCAD.DatabaseServices.ObjectId.Null;
 }
示例#4
0
        highlightNestedEntity()
        {
            Document doc =
                Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            PromptNestedEntityResult rs =
                ed.GetNestedEntity("\nSelect nested entity: ");

            if (rs.Status == PromptStatus.OK)
            {
                ObjectId[] objIds = rs.GetContainers();
                ObjectId   ensel  = rs.ObjectId;
                int        len    = objIds.Length;

                // Reverse the "containers" list
                ObjectId[] revIds = new ObjectId[len + 1];
                for (int i = 0; i < len; i++)
                {
                    ObjectId id =
                        (ObjectId)objIds.GetValue(len - i - 1);
                    revIds.SetValue(id, i);
                }
                // Now add the selected entity to the end
                revIds.SetValue(ensel, len);

                // Retrieve the sub-entity path for this entity
                SubentityId subEnt =
                    new SubentityId(SubentityType.Null, (IntPtr)0);
                FullSubentityPath path =
                    new FullSubentityPath(revIds, subEnt);

                try
                {
                    using (Transaction tr = BaseObjs.startTransactionDb())
                    {
                        // Open the outermost container...
                        ObjectId id  = (ObjectId)revIds.GetValue(0);
                        Entity   ent =
                            (Entity)tr.GetObject(id, OpenMode.ForRead);
                        // ... and highlight the nested entity
                        ent.Highlight(path, false);
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " View.cs: line: 162");
                }
            }
        }
示例#5
0
        public void NestEntSelect()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor   ed  = doc.Editor;

            PromptNestedEntityOptions pneo = new PromptNestedEntityOptions(
                "\nSelect nested entity:");

            PromptNestedEntityResult nestedBlock = ed.GetNestedEntity(pneo);

            if (nestedBlock.Status != PromptStatus.OK)
            {
                return;
            }

            using (Transaction Tx = doc.TransactionManager.StartTransaction())
            {
                //Containers
                ObjectId[] containerIds = nestedBlock.GetContainers();

                foreach (ObjectId id in containerIds)
                {
                    DBObject container = Tx.GetObject(id, OpenMode.ForRead);

                    if (container is BlockReference)
                    {
                        BlockReference bref = container as BlockReference;

                        ed.WriteMessage("\nContainer: " + bref.BlockName);
                    }
                }

                Entity entity = Tx.GetObject(nestedBlock.ObjectId, OpenMode.ForRead)
                                as Entity;

                ed.WriteMessage("\nEntity: " + entity.ToString());

                ed.WriteMessage("\nBlock: " + entity.BlockName);

                BlockTableRecord btr = Tx.GetObject(entity.BlockId, OpenMode.ForRead)
                                       as BlockTableRecord;

                Tx.Commit();
            }
        }
示例#6
0
        private static void HighlightSubEntity(Document doc, PromptNestedEntityResult rs)
        {
            // Extract relevant information from the prompt object
            ObjectId selId = rs.ObjectId;

            ObjectId[] objIds = rs.GetContainers();

            int len = objIds.Length;

            // Reverse the "containers" list
            ObjectId[] revIds = new ObjectId[len + 1];
            for (int i = 0; i < len; i++)
            {
                ObjectId id = (ObjectId)objIds.GetValue(len - i - 1);
                revIds.SetValue(id, i);
            }

            // Now add the selected entity to the end
            revIds.SetValue(selId, len);

            // Retrieve the sub-entity path for this entity
            SubentityId subEnt = new SubentityId(SubentityType.Null, 0);

            FullSubentityPath path = new FullSubentityPath(revIds, subEnt);

            // Open the outermost container, relying on the open
            // transaction...

            ObjectId id2 = (ObjectId)revIds.GetValue(0);
            Entity   ent = id2.GetObject(OpenMode.ForRead) as Entity;

            // ... and highlight the nested entity
            if (ent != null)
            {
                ent.Highlight(path, false);
            }
        }
示例#7
0
        public bool SelectNestedEntitiesAuto(Editor ed, Point3d pos, out ObjectId id, out ObjectId[] ids, out string result, out Point3d point)
        {
            result = "";
            id     = ObjectId.Null;
            ids    = null;
            point  = default(Point3d);
            PromptNestedEntityResult nestedEntity = ed.GetNestedEntity(new PromptNestedEntityOptions("")
            {
                NonInteractivePickPoint    = pos,
                UseNonInteractivePickPoint = true
            });

            if (nestedEntity.Status == 5100)
            {
                id = nestedEntity.ObjectId;
                ObjectId        objectId = nestedEntity.ObjectId;
                List <ObjectId> list     = new List <ObjectId>(nestedEntity.GetContainers());
                list.Reverse();
                list.Add(objectId);
                ids   = list.ToArray();
                point = nestedEntity.PickedPoint;
            }
            return(nestedEntity.Status == 5100);
        }
示例#8
0
        public void NestedEntityTest()
        {
            ObjectIdCollection        coll    = new ObjectIdCollection();
            Editor                    ed      = Application.DocumentManager.MdiActiveDocument.Editor;
            PromptNestedEntityOptions entopts = new PromptNestedEntityOptions("prompt nested entity");

            entopts.AllowNone = true;
            entopts.Keywords.Add("Done");
            PromptNestedEntityResult ent = null;
            Database db = Application.DocumentManager.MdiActiveDocument.Database;

            Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;

            using (Transaction myT = tm.StartTransaction())
            {
                while (true)
                {
                    entopts.Message = "\nPick an entity of your choice from the drawing or type Done";

                    try
                    {
                        ent = ed.GetNestedEntity(entopts);
                    }
                    catch
                    {
                        ed.WriteMessage("\nYou did not select a valid nested entity");
                        break;
                    }
                    if (ent.Status == PromptStatus.Keyword)
                    {
                        if (ent.StringResult.Equals("Done"))
                        {
                            break;
                        }
                    }

                    try
                    {
                        if (ent.GetContainers().Length > 0)
                        {
                            Entity entity;
                            foreach (ObjectId oid in ent.GetContainers())
                            {
                                entity = (Entity)tm.GetObject(oid, OpenMode.ForRead, true);
                                ed.WriteMessage("You selected: " + entity.GetType().FullName);
                            }
                            break;
                        }
                        else
                        {
                            ed.WriteMessage("You did not select any nested entity");
                        }
                    }
                    catch
                    {
                        ed.WriteMessage("You are Done or did not select any nested entity");
                        myT.Commit();
                        return;
                    }
                }

                entopts.NonInteractivePickPoint    = new Point3d(30.4, 11.6, 0);
                entopts.UseNonInteractivePickPoint = true;

                try
                {
                    ent = ed.GetNestedEntity(entopts);
                    if (ent.GetContainers().Length > 0)
                    {
                        Entity entity;
                        foreach (ObjectId oid in ent.GetContainers())
                        {
                            entity = (Entity)tm.GetObject(oid, OpenMode.ForRead, true);
                            ed.WriteMessage(entity.GetType().FullName + " has been selected");
                        }
                    }
                    else
                    {
                        ed.WriteMessage("No nested entity was selected");
                    }
                }
                catch
                {
                    ed.WriteMessage("\nNo entity was selected");
                }
                myT.Commit();
            }
        }
示例#9
0
        OnPromptForEntityEnding(object sender, PromptForEntityEndingEventArgs e)
        {
            if (e.Result.Status == PromptStatus.OK)
            {
                Editor   ed    = sender as Editor;
                ObjectId objId = e.Result.ObjectId;
                Database db    = objId.Database;

                try
                {
                    using (Transaction tr = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database.TransactionManager.StartTransaction())
                    {
                        // First get the currently selected object and check whether it's a block reference
                        BlockReference br = tr.GetObject(objId, OpenMode.ForRead) as BlockReference;
                        if (br != null)
                        {
                            // If so, we check whether the block table record to which it refers is actually from an XRef
                            ObjectId         btrId = br.BlockTableRecord;
                            BlockTableRecord btr   = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
                            if (btr != null)
                            {
                                if (btr.IsFromExternalReference)
                                {
                                    // If so, then we programmatically select the object underneath the pick-point already used
                                    PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("");
                                    pneo.NonInteractivePickPoint    = e.Result.PickedPoint;
                                    pneo.UseNonInteractivePickPoint = true;

                                    PromptNestedEntityResult pner = ed.GetNestedEntity(pneo);

                                    if (pner.Status == PromptStatus.OK)
                                    {
                                        try
                                        {
                                            ObjectId selId = pner.ObjectId;

                                            // Let's look at this programmatically-selected object, to see what it is

                                            DBObject obj = selId.GetObject(OpenMode.ForRead);

                                            // If it's a polyline vertex, we need to go one level up to the polyline itself

                                            if (obj is PolylineVertex3d || obj is Vertex2d)
                                            {
                                                selId = obj.OwnerId;
                                            }

                                            // We don't want to do anything at all for textual stuff, let's also make sure we
                                            // are dealing with an entity (should always be the case)

                                            if (obj is MText || obj is DBText || !(obj is Entity))
                                            {
                                                return;
                                            }

                                            // Now let's get the name of the layer, to use later

                                            Entity           ent     = (Entity)obj;
                                            LayerTableRecord ltr     = (LayerTableRecord)tr.GetObject(ent.LayerId, OpenMode.ForRead);
                                            string           layName = ltr.Name;

                                            // Clone the selected object

                                            object o     = ent.Clone();
                                            Entity clone = o as Entity;

                                            // We need to manipulate the clone to make sure it works

                                            if (clone != null)
                                            {
                                                // Setting the properties from the block reference helps certain entities get the
                                                // right references (and allows them to be offset properly)
                                                clone.SetPropertiesFrom(br);

                                                // But we then need to get the layer information from the database to set the
                                                // right layer (at least) on the new entity

                                                LayerTable lt = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
                                                if (lt.Has(layName))
                                                {
                                                    clone.LayerId = lt[layName];
                                                }

                                                // Now we need to transform the entity for each of its Xref block reference containers
                                                // If we don't do this then entities in nested Xrefs may end up in the wrong place

                                                ObjectId[] conts = pner.GetContainers();
                                                foreach (ObjectId contId in conts)
                                                {
                                                    BlockReference cont = tr.GetObject(contId, OpenMode.ForRead) as BlockReference;
                                                    if (cont != null)
                                                    {
                                                        clone.TransformBy(cont.BlockTransform);
                                                    }
                                                }

                                                // Let's add the cloned entity to the current space

                                                BlockTableRecord space = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                                                if (space == null)
                                                {
                                                    clone.Dispose();
                                                    return;
                                                }

                                                ObjectId cloneId = space.AppendEntity(clone);
                                                tr.AddNewlyCreatedDBObject(clone, true);

                                                // Now let's flush the graphics, to help our clone get displayed

                                                tr.TransactionManager.QueueForGraphicsFlush();

                                                // And we add our cloned entity to the list for deletion

                                                _ids.Add(cloneId);

                                                // Created a non-graphical selection of our newly created object and replace it with
                                                // the selection of the container Xref

                                                IntPtr         ip = (IntPtr)0;
                                                SelectedObject so = new SelectedObject(cloneId, SelectionMethod.NonGraphical, ip);  //?????????????????????????????????
                                                e.ReplaceSelectedObject(so);
                                            }
                                        }
                                        catch (System.Exception ex)
                                        {
                                            BaseObjs.writeDebug(ex.Message + " xRefOffsetApp.cs: line: 259");
                                        }
                                    }
                                }
                            }
                        }
                        tr.Commit();
                    }
                }
                catch (System.Exception ex)
                {
                    BaseObjs.writeDebug(ex.Message + " xRefOffsetApp.cs: line: 270");
                }
            }
        }
示例#10
0
        getNestedEntity(string prompt, out bool escape, out Point3d pnt3dX, out string nameLayer, out FullSubentityPath path)
        {
            nameLayer = "";
            Entity   ent = null;
            Database db  = BaseObjs._db;

            path = new FullSubentityPath();

            Editor ed = BaseObjs._editor;

            PromptNestedEntityOptions pneo = new PromptNestedEntityOptions(prompt);
            PromptNestedEntityResult  pner = ed.GetNestedEntity(pneo);

            if (pner.Status == PromptStatus.Cancel || pner.Status == PromptStatus.None)
            {
                pnt3dX = Pub.pnt3dO;
                escape = true;
                return(null);
            }

            pnt3dX = pner.PickedPoint;

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    if (pner.Status == PromptStatus.OK)
                    {
                        escape = false;
                        ObjectId[] idsContainers = pner.GetContainers();
                        ObjectId   idSel         = pner.ObjectId;
                        int        len           = idsContainers.Length;

                        ObjectId[] idsRev = new ObjectId[len + 1];
                        //Reverse the "containers" list
                        for (int i = 0; i < len; i++)
                        {
                            ObjectId id = (ObjectId)idsContainers.GetValue(len - 1 - i);
                            idsRev.SetValue(id, i);
                        }
                        //Now add the selected entity to the end of the array
                        idsRev.SetValue(idSel, len);

                        //Retrieve the sub-entity path for this entity
                        SubentityId idSubEnt = new SubentityId(SubentityType.Null, (IntPtr)0);
                        path = new FullSubentityPath(idsRev, idSubEnt);

                        ObjectId idX = (ObjectId)idsRev.GetValue(0);
                        ent = (Entity)tr.GetObject(idX, OpenMode.ForRead);

                        ent.Highlight(path, false);

                        DBObject obj = idSel.GetObject(OpenMode.ForRead);

                        ObjectId idOwner = ObjectId.Null;

                        if (obj is PolylineVertex3d || obj is Vertex2d)
                        {
                            idOwner = obj.OwnerId;
                            ent     = (Entity)tr.GetObject(idOwner, OpenMode.ForRead);
                        }
                        else if (obj is MText || obj is DBText || !(obj is Entity))
                        {
                            return(ent);
                        }
                        else
                        {
                            ent = (Entity)obj;
                        }

                        object o     = ent.Clone();
                        Entity clone = (Entity)o;

                        if (clone != null)
                        {
                            //ObjectId[] conts = pner.GetContainers();
                            foreach (ObjectId idContainer in idsContainers)
                            {
                                BlockReference br = (BlockReference)idContainer.GetObject(OpenMode.ForRead);
                                if (br != null)
                                {
                                    clone.SetPropertiesFrom(br);
                                    clone.TransformBy(br.BlockTransform);
                                }
                            }

                            BlockTableRecord space = (BlockTableRecord)db.CurrentSpaceId.GetObject(OpenMode.ForWrite);
                            if (space == null)
                            {
                                clone.Dispose();
                                return(ent);
                            }
                            else if (clone is Arc)
                            {
                                Arc arc = (Arc)clone;
                                pnt3dX = arc.GetClosestPointTo(pnt3dX, false);
                            }
                            else if (clone is Line)
                            {
                                Line line = (Line)clone;
                                pnt3dX = line.GetClosestPointTo(pnt3dX, false);
                            }
                            else if (clone is Polyline)
                            {
                                Polyline poly = (Polyline)clone;
                                pnt3dX = poly.GetClosestPointTo(pnt3dX, false);
                            }
                            else
                            {
                                Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Selected item was of type: {0}.  Exiting...", clone.GetType().Name));
                            }
                            nameLayer = ent.Layer.ToString();

                            tr.Commit();

                            return(ent);
                        }
                    }
                    else
                    {
                        escape = true;
                    }
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xRef.cs: line: 842");
                escape = true;
            }
            return(ent);
        }
示例#11
0
        getNestedEntity(PromptEntityResult per, BlockReference br, bool makeCopy, out string nameLayer)
        {
            nameLayer = "";
            Entity   ent = null;
            Editor   ed  = BaseObjs._editor;
            Database db  = BaseObjs._db;
            PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("");

            pneo.NonInteractivePickPoint    = per.PickedPoint;
            pneo.UseNonInteractivePickPoint = true;

            PromptNestedEntityResult pner = ed.GetNestedEntity(pneo);

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    if (pner.Status == PromptStatus.OK)
                    {
                        ObjectId idSel = pner.ObjectId;
                        DBObject OBJ   = idSel.GetObject(OpenMode.ForRead);

                        if (OBJ is PolylineVertex3d || OBJ is Vertex2d)
                        {
                            idSel = OBJ.OwnerId;
                        }

                        if (OBJ is MText || OBJ is DBText || !(OBJ is Entity))
                        {
                            return(null);
                        }

                        ent = (Entity)OBJ;
                        if (makeCopy == true)
                        {
                            object o     = ent.Clone();
                            Entity clone = o as Entity;

                            if (clone != null)
                            {
                                clone.SetPropertiesFrom(br);

                                ObjectId[] conts = pner.GetContainers();
                                foreach (ObjectId idCont in conts)
                                {
                                    BlockReference cont = (BlockReference)idCont.GetObject(OpenMode.ForRead);
                                    if (cont != null)
                                    {
                                        clone.TransformBy(cont.BlockTransform);
                                    }
                                }

                                BlockTableRecord space = (BlockTableRecord)db.CurrentSpaceId.GetObject(OpenMode.ForWrite);
                                if (space == null)
                                {
                                    clone.Dispose();

                                    nameLayer = ent.Layer;
                                    return(null);
                                }
                                space.AppendEntity(clone);
                                tr.AddNewlyCreatedDBObject(clone, true);
                                tr.Commit();

                                nameLayer = ent.Layer.ToString();
                                return(clone);
                            }
                        }
                        else
                        {
                            return(ent);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xRef.cs: line: 715");
            }
            return(ent);
        }
示例#12
0
        public void QB()
        {
            PromptEntityOptions selectCalloutOptions;
            PromptEntityResult  selectedCalloutResults;

            string         msAndKwds;
            string         kwds;
            string         verbose = "default";
            BlockReference blkRef  = null;
            //string station;
            //string lineNumber;

            //need editor to prompt user
            Editor ed = doc.Editor;

            //Prompt options for running line
            PromptNestedEntityOptions promptRunningLineOpt = new PromptNestedEntityOptions("\nSelect Running Line");

            //must select an object
            promptRunningLineOpt.AllowNone = false;
            PromptNestedEntityResult runningLineResults = ed.GetNestedEntity(promptRunningLineOpt);

            if (runningLineResults.Status != PromptStatus.OK)
            {
                return;
            }
            //only allow polylines
            if (runningLineResults.GetType() != typeof(Polyline))
            {
                ed.WriteMessage("\nObject selected not Running Line ");
            }
            //prompt for line number
            PromptStringOptions pStrOpts = new PromptStringOptions("\nEnter Line Number: ");

            pStrOpts.AllowSpaces = false;
            PromptResult pStrRes = ed.GetString(pStrOpts);

            if (pStrRes.Status != PromptStatus.OK)
            {
                return;
            }

            /******************************************************
            *  prompt user to select block
            ******************************************************/
            PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("\nSelect DFWT Block");

            pneo.AllowNone = false;

            //check prompt results from user else return
            PromptNestedEntityResult nestedBlock = ed.GetNestedEntity(pneo);

            if (nestedBlock.Status != PromptStatus.OK)
            {
                return;
            }

            while (true)
            {
                Transaction trans = database.TransactionManager.StartTransaction();
                using (trans)
                {
                    //access block table and create block table record
                    BlockTable       bt  = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable;
                    BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;

                    //get the running line
                    Polyline runningLine = trans.GetObject(runningLineResults.ObjectId, OpenMode.ForRead) as Polyline;

                    ObjectId[] containerIds = nestedBlock.GetContainers();

                    foreach (ObjectId id in containerIds)
                    {
                        DBObject container = trans.GetObject(id, OpenMode.ForRead);

                        if (container is BlockReference)
                        {
                            blkRef = container as BlockReference;
                            ed.WriteMessage("\nContainer: " + blkRef.BlockName);

                            if (blkRef.Name == "CPR")
                            {
                                //maybe call the dropdown menu????
                                break;
                            }
                        }
                    }

                    string str = String.Format("{0:0}", runningLine.GetDistAtPoint(blkRef.Position));
                    switch (str.Length)
                    {
                    case 1:
                        str = "0+0" + str;
                        break;

                    case 2:
                        str = "0+" + str;
                        break;

                    default:
                        str = str.Substring(0, str.Length - 2) + "+" + str.Substring(str.Length - 2);
                        break;
                    }

                    if (pStrRes.StringResult != "")
                    {
                        str = str + " LINE " + pStrRes.StringResult;
                    }

                    //
                    selectCalloutOptions = new PromptEntityOptions("\n Select Type: ");
                    switch (blkRef.Name.ToUpper())
                    {
                    case "CPR":
                        //msAndKwds = "\nSelect Type:[Drop Bucket/Tap pedestal/Splitter Pedestal]";
                        //kwds = "'Drop Bucket' 'Tap Pedestal' 'Tap Splitter'";

                        selectCalloutOptions.Keywords.Add("Drop bucket");
                        selectCalloutOptions.Keywords.Add("Tap pedestal");
                        selectCalloutOptions.Keywords.Add("Splitter pedestal");


                        selectedCalloutResults = ed.GetEntity(selectCalloutOptions);

                        switch (selectedCalloutResults.StringResult.ToUpper())
                        {
                        case "DROP BUCKET":
                            verbose = DROP_BUCKET;
                            break;

                        case "TAP PEDESTAL":
                            verbose = TAP_PED;
                            break;

                        default:
                            break;
                        }

                        break;

                    case "CPS":
                        break;

                    default:
                        ed.WriteMessage(blkRef.BlockName);
                        break;
                    }

                    //.string msAndKwds = "\nCPR or [A/B/C]";
                    //string kwds = "Apple Bob Cat";
                    //peo.SetMessageAndKeywords(msAndKwds, kwds);
                    //ed.WriteMessage(per1.StringResult);

                    /************************************************************************************************
                     *			Prompting for callout box insertion point
                     *			Set geometry for placing box
                     ***********************************************************************************************/
                    PromptPointOptions pPtOpt = new PromptPointOptions("\nEnter Insertion Point");
                    PromptPointResult  pPtRes = ed.GetPoint(pPtOpt);
                    Point3d            insPt  = pPtRes.Value;

                    CoordinateSystem3d cs = Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.CoordinateSystem3d;
                    Plane plane           = new Plane(Point3d.Origin, cs.Zaxis);

                    //create polyline
                    Polyline rec = new Polyline();
                    rec.AddVertexAt(0, insPt.Convert2d(plane), 0, 0, 0);

                    bool Xdir = true;
                    bool Ydir = true;

                    if (insPt.X < blkRef.Position.X)
                    {
                        Xdir = false;
                    }
                    //

                    if (insPt.Y < blkRef.Position.Y)
                    {
                        Ydir = false;
                    }

                    if (Xdir)
                    {
                        if (Ydir)
                        {
                            //quadrant I
                            rec.AddVertexAt(0, new Point2d(insPt.X + recLength, insPt.Y), 0, 0, 0);
                            rec.AddVertexAt(1, new Point2d(insPt.X + recLength, insPt.Y + recWidth), 0, 0, 0);
                            rec.AddVertexAt(2, new Point2d(insPt.X, insPt.Y + recWidth), 0, 0, 0);
                        }
                        else
                        {
                            //quadrant IV
                            rec.AddVertexAt(0, new Point2d(insPt.X + recLength, insPt.Y), 0, 0, 0);
                            rec.AddVertexAt(1, new Point2d(insPt.X + recLength, insPt.Y - recWidth), 0, 0, 0);
                            rec.AddVertexAt(2, new Point2d(insPt.X, insPt.Y - recWidth), 0, 0, 0);
                        }
                    }
                    else
                    {
                        if (Ydir)
                        {
                            //quadrant II
                            rec.AddVertexAt(0, new Point2d(insPt.X - recLength, insPt.Y), 0, 0, 0);
                            rec.AddVertexAt(1, new Point2d(insPt.X - recLength, insPt.Y + recWidth), 0, 0, 0);
                            rec.AddVertexAt(2, new Point2d(insPt.X, insPt.Y + recWidth), 0, 0, 0);
                        }
                        else
                        {
                            //quadrant III
                            rec.AddVertexAt(0, new Point2d(insPt.X - recLength, insPt.Y), 0, 0, 0);
                            rec.AddVertexAt(1, new Point2d(insPt.X - recLength, insPt.Y - recWidth), 0, 0, 0);
                            rec.AddVertexAt(2, new Point2d(insPt.X, insPt.Y - recWidth), 0, 0, 0);
                        }
                    }
                    rec.Closed = true;
                    rec.SetDatabaseDefaults();

                    /************************************************************************************************
                     *			Add object to block table and Commit Transaction
                     *
                     ***********************************************************************************************/

                    MText mt = new MText();
                    mt.Contents = verbose;

                    btr.AppendEntity(rec);
                    btr.AppendEntity(mt);

                    trans.AddNewlyCreatedDBObject(rec, true);
                    trans.AddNewlyCreatedDBObject(mt, true);
                    trans.Commit();
                }

                return;
            }
        }
示例#13
0
文件: xRef2.cs 项目: 15831944/EM
        getNestedEntityAndHighlight(Point3d pnt3d, BlockReference br, out FullSubentityPath path, out bool isClosed)
        {
            Entity ent = null;

            isClosed = false;
            path     = new FullSubentityPath();

            Editor ed = BaseObjs._editor;

            PromptNestedEntityOptions pneo = new PromptNestedEntityOptions("");

            pneo.NonInteractivePickPoint    = pnt3d;
            pneo.UseNonInteractivePickPoint = true;
            PromptNestedEntityResult pner = ed.GetNestedEntity(pneo);

            try
            {
                using (Transaction tr = BaseObjs.startTransactionDb())
                {
                    if (pner.Status == PromptStatus.OK)
                    {
                        ObjectId[] idsContainers = pner.GetContainers();
                        ObjectId   idSel         = pner.ObjectId;
                        int        len           = idsContainers.Length;

                        ObjectId[] idsRev = new ObjectId[len + 1];
                        //Reverse the "containers" list
                        for (int i = 0; i < len; i++)
                        {
                            ObjectId id = (ObjectId)idsContainers.GetValue(len - i - 1);
                            idsRev.SetValue(id, i);
                        }
                        //Now add the selected entity to the end of the array
                        idsRev.SetValue(idSel, len);

                        //Retrieve the sub-entity path for this entity
                        SubentityId idSubEnt = new SubentityId(SubentityType.Null, (IntPtr)0);
                        path = new FullSubentityPath(idsRev, idSubEnt);

                        ObjectId idX = (ObjectId)idsRev.GetValue(0);
                        ent = (Entity)tr.GetObject(idX, OpenMode.ForRead);

                        DBObject obj = idSel.GetObject(OpenMode.ForRead);

                        ObjectId idOwner   = ObjectId.Null;
                        DBObject objParent = null;

                        if (obj is PolylineVertex3d)
                        {
                            idOwner   = obj.OwnerId;
                            objParent = (Polyline3d)idOwner.GetObject(OpenMode.ForRead);
                            Polyline3d poly3d = (Polyline3d)obj;
                            poly3d.Highlight(path, false);
                            isClosed = poly3d.Closed;
                        }
                        else if (obj is Vertex2d)
                        {
                            idOwner   = obj.OwnerId;
                            objParent = (Polyline)idOwner.GetObject(OpenMode.ForRead);
                            Polyline poly = (Polyline)obj;
                            poly.Highlight(path, false);
                            isClosed = poly.Closed;
                        }
                        else if (obj is Polyline3d)
                        {
                            objParent = obj;
                            Polyline3d poly3d = (Polyline3d)obj;
                            poly3d.Highlight(path, false);
                            isClosed = poly3d.Closed;
                        }
                        else if (obj is Polyline)
                        {
                            objParent = obj;
                            Polyline poly = (Polyline)obj;
                            poly.Highlight(path, false);
                            isClosed = poly.Closed;
                        }
                        else if (obj is Arc)
                        {
                            objParent = obj;
                            Arc arc = (Arc)obj;
                            arc.Highlight(path, false);
                            isClosed = false;
                        }
                        else if (obj is MText || obj is DBText)
                        {
                            return(null);
                        }

                        ent = (Entity)objParent;
                    }
                    tr.Commit();
                }
            }
            catch (System.Exception ex)
            {
                BaseObjs.writeDebug(ex.Message + " xRef2.cs: line: 108");
            }
            return(ent);
        }