@j@y123 Ответов: 0

Печать слоя на чертеже с использованием определенного цвета.


using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;

namespace NAL_Layer11
{
    public class class1
    {
        [CommandMethod("NLCL")]
        public static void PurgeLayers()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            Transaction tr = doc.Database.TransactionManager.StartTransaction();
            var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
            PromptPointResult ppr;
            PromptPointOptions ppo = new PromptPointOptions("");
            ppo.Message = "\n Select the place for print output:";
            //get the coordinates from user
            ppr = ed.GetPoint(ppo);
            if (ppr.Status != PromptStatus.OK)
                return;
            Point3d startPoint = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);

            Vector3d disp = new Vector3d(0.0, -2.0 * db.Textsize, 0.0);
            //Vector3d disp2 = new Vector3d(0.0, -2.0 * db.Textsize, 0.0);

            TextStyleTable ts = (TextStyleTable)tr.GetObject(db.TextStyleTableId, OpenMode.ForRead);
            ObjectId mtStyleid = db.Textstyle;
            if (ts.Has("NAL-TEXT"))
            {
                mtStyleid = ts["NAL-FORMAT"];
            }

            // using (Transaction tr =
            //  db.TransactionManager.StartTransaction())
            {
                LayerTable table = tr.GetObject(db.LayerTableId,
                    OpenMode.ForRead) as LayerTable;

                ObjectIdCollection layIds = new ObjectIdCollection();
                foreach (ObjectId id in table)
                {
                    layIds.Add(id);
                }

                //this function will remove all
                //layers which are used in the drawing file
                db.Purge(layIds);
                MText mtext1 = new MText();
                mtext1.Location = startPoint;
                mtext1.TextStyleId = mtStyleid;
                // mtext1.Contents = "The unauthorized layers are:";
                mtext1.Width = 85.000;
                mtext1.Height = 2.000;
                mtext1.Contents = "{\\C1;The unauthorized layers are:}\\P";
                curSpace.AppendEntity(mtext1);
                tr.AddNewlyCreatedDBObject(mtext1, true);
                db.TransactionManager.QueueForGraphicsFlush();

                foreach (ObjectId id in layIds)
                {
                    DBObject obj = tr.GetObject(id, OpenMode.ForWrite);
                    obj.Erase();
                }

                SymbolTable symTable = (SymbolTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);

                // mtext.Contents = "The unauthorized layers are:";
                foreach (ObjectId id in symTable)
                {
                    ColorDialog cd = new ColorDialog();
                    LayerTableRecord symbol = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);

                    if (symbol.Name.StartsWith("NL"))
                    {
                        // ed.WriteMessage("The authorized layres are:" + symbol.Name);
                    }
                    else
                    {
                       
                        MText mtext = new MText();
                        mtext.Contents = "\n" + symbol.Name;
                        mtext.Location = startPoint;
                        mtext.Width = 75.207;
                        mtext.Height = 1.488;
                        mtext.TextStyleId = mtStyleid;
                        curSpace.AppendEntity(mtext);
                        tr.AddNewlyCreatedDBObject(mtext, true);
                        db.TransactionManager.QueueForGraphicsFlush();
                        startPoint += disp;
                    }
                }
                tr.Commit();
            }
        }
    }
}


Что я уже пробовал:

Это мой код, который возвращает мне некоторые слои, и я хочу отобразить эти слои в моем dwg-файле, чтобы я мог правильно просматривать слои на моем чертеже.

0 Ответов