September 2014

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        








« Mardi Gras, Super Tuesday and F# | Main | Modifying the color, linetype and lineweight of an AutoCAD entity using standard dialogs from .NET »

February 08, 2008

Using standard AutoCAD dialogs to select colors, linetypes and lineweights with .NET

AutoCAD has a number of handy dialogs available in the "Autodesk.AutoCAD.Windows" namespace. The following code shows how to use three, in particular: ColorDialog, LinetypeDialog and LineWeightDialog. These three classes allow you to very easily implement user-interfaces selecting their corresponding properties.

Here's the C# code:

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Windows;


namespace AutoCADDialogs

{

  public class Commands

  {

    [CommandMethod("CDL")]

    public void ShowColorDialog()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;

      Editor ed = doc.Editor;


      ColorDialog cd = new ColorDialog();

      System.Windows.Forms.DialogResult dr =

        cd.ShowDialog();

      if (dr == System.Windows.Forms.DialogResult.OK)

      {

        ed.WriteMessage(

          "\nColor selected: " +

          cd.Color.ToString()

        );

      }

    }


    [CommandMethod("LTDL")]

    public void ShowLinetypeDialog()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;

      Editor ed = doc.Editor;


      LinetypeDialog ltd = new LinetypeDialog();

      System.Windows.Forms.DialogResult dr =

        ltd.ShowDialog();

      if (dr == System.Windows.Forms.DialogResult.OK)

      {

        ed.WriteMessage(

          "\nLinetype selected: " +

          ltd.Linetype.ToString()

        );

      }

    }


    [CommandMethod("LWDL")]

    public void ShowLineWeightDialog()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;

      Editor ed = doc.Editor;


      LineWeightDialog lwd = new LineWeightDialog();

      System.Windows.Forms.DialogResult dr =

        lwd.ShowDialog();

      if (dr == System.Windows.Forms.DialogResult.OK)

      {

        ed.WriteMessage(

          "\nLineweight selected: " +

          lwd.LineWeight.ToString()

        );

      }

    }

  }

}

When we run the CDL command, we have three tabs available:

Color_dialog_1

Color_dialog_2

Color_dialog_3

Here's the dialog shown by the LTDL command:

Linetype_dialog

And the LWDL command:

Lineweight_dialog

And here is the command-line output for selecting each of the above items:

Command: CDL

Color selected: 91

Command: CDL

Color selected: 56,166,199

Command: CDL

Color selected: DIC 266

Command: LTDL

Linetype selected: (2130316464)

Command: LWDL

Lineweight selected: LineWeight009

In the next post we'll look at at how to use these dialogs in a more realistic way.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d83452464869e200e5503a4fa18834

Listed below are links to weblogs that reference Using standard AutoCAD dialogs to select colors, linetypes and lineweights with .NET:

blog comments powered by Disqus

Feed/Share

10 Random Posts