Through the Interface

April 2015

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    


April 03, 2015

Autodesk Cloud Accelerator v2 | Updated developer portal

Thanks for all the interactions, yesterday. April 1st is really one of my favourite days of the year: there’s lightheartedness and creative energy everywhere you look. But all good things come to an end – even if the years seem to tick by increasingly quickly – so it’s time for more serious matters.

Today’s post shares a couple of updates related to Autodesk’s burgeoning PaaS layer…

Autodesk Cloud Accelerator v2Firstly, the inaugural Autodesk Cloud Accelerator turned out to be wildly successful: both for the external people who attended – there were 12 proposals selected from a pool of 50, with developers focused with a fairly even split between the View & Data, BIM 360, AutoCAD I/O and ReCap Photo APIs – and the Autodesk employees supporting them.

I’ve heard from a number of people that this type of activity – where you spend 2 intensive weeks kick-starting the project and working through those early, often gnarly issues – is extremely rewarding for all involved. Our engineering teams got some great, actionable feedback, for instance.

Based on such a positive experience we’ve already planned to hold another one, (once again) in Autodesk’s San Francisco office from June 1st-12th, 2015. Head on over to the Cloud & Mobile DevBlog – or to the accelerator’s web-site – for more details, but do bear in mind that the proposal deadline is already looming: youAutodesk Web Services Platform portal have to submit a proposal by April 19th to qualify.

Secondly, the Autodesk Web Services Platform portal has been revamped.

You’ll find updated documentation, live sample code and testimonials from developers who are already working with our web-service APIs.

Something else to point out is the streamlined application process: people requesting an application key to use the View & Data API or AutoCAD I/O (or both) no longer have to wait for an actual person (or even multiple people) at Autodesk to approve the application. Once you’ve provided the few pieces of information that are required you’ll be notified immediately of your consumer key and secret.

All in all the experience of working with Autodesk’s Web Services Platform is getting easier, and we intend to make it more so, over time. If you haven’t already, it’s time to take a look!

April 01, 2015

Autodesk SoCap

SoCap logo

I’m excited to announce the newest member of the Autodesk product portfolio, Autodesk SoCap. The term “SoCap” stands for “Software Capture”, in much the same way as ReCap stands for “Reality Capture”. SoCap is a tool that helps you capture existing software behaviour as code, just as ReCap helps you capture a 3D scene as a point cloud.

For SoCap to do its thing, you point it at the piece of software whose behaviour you want to capture – whether desktop software on Windows/Linux/OS X, mobile software targeting iOS/Android* or the URL of a cloud-based app – and SoCap will then create a C++, C# or HTML/JavaScript source project that, once built, will perform much like the original.

[* We expect to support Windows Phone sometime later in the year – probably to coincide with the Windows 10 launch. Also, the exported source project currently targets Visual Studio: at some point we expect to support other IDEs such as Xcode and Android Studio.]

Sounds magical? It actually is pretty amazing. Under the hood, SoCap works by performing dynamic analysis on program modules and by performing a comprehensive suite of automated, runtime UI tests. Graphical output is captured frame by frame, correlated with UI input and then fed into a cloud-based expert system with codified rules built up over decades. (This may sound a little old-fashioned, but then we did start this project over 20 years ago… if it was “born in the cloud” I’d no doubt be talking about our extensive use of machine learning and big data. :-)

The system generates a set of source files that can be used to build your own comparable software product with minimal effort. The resulting source project won’t have 100% of the functionality of the captured software – there’s still some program logic that’s just too obscure to be inferred in this way – but SoCap is a great way to get 90-95% of the way there with modest cost.

Coding factory

Before SoCap it took large teams of talented coders to re-implement complex software products.

This is a very different product for Autodesk to release in that it relates to the process of software development rather than “real world” design and engineering. The closest comparable product I can remember is Hyperwire, which was developed by our Kinetix division, back in the mid-90s, and allowed you to write Java applets using a visual programming interface.

