Example #1
0
        private static void extractContours(Surface surf)
        {
            if (surf is TinSurface)
            {
                if (surf.IsReferenceObject)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(string.Format("Surface {0} is from {1}", surf.Name, surf.OwnerId.ToString()));
                    return;
                }
                TinSurface   tinSurf  = (TinSurface)surf;
                string       nameSurf = tinSurf.Name;
                ObjectId     idStyle  = tinSurf.StyleId;
                SurfaceStyle style    = Surf_Styles.getSurfaceStyle(idStyle);

                double majorInt = style.ContourStyle.MajorContourInterval;
                double minorInt = style.ContourStyle.MinorContourInterval;

                DisplayStyle planDispStyle = style.GetDisplayStylePlan(SurfaceDisplayStyleType.MajorContour);
                string       majorLay      = planDispStyle.Layer;

                planDispStyle = style.GetDisplayStylePlan(SurfaceDisplayStyleType.MinorContour);
                string minorLay = planDispStyle.Layer;

                ObjectIdCollection idsContours = tinSurf.ExtractContours(minorInt);

                Color color = new Color();
                color = Color.FromColorIndex(ColorMethod.ByLayer, 256);

                using (Transaction tr = BaseObjs.startTransactionDb()) {
                    foreach (ObjectId id in idsContours)
                    {
                        Polyline poly = (Polyline)tr.GetObject(id, OpenMode.ForRead);
                        double   elev = System.Math.Round(poly.Elevation, 2);
                        if ((elev / majorInt).mantissa() == 0)
                        {
                            id.changeProp(color, majorLay, LineWeight.LineWeight030);
                        }
                        else
                        {
                            id.changeProp(color, minorLay, LineWeight.LineWeight020);
                        }
                    }
                    tr.Commit();
                }
            }
        }