コード例 #1
0
        protected override IEnumerable <CheckResult> CheckImpl(IEnumerable <Autodesk.AutoCAD.DatabaseServices.ObjectId> selectedObjectIds)
        {
            var result = new List <AntiClockwisePolygonCheckResult>();

            if (!selectedObjectIds.Any())
            {
                return(result);
            }

            var database = selectedObjectIds.First().Database;

            using (var tr = database.TransactionManager.StartTransaction())
            {
                foreach (var objectId in selectedObjectIds)
                {
                    var pline = tr.GetObject(objectId, OpenMode.ForRead);
                    if (pline == null)
                    {
                        continue;
                    }

                    bool bIsCloseWise = false;
                    if (pline is Polyline)
                    {
                        bIsCloseWise = CurveUtils.IsPolygonClockWise(pline as Polyline);
                    }
                    else if (pline is Polyline2d)
                    {
                        bIsCloseWise = CurveUtils.IsPolygonClockWise(pline as Polyline2d, tr);
                    }
                    else
                    {
                        continue;
                    }

                    if (!bIsCloseWise)
                    {
                        result.Add(new AntiClockwisePolygonCheckResult(objectId));
                    }
                }

                tr.Commit();
            }
            return(result);
        }