So why now – what has driven the decision to make this available externally? I liken the move to Facebook open-sourcing tools such as Flow and Torch. People generally don’t understand why Facebook does such things, but it no doubt feels good to them and few people externally are complaining.

It just felt like the right time to donate this capability back to the software development community: for years Autodesk was very much a “fast follower” when it came to technology – taking groundbreaking technology developed by others in the industry and making it available at lower cost… democratizing it – but in recent years we’ve shifted strategic focus on becoming a technology leader. As you will see from our investments in BIM, Reality Computing, 3D printing and cloud-based 3D design tools.

Which means our need for reverse engineering rapid application development tools has reduced, as these days we spend our R&D budget on genuine innovation rather than copying imitating replicating standing on the shoulders of other players in the industry.

But wait – couldn’t this tool be used to imitate Autodesk software tools? Well, yes, it could be used by unscrupulous competitors to develop lower cost alternatives, but we’re confident in our ability to keep ahead of the game. We’re just that arrogant good at what we do. That and the fact we’ve hardcoded the tools not to work when pointed at any software coming from Autodesk.

I’ll be posting a download link to Autodesk SoCap as soon as it’s publicly available – watch this space. In the meantime, do start thinking about the non-Autodesk software tool you’d most like to rip-off take after. Here’s a list of Autodesk’s competitors (according to Yahoo! Finance) to get the creative juices flowing.

photo credit: spring 2012 hackNY student hackathon presentations via photopin(license)

March 30, 2015

AutoCAD 2016: Calling commands from external events using .NET

Last week we introduced the ExecuteInCommandContextAsync() method and saw it in action from a context menu click event. In today’s post we’re going to see how it can be used for a lot more: we’re going to use it to respond to external, operating system-level events (although admittedly we’re handling the event in-process to AutoCAD via .NET).

What we’re actually going to do is fire off a command inside AutoCAD – in our case we’re going to use RECTANG to create square polylines – each time we find that a file has been placed in a particular folder (in our case “c:\temp\files”, although the actually location isn’t particularly important).

Here’s what we’re aiming for – this recording shows AutoCAD on the left and an Explorer window pointed at “c:\temp\files” on the right.

A FileSystemWatcher feeding AutoCAD

Of course the specific event we’re responding to – in our case the Changed event  on a FileSystemWatcher – isn’t really the point. The point is that this mechanism allows you to react to things happening outside AutoCAD, calling AutoCAD commands in reaction.

Here’s the C# code, to show how it’s working. Something to bear in mind… we’re only adding squares until there are as many as files in the tracked folder: more work would be needed to remove squares as files get deleted or moved away. But this is simply an example of hooking such an event into AutoCAD – I didn’t see much point in adding that kind of complexity to the code.

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;

using System;

using System.IO;


namespace CommandFromAppContext


  public class Commands


    const int columns = 10;

    const string path = "c:\\temp\\files";


    private FileSystemWatcher _fsw = null;

    private int _fileNum = 0;

    private int _filesTotal = 0;

    private bool _drawing = false;



    public void EventCommand()


      var dm = Application.DocumentManager;

      var doc = dm.MdiActiveDocument;

      if (doc == null)



      var ed = doc.Editor;


      // We'll start by creating one square for each file in the

      // specified location. The nSquares() function uses some

      // global state for the index and the total count


      _fileNum = 0;

      _filesTotal = Directory.GetFiles(path).Length;




      // Create a FileSystemWatcher for the path, looking for

      // write changes and drawing more squares as needed


      if (_fsw == null)


        _fsw = new FileSystemWatcher(path, "*.*");

        _fsw.Changed += (o, s) => nSquaresInContext(dm, ed, path);

        _fsw.NotifyFilter = NotifyFilters.LastWrite;

        _fsw.EnableRaisingEvents = true;


        ed.WriteMessage("\nWatching \"{0}\" for changes.", path);





    public void StopEventCommand()


      var dm = Application.DocumentManager;

      var doc = dm.MdiActiveDocument;

      if (doc == null)



      var ed = doc.Editor;


      if (_fsw != null)



        _fsw = null;



      ed.WriteMessage("\nNo longer watching folder.");



