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();
}
}
}
}
}