Close all colored Layers

Source: Internet
Author: User
Close all colored Layers

/* Close all colored layers.
*
* When there are a lot of color spots, It is troublesome to do it one by one. This time it is completely off, and then it is very easy to switch between layers with the layer state saving function.
*
* Http://goat.cublog.cn
* Author: Wang Xiaodong QQ: 10516321 Email: xiaook@gmail.com
*
*/
Using Autodesk. AutoCAD. applicationservices;
Using Autodesk. AutoCAD. databaseservices;
Using Autodesk. AutoCAD. editorinput;
Using Autodesk. AutoCAD. runtime;

/*Copyright © CHINA 2009

AutoCAD version:AutoCAD 2006
Description:

To use DelectObjectsInWindowPolyline.dll:

1. Start AutoCAD and open a new drawing.
2. Type netload and select CloseLayerHasHatchSolid.dll.
3. Execute the xqd command.*/

namespace CloseLayerHasHatchSolid
{
    /// <summary>

    /// Summary for Class1.

    /// </summary>

    public class Class1
    {

        [CommandMethod("xcl")]
        public void xcl()
        {
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
            Database acDb = acDoc.Database;
            ObjectIdCollection acObjIdColl = new ObjectIdCollection();

// Select the range line

Typedvalue [] TV = new typedvalue [2];
TV [0] = new typedvalue (INT) dxfcode. Start, "hatch ");
TV [1] = new typedvalue (INT) dxfcode. shapename, "solid ");
Selectionfilter Sf = new selectionfilter (TV );
Promptselectionresult acptres = acdoced. selectall (SF );
Objectidcollection oidcol = new objectidcollection ();

            if (acPtRes.Status == PromptStatus.OK)
            {
                SelectionSet ss = acPtRes.Value;
                oIdCol = new ObjectIdCollection(ss.GetObjectIds());
            }
            foreach (ObjectId oid in oIdCol)
            {
                using (Transaction acTrans = acDb.TransactionManager.StartTransaction())
                {
                    Entity ent = (Entity)acTrans.GetObject(oid, OpenMode.ForRead);
                    LayerTable lt;
                    lt = (LayerTable)acTrans.GetObject(acDb.LayerTableId, OpenMode.ForRead);
                    LayerTableRecord ltr = (LayerTableRecord)acTrans.GetObject(lt[ent.Layer], OpenMode.ForWrite);
                    ltr.IsOff = true;
                    acTrans.Commit();
                }
            }
        }
    }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.