Ejemplo n.º 1
0
Archivo: xRef2.cs Proyecto: 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);
        }