Kean Walmsley


  • About the Author
    Kean on Google+

April 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      







« Getting the names of the colors in an AutoCAD color-book using .NET | Main | Launching AutoCAD from a .NET application »

December 12, 2007

Creating an AutoCAD Wipeout using .NET

This topic was suggested via a comment from Dale Bartlett on this post.

In AutoCAD 2008 an API was exposed for the Wipeout object. For those of you who aren't familiar with Wipeouts: this handy object was originally developed as part of the AutoCAD Express Tools, and has since been integrated into core AutoCAD. The implementation uses a raster image of the same colour as the drawing canvas to "wipe out" the graphics behind it (assuming it's nearer the front in terms of draw order relative to the entities being masked). This is the main reason the Wipeout class is derived from RasterImage in the managed API.

The RasterImage-based implementation was chosen at a time when True Color support was not available through AutoCAD's graphics interface (a.k.a. AcGi for the ObjectARX coders reading this). Since then it has been altogether possible to implement Wipeouts without using RasterImage: you can simply use the AcGi protocol to create the same effect. But that's history - once the Wipeout class became widely used it was unfeasible to change the implementation and introduce an incompatibility. On a design note: if the raster had been contained rather that derived from, the choice would have been simpler (an implementation detail, rather than something affecting the class hierarchy in AutoCAD). The design choice was probably due to the capabilities of the ObjectARX API at the time the object was originally developed - containment was inherently more complicated that derivation, back then. Anyway, I digress.

The below C# code shows how to create a Wipeout based on an array of points - in this case we simply make it square, from 0,0 to 100,100. The tricky part is to make sure we close the wipeout manually by specifying the first vertex again as the last point in the list - something Dale and I discovered independently when researching this.

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Geometry;


namespace WipeoutApplication

{

  public class Commands

  {

    [CommandMethod("CW")]

    public void CreateWipeout()

    {

      Document doc =

        Application.DocumentManager.MdiActiveDocument;

      Database db = doc.Database;


      Transaction tr =

        db.TransactionManager.StartTransaction();

      using (tr)

      {

        BlockTable bt =

          (BlockTable)tr.GetObject(

            db.BlockTableId,

            OpenMode.ForRead,

            false

          );

        BlockTableRecord btr =

          (BlockTableRecord)tr.GetObject(

            bt[BlockTableRecord.ModelSpace],

            OpenMode.ForWrite,

            false

          );


        Point2dCollection pts =

          new Point2dCollection(5);


        pts.Add(new Point2d(0.0, 0.0));

        pts.Add(new Point2d(100.0, 0.0));

        pts.Add(new Point2d(100.0, 100.0));

        pts.Add(new Point2d(0.0, 100.0));

        pts.Add(new Point2d(0.0, 0.0));


        Wipeout wo = new Wipeout();

        wo.SetDatabaseDefaults(db);

        wo.SetFrom(pts, new Vector3d(0.0, 0.0, 0.1));


        btr.AppendEntity(wo);

        tr.AddNewlyCreatedDBObject(wo, true);

        tr.Commit();

      }

    }

  }

}

TrackBack

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

Listed below are links to weblogs that reference Creating an AutoCAD Wipeout using .NET:

blog comments powered by Disqus

10 Random Posts