Example #1
0
        public static List <LineSegment3d> getLines(ObjectId[] ids)
        {
            List <LineSegment3d> ll = new List <LineSegment3d>();

            try
            {
                PLDictionary plDic = new PLDictionary();
                // Get the current document and database
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;
                Editor   ed      = acDoc.Editor;
                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (ids[i].ObjectClass != RXClass.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line)))
                        {
                            continue;
                        }
                        Autodesk.AutoCAD.DatabaseServices.Line line = acTrans.GetObject(ids[i], OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Line;

                        ll.Add(new LineSegment3d(line.StartPoint, line.EndPoint));
                    }
                    ll = ll.Distinct(new My.CompareLineSegment3d()).ToList();// as

                    acTrans.Commit();
                }
            }
            catch (System.Exception ex)
            {
            }
            return(ll);
        }
Example #2
0
        public static List <Point3d> getBo(DBObjectCollection dbCol)
        {
            if (dbCol == null)
            {
                return(null);
            }
            List <Point3d> plist = new List <Point3d>();

            try
            {
                List <Autodesk.AutoCAD.DatabaseServices.Line> ll = new List <Autodesk.AutoCAD.DatabaseServices.Line>();
                PLDictionary plDic = new PLDictionary();
                for (int i = 0; i < dbCol.Count; i++)
                {
                    ll.Add(dbCol[i] as Autodesk.AutoCAD.DatabaseServices.Line);
                }
                ll = ll.Distinct(new My.CompareLine()).ToList();
                plDic.Add(ll);
                KeyValuePair <Point3d, Vector2d>?kvp = plDic.getLeftMost();
                if (kvp == null)
                {
                    return(null);
                }
                Point3d  startP = kvp.Value.Key;
                Point3d  curP   = kvp.Value.Key;
                Vector2d curV   = kvp.Value.Value;

                plist.Add(curP);
                int maxLoopCount = plDic.Count;
                while (maxLoopCount-- > 0)
                {
                    Point3d?p = plDic.getMaxAnglePoint(curP, curV);
                    //ed.DrawVectors()
                    if (p == null)
                    {
                        break;
                    }
                    if (p.Value == startP)
                    {
                        break;
                    }
                    curV = new Vector2d(curP.X - p.Value.X, curP.Y - p.Value.Y);
                    curP = p.Value;

                    plist.Add(p.Value);
                }
            }
            catch (System.Exception ex)
            {
            }
            return(plist);
        }
Example #3
0
        //ng:获得计算边界时所用的起点
        public static Point3d?getBoStartPoint(Point3d innerP, List <Autodesk.AutoCAD.DatabaseServices.Line> ll, PLDictionary plDic)
        {
            Autodesk.AutoCAD.DatabaseServices.Line resultL = new Autodesk.AutoCAD.DatabaseServices.Line();

            Point3d?resultP = null;

            if (ll == null)
            {
                return(null);
            }

            double intersectPointX = innerP.X;

            for (int i = 0; i < ll.Count; i++)
            {
                Point3d?p = getIntersectPoint2d(innerP.Y, ll[i]);
                if (p == null)
                {
                    continue;
                }
                if (resultP == null && p.Value.X > innerP.X)
                {
                    intersectPointX = p.Value.X;
                    resultL         = ll[i];
                }
                else
                {
                    if (p.Value.X > innerP.X && p.Value.X < intersectPointX)
                    {
                        intersectPointX = p.Value.X;
                        resultL         = ll[i];
                    }
                }
            }
            if (resultL.StartPoint.X < resultL.EndPoint.X)
            {
                resultP = resultL.StartPoint;
            }
            else
            {
                resultP = resultL.EndPoint;
            }
            return(resultP);
        }
Example #4
0
 public static KeyValuePair <Point3d, Vector2d>?getLeftMost(Point3d innerP, List <Autodesk.AutoCAD.DatabaseServices.Line> ll, PLDictionary plDic)
 {
     try
     {
         Point3d? startP = Utility2d.getBoStartPoint(innerP, ll, plDic);
         Vector2d?startV = plDic.getStartVector(startP);
         if (startV == null)
         {
             return(null);
         }
         return(new KeyValuePair <Point3d, Vector2d>(startP.Value, startV.Value));
     }
     catch (System.Exception ex)
     {
     }
     return(null);
 }
Example #5
0
        //从直线集合中计算外围边界,直线在相交处都是打断的。得出的边界用点列表表示
        public static List <Point3d> getOuterBoundaryFromLine(ObjectId[] ids, Point3d?innerP)
        {
            List <Point3d> ret = null;

            try
            {
                PLDictionary plDic = new PLDictionary();
                // Get the current document and database
                Document acDoc   = Application.DocumentManager.MdiActiveDocument;
                Database acCurDb = acDoc.Database;
                Editor   ed      = acDoc.Editor;
                // Start a transaction
                using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
                {
                    // Open the Block table for read
                    BlockTable acBlkTbl;
                    acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                                 OpenMode.ForRead) as BlockTable;
                    // Open the Block table record Model space for write
                    BlockTableRecord acBlkTblRec;
                    acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                                    OpenMode.ForWrite) as BlockTableRecord;
                    List <Autodesk.AutoCAD.DatabaseServices.Line> ll = new List <Autodesk.AutoCAD.DatabaseServices.Line>();
                    DBObjectCollection acDBObjColl = new DBObjectCollection();
                    for (int i = 0; i < ids.Length; i++)
                    {
                        if (ids[i].ObjectClass != RXClass.GetClass(typeof(Autodesk.AutoCAD.DatabaseServices.Line)))
                        {
                            continue;
                        }
                        Autodesk.AutoCAD.DatabaseServices.Line line = acTrans.GetObject(ids[i], OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Line;

                        ll.Add(line);
                    }
                    ll = ll.Distinct(new My.CompareLine()).ToList();// as List<Autodesk.AutoCAD.DatabaseServices.Line>;
                    plDic.Add(ll);
                    KeyValuePair <Point3d, Vector2d>?kvp = null;
                    if (innerP == null)
                    {
                        kvp = plDic.getLeftMost();//外部边界起始
                    }
                    else
                    {
                        //内部边界起始
                        kvp = Utility2d.getLeftMost(innerP.Value, ll, plDic);
                    }

                    if (kvp == null)
                    {
                        return(null);
                    }
                    Point3d        startP = kvp.Value.Key;
                    Point3d        curP   = kvp.Value.Key;
                    Vector2d       curV   = kvp.Value.Value;
                    List <Point3d> plist  = new List <Point3d>();
                    plist.Add(curP);
                    int maxLoopCount = plDic.Count;
                    while (maxLoopCount-- > 0)
                    {
                        Point3d?p = plDic.getMaxAnglePoint(curP, curV);
                        //ed.DrawVectors()
                        if (p == null)
                        {
                            break;
                        }
                        if (p.Value == startP)
                        {
                            break;
                        }
                        curV = new Vector2d(curP.X - p.Value.X, curP.Y - p.Value.Y);
                        curP = p.Value;

                        plist.Add(p.Value);
                    }
                    ret = plist;

                    acTrans.Commit();
                }
            }
            catch (System.Exception ex)
            {
            }
            return(ret);
        }