Jump to content
tigger29900

change layer color using .net

Recommended Posts

tigger29900

I have been trying to work out a quick solution to a problem using .net but have been stumped by my lack of knowledge in programming. I need to write an app/plugin for autocad that will change the color of a layer when a checkbox is checked. I have been able to set up the user form but i am not sure how to code the actual changing of layer colors. Another feature i am trying to incorporate is the output filtering of the text contained on the layer which have had their colors changed to build an effect equipment list

 

Any help would be greatly appreciated

Share this post


Link to post
Share on other sites
Jeff H

Here is a little something to get you started where you enter a color index to change all layers.

Took out little bit for checking IsDependent, etc..... for handling xref layers

 

 [CommandMethod("ChangeAllLayersColor")]
       public void ChangeAllLayersColor()
       {
           PromptIntegerOptions pio = new PromptIntegerOptions("\nPlease enter color index for xref colors");
           pio.LowerLimit = 1;
           pio.UpperLimit = 255;
           PromptIntegerResult pir = Ed.GetInteger(pio);
           if (pir.Status != PromptStatus.OK)
           {
               return;
           }
           short index = (short)pir.Value;
           using (Transaction trx = Db.TransactionManager.StartTransaction())
           {
               
               LayerTable lt = (LayerTable)trx.GetObject(Db.LayerTableId, OpenMode.ForRead);

               foreach (ObjectId ltrId in lt)
               {
                   LayerTableRecord ltr = (LayerTableRecord)trx.GetObject(ltrId, OpenMode.ForRead, false, true);
                   if (ltr.Color.ColorIndex != index)
                   {
                       if (ltrId != Db.LayerZero)
                       {                          
                           ltr.UpgradeOpen();
                           ltr.Color = Color.FromColorIndex(ColorMethod.ByAci, index);
                       }
                   }
               }
               trx.Commit();
           }
       }

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...