Пример #1
0
        private static bool IsProtectedLayer(ObjectId obase)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;
            var db  = doc.Database;
            var tr  = db.TransactionManager.StartTransaction();


            using (tr)
            {
                var obj =
                    tr.GetObject(obase, OpenMode.ForRead);

                var lwp = obj as Polyline;

                /*Change the Layer Color*/

                LayerManager.ChangeLayerColor
                    (db, lwp.Layer, PLineToLayers.AssignLayerColor(lwp));

                if (!(lwp.Layer.ToUpper() == "ORO"))
                {
                    tr.Commit();
                    return(true);
                }
                tr.Commit();
            }

            return(false);
        }
Пример #2
0
        private static void ChangeLayerColorFor3LetterName(ObjectId pobj)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;
            var db  = doc.Database;
            var tr  = db.TransactionManager.StartTransaction();


            using (tr)
            {
                var obj =
                    tr.GetObject(pobj, OpenMode.ForWrite);

                var lwp = obj as Polyline;

                /*Change the Layer Color*/
                if (lwp != null)
                {
                    LayerManager.ChangeLayerColor
                        (db, lwp.Layer, PLineToLayers.AssignLayerColor(lwp));
                }


                tr.Commit();
            }
        }
Пример #3
0
        public static void InteratePolyLines(ObjectId selectedObjectId)
        {
            var doc = Application.DocumentManager.MdiActiveDocument;
            var ed  = doc.Editor;
            var db  = doc.Database;
            var tr  = db.TransactionManager.StartTransaction();

            // Get the current UCS

            var ucs =
                ed.CurrentUserCoordinateSystem.CoordinateSystem3d;

            using (tr)
            {
                var obj =
                    tr.GetObject(selectedObjectId, OpenMode.ForRead);


                // If a "lightweight" (or optimized) polyline

                var lwp = obj as Polyline;

                /*Change the Layer Color*/
                if (lwp != null)
                {
                    LayerManager.ChangeLayerColor
                        (db, lwp.Layer, PLineToLayers.AssignLayerColor(lwp));
                }

                if (lwp != null)
                {
                    // Is Polyline Closed
                    if (!lwp.Closed)
                    {
                        lwp.UpgradeOpen();
                        lwp.Color = Color.FromColorIndex(ColorMethod.ByColor, 1);
                        CreateDrawingErrorReferences(lwp.StartPoint, lwp.EndPoint, db, ucs);
                        LayerManager.ChangeLayerColor(db, lwp.Layer, PLineToLayers.AssignLayerColor(lwp));
                        lwp.DowngradeOpen();
                    }
                    // Use a for loop to get each vertex, one by one

                    var vn = lwp.NumberOfVertices;

                    for (var i = 0; i < vn; i++)
                    {
                        // Could also get the 3D point here

                        var pt = lwp.GetPoint2dAt(i);

                        ed.WriteMessage("\n" + pt);
                    }
                }

                else
                {
                    // If an old-style, 2D polyline

                    var p2d = obj as Polyline2d;

                    if (p2d != null)
                    {
                        // Use foreach to get each contained vertex

                        foreach (ObjectId vId in p2d)
                        {
                            var v2d =
                                (Vertex2d)tr.GetObject(
                                    vId,
                                    OpenMode.ForRead
                                    );

                            ed.WriteMessage(
                                "\n" + v2d.Position
                                );
                        }
                    }

                    else
                    {
                        // If an old-style, 3D polyline

                        var p3d = obj as Polyline3d;

                        if (p3d != null)
                        {
                            // Use foreach to get each contained vertex

                            foreach (ObjectId vId in p3d)
                            {
                                var v3d =
                                    (PolylineVertex3d)tr.GetObject(
                                        vId,
                                        OpenMode.ForRead
                                        );

                                ed.WriteMessage(
                                    "\n" + v3d.Position
                                    );
                            }
                        }
                    }
                }

                // Committing is cheaper than aborting

                tr.Commit();
            }
        }