#pragma warning disable 1998


    private async void nSquaresInContext(

      DocumentCollection dc, Editor ed, string path



      // We'll set the total as it may well have changed (hence the

      // need for global state rather than using an argument)


      _filesTotal = Directory.GetFiles(path).Length;


      // Protect the command-calling function with a flag to avoid

      // eInvalidInput failures


      if (!_drawing)


        _drawing = true;


        // Call our square creation function asynchronously


        await dc.ExecuteInCommandContextAsync(

          async (o) => nSquares(ed),




        _drawing = false;




#pragma warning restore 1998


    private void nSquares(Editor ed)


      // Draw squares until we have enough (the total might

      // change, hence the need for global state)


      for (; _fileNum < _filesTotal; _fileNum++)


        // Determine the position in our grid


        int xoff = _fileNum % columns,

            yoff = _fileNum / columns;


        // Create our polyline via the RECTANG command




          String.Format("{0},{1}", xoff, yoff),

          String.Format("{0},{1}", xoff + 1, yoff + 1),







I think this is a really powerful mechanism. I’d be very curious to hear how people anticipate using it with AutoCAD 2016.

March 27, 2015

NuGet packages now available for AutoCAD 2016

Some time ago we posted the NuGet packages for AutoCAD 2015’s .NET API. The packages for AutoCAD 2016 are now live, too.

Here’s the report from the NuGet console (accessible in Visual Studio via Tools –> NuGet Package Manager –> Package Manager Console).

PM> Get-Package -filter AutoCAD.NET -ListAvailable


Id                   Version    Description/Release Notes

--                   -------    -------------------------

AutoCAD.NET          20.1.0     AutoCAD 2016 API

AutoCAD.NET.Core     20.1.0     AutoCAD 2016 core object model API

AutoCAD.NET.Model    20.1.0     AutoCAD 2016 drawing object model API

To install the 2016 versions of the assemblies into your project, you can use the following command, once again in the NuGet Console.

PM> Install-Package AutoCAD.NET -Version 20.1

And the 2015 are still available too, of course:

PM> Install-Package AutoCAD.NET -Version 20.0

I actually just learned a nice trick: you can use tab to autocomplete the version number inside the NuGet console, as you can see below. Very handy!

NuGet package manager console with autocomplete

I hadn’t realised there was a 20.0.1 version posted – I’ll check in on that and report its significance.

As promised last time, on Monday we’ll look at another possible use of DocumentCollection.ExecuteInCommandAsync() in AutoCAD 2016.


It turns out 20.0.1 was a very minor bugfix. There were some versioning issues with 20.0.0 and we’d also omitted the Brep API’s .NET assembly from that version.

March 25, 2015

AutoCAD 2016: Calling commands from AutoCAD events using .NET

It’s time to start looking in more detail at some of the new API capabilities in AutoCAD 2016. To give you a sense of what to expect in terms of a timeline, this week we’ll look at a couple of uses for DocumentCollection.ExecuteInCommandContextAsync() and next week we’ll look at point cloud floorplan extraction and (hopefully) security and signing.

The first use of ExecuteInCommandContextAsync() I wanted to highlight was one raised in a blog comment a couple of months ago. The idea is simple enough: we want to be able to launch a command reliably from an event handler, in our case the Click event of a ContextMenuExtension’s MenuItem. Before now you would have to use Document.SendStringToExecute(), as we saw in this previous post – calling a command in another way would typically lead to an eInvalidInput exception.

There are certainly advantages to avoiding SendStringToExecute() in this scenario: while commands that use the pickfirst selection set are OK – including ones you implement yourself – using Command() or CommandAsync() gives you greater control over which entities you choose to pass entities to the command being called (whether it accepts pickfirst selection or not).

By the way, as mentioned briefly in a comment on the last post, in AutoCAD 2015 you will find the DocumentCollection.BeginExecuteInCommandContext() method, which was the former name for ExecuteInCommandContextAsync() (it’s taken from the ObjectARX method it calls through to). If you try to make the below code work in AutoCAD 2015 with the previous method name, you’re probably going to hit this error: ‘Unknown command: “EXECUTEFUNCTION”’.

Before we look at the code, here’s a recording of what we want it to do:

Context menu to scale by 5

It’s pretty simple in concept, at least. Here’s the C# code that makes it work:

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Geometry;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Windows;

using System;


namespace ContextMenuApplication


  public class Commands : IExtensionApplication


    public void Initialize()




    public void Terminate()






  public class ScaleMenu


    private static ContextMenuExtension cme;


    public static void Attach()


      if (cme == null)


        cme = new ContextMenuExtension();

        MenuItem mi = new MenuItem("Scale by 5");

        mi.Click += new EventHandler(OnScale);



      RXClass rxc = Entity.GetClass(typeof(Entity));

      Application.AddObjectContextMenuExtension(rxc, cme);



    public static void Detach()


      RXClass rxc = Entity.GetClass(typeof(Entity));

      Application.RemoveObjectContextMenuExtension(rxc, cme);



    private static async void OnScale(Object o, EventArgs e)


      var dm = Application.DocumentManager;

      var doc = dm.MdiActiveDocument;

      var ed = doc.Editor;


      // Get the selected objects


      var psr = ed.GetSelection();

      if (psr.Status != PromptStatus.OK)





        // Ask AutoCAD to execute our command in the right context


        await dm.ExecuteInCommandContextAsync(

          async (obj) =>


            // Scale the selected objects by 5 relative to 0,0,0


            await ed.CommandAsync(

              "._scale", psr.Value, "", Point3d.Origin, 5






      catch (System.Exception ex)


        ed.WriteMessage("\nException: {0}\n", ex.Message);





We might have used Editor.Command() rather than Editor.CommandAsync(), but ExecuteInCommandContextAsync() is expecting an asynchronous task to be passed in, so doing so would lead to a warning about the async lambda running synchronously. Ultimately it works comparably, but the above code makes the C# compiler happier, so I’ve left it that way. I’ve also chosen to await the call to ExecuteInCommandContextAsync(), although for this type of operation it’s probably not strictly needed.

In the next post we’re going to take a look at calling AutoCAD commands based on external events: we’re going to hook up a FileSystemWatcher to check for changes to a folder and call a command inside AutoCAD each time a file gets created there.

March 23, 2015

AutoCAD 2016 for developers

After our quick look at AutoCAD 2016 from a user perspective, let’s now spend some time looking at the things important to developers in this latest release.


Off the bat it’s worth stating that AutoCAD 2016 is a DWG compatible release: it’s using the same file format as AutoCAD 2013, 2014 and 2015. It’s also a binary application compatible release: ObjectARX apps written for AutoCAD 2015 should work in 2016 and it’s likely that .NET apps built for AutoCAD 2014 will work, too. That said, some changes have been made to the security model for this release of AutoCAD, so you may want to make sure these changes haven’t impacted your application…


You’ll see straight away when you try to load your application that there’s a bit more going on in the 2016 version of this dialog.

Security dialog in AutoCAD 2016

Firstly, the word “unsigned” indicates something very important: we’re encouraging developers to sign their executables – and even their LISP files – to improve security. An increasing number of AutoCAD customers – often the larger ones, as you might expect – are requiring application modules to be signed. This is certainly a topic that’s worth go into more deeply in a future post.

The other addition to the dialog is the “Always load this application” checkbox. This tells AutoCAD to continue loading this module from a non-trusted location, with the caveat that if the module changes the user will be prompted again.

A number of sysvars related to AutoCAD’s security features can now be locked by CAD managers:

  • TRUSTEDDOMAINS (see update below)
  • ACADLSPASDOC (see update below)

LEGACYCODESEARCH is important to note: AutoCAD’s default “find file” behaviour has been changed neither to search the current working folder nor the folder of the active drawing. This will make it much harder for people to write viruses that travel around with AutoCAD drawings.

On the subject of sysvars, I do think the System Variable Monitor – which we mentioned last time – will be a useful diagnostic tool for developers. If you know you’re using sysvars in your code – such as CMDECHO, CMDDIA, FILEDIA, etc. – try adding them to the monitor and see whether you get any notifications about your commands not setting them back properly. If you get any you can bet your users will, too.

Sysvar monitor

Now let’s take a look at the new .NET API features (equivalent – and in a few cases more – functionality is also available via ObjectARX).

Reality computing

A number of point cloud-related features have been added to the product and are also available via the API.

You can create point cloud extension definitions (PointCloudDefEx objects) by attaching .RCS/.RCP files. These are analogous to block definitions. You can also create point cloud extension entities (PointCloudEx objects) that “insert” these into the drawing. A whole slew of properties and methods are exposed from both these classes.

A number of capabilities have been added relating to extraction of features from point clouds. Firstly, the Section class now has a “slice” type, and can be used to slice through a point cloud. Correspondingly it’s possible to use a PointCloudCrop object to crop a point cloud relative to a plane.

Even silly point clouds can be sectioned

The extraction itself can also be driven programmatically. I’ve put together a sample that performs an extraction and adds the extracted geometry to the drawing: we’ll take a look at that in an upcoming post.


A number of capabilities related to the newly introduced RapidRT rendering system have been added to the API in this release. You can add and control image-based lighting, for instance, as well as managing the various settings related to RapidRT.

As this is a binary application compatible release, when we change an API significantly we make sure we do so via a new class until we can safely break API compatibility in a future release. So there’s a new Autodesk.AutoCAD.GraphicsSystem.Manager2 class which contains GetOffScreenDevice() and GetOffScreenView() methods making use of the RapidRT engine.


Here’s a quick round-up of some of the more interesting miscellaneous API enhancements in this release…

The Spline.ToPolyline() method has a couple of new Boolean parameters allowing you to specify that you wish to create arc segments as well as requesting the generation of lightweight polylines.

The Dimension.TextDefinedSize property allows you to control the width associated with long dimension text.

The MText class has a couple of new properties: ContentsRTF allows you to extract a version of the contents in Rich Text Format, while ShowBorders allows you to query or control whether an MText object’s borders are visible.

We mentioned the ability for CAD managers to lock certain system variables. There’s a corresponding Variable.IsLocked property allowing you to test this programmatically.

And finally my personal favourite miscellaneous enhancement in this release… you can now request code to be executed within a command context from the application context using DocumentCollection.ExecuteInCommandContextAsync(). Now this may not sound like much, but this one method allows you to do some really interesting things, such as calling commands from AutoCAD event handlers or even OS-level events. This is definitely a method of which we’re going to make a great deal of use, both in a few near-term posts and in the longer term.


It turns out that while the documentation for ACADLSPASDOC and TRUSTEDDOMAINS state they “may be locked by CAD managers”, the CAD Manager Control Utility currently does not, in fact, allow you to lock these two sysvars. Thanks to Dieter and Karen for tracking this one down: we’ll make sure the docs get fixed during the next update.

March 19, 2015

AutoCAD 2016

It’s that time again! Over the coming days you’re going to be hearing lots about the next release of AutoCAD, codenamed “Maestro”.AutoCAD 2016 makes a splash

Before taking a look at AutoCAD 2016 from a developer’s perspective – which we’ll do next time – in this post we’re going to take a quick look at its user features.

To kick things off here are the new commands and system variables, here are those that have changed and here are those that have been removed. To cherry-pick from the top of the new commands list, CLOSEALLOTHER will close all open drawings other than the one you’re currently working on: I know that one’s going to come in handy.

Here’s a quick run-down of the main new features…

Snap to geometric center

A new object snap mode – geometric center, or GCE at the command-line – allows you to snap to the center of closed polylines, whether regular (such as the ones shown below) or irregular.

Snap to geometric center

Revision cloud creation

The REVCLOUD command has some new options: you can easily create rectangular or polygonal revision clouds, for instance, as well as modify them afterwards.


Smart dimensioning

The DIM command now infers the kind of dimension you want to create as you hover over/select geometry.


You’ll also see enhancements around wrapping of long dimension text in this release.

System variable monitor

This feature is intended for users to make sure they don’t have impolite apps or scripts running that don’t reset sysvars to their previous settings when they’ve finished what they’re doing. But this is also likely to be a very handy debugging tool for application developers to identify when their applications are misbehaving in this respect.

Sysvar monitor

Higher quality graphics display

Those of you with capable graphics cards will see some nice improvements in terms of the display of curves in AutoCAD 2016. We’ve gone beyond the line-smoothing work in 2015 to make greater use of the GPU for elaboration of curves and line-weights.

Line quality in 2016

Coordination models

You can now attach Navisworks and BIM360 models (.NWC, .NWD) directly into AutoCAD using the new CMATTACH command, allowing you to model within and around them. The “BIM underlay” feature team did a great job delivering the ability to attach large models with very good performance.

Coordination model

Point cloud sectioning and floorplan extraction

Fans of Reality Computing are really going to like AutoCAD’s new 2D floorplan extraction: it’s great to see some point cloud feature extraction capabilities being introduced in the product. The SECTIONPLANE command has been updated to generate the new “slice” section which works with point cloud objects. You can then use the PCEXTRACTSECTION command to generate geometry based on this slice through the point cloud:

Section extraction options for point clouds

PDF enhancements

AutoCAD 2016 creates better PDFs:

  • They are smaller – typically half the size or less than the 2015 output – and are generated more quickly
  • All text is now searchable and selectable (unless you choose otherwise), even with with multibyte and Unicode characters and SHX fonts (which have the source text added as a comment)
  • Hyperlinks are maintained, whether embedded URLs or links between drawing content (e.g. callouts linking to named views)
  • Publishing sheet sets results in PDFs with named pages, and can be launched directly from the Sheet Set Manager as a one-click option
  • There are now a number of PC3 files containing commonly-used output settings, usable from PLOT, PUBLISH and EXPORTPDF commands

PDF options

  • PDF underlays now have much better performance

It’s definitely worth taking another look at AutoCAD’s PDF support if you haven’t in a while.

Rendering improvements

A lot of work has been done on rendering, in this release. We’ve simplified the options available – creating a number of handy presets, such as “Coffee-Break Quality” :-) – and introduced image-based lighting. Many of these enhancements relate to our integration of Autodesk’s RapidRT engine into AutoCAD.

Render presets palette

Help enhancements

The very handy “UI finder” capability that is built into our user documentation has been extended to find pretty much anything in AutoCAD’s UI, including entries on the app menu and the status bar.

UI finder and the app menu

That's it for this non-exhaustive look at AutoCAD 2016’s new features. Next time we’ll focus more on what the release brings for developers.

March 18, 2015

Docking a WPF window inside AutoCAD – Part 3

In this post we’re wrapping up this mini-series on docking, which is part of a much broader story arc around a “command-line helper” tool, of course. But then we’re reaching the end of that, too, I suspect, as the app’s just about done. Hopefully it’s ready for posting to Autodesk Labs, at least.

Last time we added right-click dragging to allow our keywords window to be moved around without interrupting the active command. Now we’re taking it a step further to preview docking at one of the four corners of the drawing window, as well as to actually dock the dialog when the right mouse-button gets released, of course.

Here’s a recording of this in action:

CmdLineHelper with draggable docking

And here’s the “completed” project (we’ll see what changes need to be made once we start to get feedback from users).

One really interesting problem took some debugging: we’re storing a dictionary of docking locations and their corresponding enumeration values so we can check on each “mouse move” to see whether the cursor is near enough to one of the locations to preview it. Because this list’s contents will change with the size or position of the screen, we recreate it each time a drag operation begins. Very curiously, calling Clear() on this dictionary from CommandEnded() (we have a StopDragging() helper that gets called from there, just in case “on right mouse-button up” doesn’t get called) resulted in our “unknown command” event handler not firing! I’m used to the need to be careful about drawing modifications from CommandEnded() – these can kill your undo file, for instance – but this was a completely non-AutoCAD-centric data structure. Setting it to null rather than clearing it causes the code to work properly, but this was a really interesting (and obscure) bug that I thought it was worth mentioning. Please post a comment if you’ve experienced something similar and have an idea about what’s going on.

It took a little work to add the docking preview, itself: I used a new, transparent WPF Window – sized at exactly the drawing area – to which we add a Canvas containing a Rectangle. The Window gets resized whenever a drag operation starts (in case the outer window has changed size) and whenever we find the mouse is close enough to one of our dock locations we set the rectangle to the right size & location. I ended up choosing a standard gray – matching the colour used for the command-line docking – but that’s a simple detail to change if you need to make your own docking preview more visible.

All in all it works well: the ability to move the dialog around during a command – docking, as needed – does make the app much more usable. Hopefully you’ll also find this useful for your own “dockable” windows inside AutoCAD.

March 17, 2015

Docking a WPF window inside AutoCAD – Part 2

I’m happy to say that the implementation I mentioned in the last post ended up being pretty straightforward. Which is actually great, as I have some important posts to work on for next week. :-)

Today we’re going to take a look at the next stage of the “command-line helper” implementation: basic right-click movement of the global keywords dialog, so we can set a custom location for the dialog without needing to use the KWSDOCK command.

Here’s the code in action:

CmdLineHelper with right-click dialog move

The main work for this stage was to add support for right-click, mouse move and right mouse-button up events, making sure that the dialog is displaced accurately irrespective of where the mouse gets moved. And that’s actually a really nice feature of this version: you can move the dialog off the main AutoCAD window, if you want to (this wasn’t supported in the KWSDOCK command as we’re using Editor.GetPoint() to let the user select custom locations).

I’ve turned off the mouse cursor in the above video, but you would see a “all-direction scrolling” cursor: the pan cursor isn’t a standard one in Windows, so I just used something that was good enough for this particular app.

There were some other minor things to work through, but hopefully the C# code in this version of the project is straightforward to understand.

In the next part in this series we’re going to extend this implementation to support docking – and preview of dock locations – when you right-click drag the dialog close to corners of the drawing window.

March 16, 2015

Docking a WPF window inside AutoCAD – Part 1

During the course of this week we’re going to look at extending the command-line helper sample posted last week by allowing our global keywords window to “dock” to the four corners of the drawing window as well as to remain fixed at a custom location somewhere on the screen. I use the term “dock” here loosely, as we’re really just placing it in one of the corners of the drawing window. If we wanted a modeless dialog that was properly docked into AutoCAD then we’d almost certainly want to use a PaletteSet.

Here’s a quick video demonstrating the KWSDOCK command, which allows the user to select one of the four corners or a custom location:

CmdLineHelper with docking

While the changes aren’t very extensive, it doesn’t make sense to embed the complete code in this post. Here’s a link to the updated C# project for you to look at in depth.

Having flexibility around the location of this kind of dialog is pretty important: it would quickly get annoying if you weren’t able to adjust it (whether because the window was too far from the area of interest or obscuring something you really needed access to).

One suggestion was to have the dialog placed at the cursor. Of course you couldn’t have it follow the cursor – that would clearly make it impossible to use the mouse to select a keyword from the list – but even having it placed where the cursor was at the start of the command feels strange: you very often have the cursor near your area of interest when you start a command. Having the option of a “fixed” custom location is one way to mitigate against this.

In the next part we’re going to take a look at implementing this via a right-click/drag operation directly on the window, to avoid having to run a separate command. I see this happening in much the same way as AutoCAD or Visual Studio previews the docking of windows: they both preview the location when you drag the window close enough. I’m not sure exactly how I’m going to do it, yet, but I’m aiming to do something similar for this keywords window.


10 Random Posts