October 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 31  










« Using augmented reality to preview the output of 123D Creature | Main | Kinect Fusion released today! »

March 15, 2013

2D vs. 3D graphics system inside AutoCAD (+ request for information)

Everyone who uses AutoCAD – even if they use it exclusively in one or the other mode – knows that it’s capable of being used to generate both 2D drawings and 3D models. Not everyone realises there are actually two distinct graphics systems in the product, however. (At least at the time of writing, talking about AutoCAD 2013… I’m not making predictions, for people reading this from the future. :-)

A 2D and 3D character, almost certainly not inside AutoCAD

The 2D graphics system is known as WHIP and has been around – albeit with regular enhancements – since the days of R13. You know if you’re using WHIP if the current Visual Style is set to “2D Wireframe”. What’s sometimes a little confusing is that WHIP is also 3D-capable: it’s not as though everything appears flattened onto the XY plane when WHIP is enabled, for instance. But it is focused on – and highly optimised for – working with 2D data.

The 3D graphics system has been in the product – again, with various incremental improvements, release-on-release – since AutoCAD 2007. For the sake of this post we’re going to refer to the 3D GS as AGS (AutoCAD Graphics System). You know if you’re using AGS if the current Visual Style is set to anything other than “2D Wireframe”.

Programmatically it’s possible to check whether you’re using WHIP or AGS via one simple API: if the result of calling Document.GraphicsManager.GetGsView() (making sure you pass “false” as the second argument, as we don’t want to create a new view) is null, then you know you’re using WHIP, otherwise you’re using AGS.

[Many developers who care whether they’re in WHIP or AGS are working with ObjectARX from C++, a requirement for implementing custom entities: these developers will check whether acgsGetGsView() returns NULL. This is, of course, the underlying unmanaged API that is wrapped by the .NET API mentioned above.]

Here’s some simple C# code that reports whether you’re in 2D or 3D (from a GS perspective, that is):

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.GraphicsSystem;

using Autodesk.AutoCAD.Runtime;

 

namespace GSTest

{

  public class Commands

  {

    [CommandMethod("GGS")]

    public void GetGS()

    {

      var doc = Application.DocumentManager.MdiActiveDocument;

      var ed = doc.Editor;

 

      short vpn = (short)Application.GetSystemVariable("CVPORT");

      View v = doc.GraphicsManager.GetGsView(vpn, false);

 

      ed.WriteMessage(

        "\nGraphics system is {0}D.", v == null ? "2" : "3"

      );

    }

  }

}

Running the GGS command should report “Graphics system is 2D” when using WHIP (i.e. with Visual Style is “2D Wireframe”) and “Graphics system is 3D” when using AGS (i.e. with any other Visual Style).

As these graphics systems have different capabilities – such as the way graphics are displayed – it’s sometimes important for applications to be aware of whether the current graphics system is WHIP or AGS. This is something that’s pretty common for applications with complex graphics – the AutoCAD-based verticals are examples of these – but it’s something we’d like to understand better and reduce the need for. Our ideal scenario would be to provide a unified graphics API that doesn’t require any knowledge of the specific, underlying GS.

Now we’ve worked through the preamble, here’s what I’m interested in knowing… Does your application at any point check whether it is in the 2D or 3D graphics system? If so, why does it need to know (i.e. what does the application use the information for)? The gist of the question I’m really asking is this: what capabilities would you therefore like to see generalised across both graphics system implementations? (Please send me an email, assuming you don’t want to post this information in a blog comment for the world to see. :-)

To be clear, I don’t actually expect many people will respond to this, as this is quite a niche area for developers who are making heavy use of custom graphics (whether via custom entities or overrules). But then I may well be surprised, and any information in this area would certainly help the AutoCAD team a great deal.

photo credit: audiovisualjunkie via photopin cc

blog comments powered by Disqus

Feed/Share

10 Random Posts