Cad.net Adding and removing layer filters

Source: Internet
Author: User

Using Autodesk.AutoCAD.ApplicationServices;

Using Autodesk.AutoCAD.DatabaseServices;

Using Autodesk.AutoCAD.EditorInput;

Using Autodesk.AutoCAD.Runtime;

Using Autodesk.AutoCAD.LayerManager;

Namespace Layerfilters

{

public class Commands

{

[Commandmethod ("Llfs")]

static public void Listlayerfilters ()

{

Document doc =

Application.DocumentManager.MdiActiveDocument;

Database db = Doc. Database;

Editor ed = doc. Editor;

//List the nested layer filters

layerfiltercollection LFC =

Db. LayerFilters.Root.NestedFilters;

For (int i = 0; i < LFC. Count; ++i)

{

layerfilter lf = lfc[i];

Ed. Writemessage (

"\n{0}-{1} (Can{2} be deleted)",

i + 1,

Lf. Name,

(LF.) AllowDelete? " ": "not")

);

}

}

[Commandmethod ("CLFS")]

static public void Createlayerfilters ()

{

Document doc =

Application.DocumentManager.MdiActiveDocument;

Database db = Doc. Database;

Editor ed = doc. Editor;

Try

{

//Get The existing layer filters

//(we'll add to them and set them back)

Layerfiltertree lft =

Db. Layerfilters;

layerfiltercollection LFC =

LfT. Root.nestedfilters;

//Create three new layer filters

layerfilter lf1 = new layerfilter ();

Lf1. Name = "Unlocked Layers";

Lf1. FilterExpression = "locked==\" false\ "";

layerfilter lf2 = new layerfilter ();

Lf2. Name = "White Layers";

Lf2. FilterExpression = "color==\" 7\ "";

layerfilter lf3 = new layerfilter ();

Lf3. Name = "Visible Layers";

Lf3. FilterExpression =

" off==\" false\ "and frozen==\" false\ "";

//ADD them to the collection

Lfc. ADD (LF1);

Lfc. ADD (LF2);

Lfc. ADD (LF3);

//Set them back on the Database

Db. Layerfilters = LFT;

//List The layer filters, to see the new ones

Listlayerfilters ();

}

catch (Exception ex)

{

Ed. Writemessage (

"\nexception: {0}",

Ex. Message

);

}

}

[Commandmethod ("DLF")]

static public void Deletelayerfilter ()

{

Document doc =

Application.DocumentManager.MdiActiveDocument;

Database db = Doc. Database;

Editor ed = doc. Editor;

Listlayerfilters ();

Try

{

//Get The existing layer filters

//(we'll add to them and set them back)

Layerfiltertree lft =

Db. Layerfilters;

layerfiltercollection LFC =

LfT. Root.nestedfilters;

//Prompt for the index of the filter to delete

Promptintegeroptions pio =

new promptintegeroptions (

"\n\nenter index of filter to delete"

);

Pio. Lowerlimit = 1;

Pio. Upperlimit = lfc. Count;

Promptintegerresult PIR =

Ed. Getinteger (PIO);

//Get the selected filter

layerfilter lf = Lfc[pir. VALUE-1];

//If It ' s possible to delete it

if (!LF. AllowDelete)

{

Ed. Writemessage (

"\nlayer filter cannot be deleted."

);

}

Else

{

Lfc. Remove (LF);

Db. Layerfilters = LFT;

Listlayerfilters ();

}

}

catch (Exception ex)

{

Ed. Writemessage (

"\nexception: {0}",

Ex. Message

);

}

}

}

}

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.