This is Scott McFarlane's TypePad Profile.
Join TypePad and start following Scott McFarlane's activity
Scott McFarlane
Charlotte, NC
Recent Activity
Hi Tony,
You are correct. I guess I had it in my mind that Dispose would not get called in the event of an Excecption being thrown. But as you point out, uderstanding the internals of LINQ as well as the compiler magic that comes with using yield really helps get your head around the whole thing. Thanks!
Querying AutoCAD objects of a particular type using .NET
Late last week I received an interesting email from Bruno Saboia, who’s been experiencing some performance issues with code he’d written to return all the objects of a particular type – in his case, Lines – from the model-space of the active drawing. We exchanged a few emails on the topic, and B...
I have encountered issues when using yield inside a transaction in this way. It works great if everything goes well, but have you tried to see what happens if an exception is thrown in the calling code?
Generally when you need this kind of pattern (getting all the objects of a particular type) you are ultimately going to *do something* with those objects. So I would recommend passing a delegate into these functions, such as Action<Line> (and the function itself would return void.) This still gives you the performance advantage of only iterating through the objects once, but it also gives you much more control over the behavior when exceptions occur.
Bruno, download the code from my AU2012 class CP2657. It's full of examples of this!
Querying AutoCAD objects of a particular type using .NET
Late last week I received an interesting email from Bruno Saboia, who’s been experiencing some performance issues with code he’d written to return all the objects of a particular type – in his case, Lines – from the model-space of the active drawing. We exchanged a few emails on the topic, and B...
Just so you know, I still want your job.
A slice of Raspberry Pi
So starts the next leg of my journey to become platform agnostic. After using a Mac as my primary system for the last year or so (albeit only doing a modest amount of Mac-specific coding, for now, and almost always having a Windows session alive inside Parallels Desktop), I now have my first Lin...
That is awesome! Way to go Jim!
Jim Quanci wins the Singlehanded TransPac 2012
This post is to belatedly congratulate Jim Quanci (Director of the Autodesk Developer Network, blogger over at Dances with Elephants and my former manager) for his recent win of the Singlehanded TransPac race from California to Hawaii. Jim sailed his 40ft boat, the Green Buffalo, singlehandedly...
Hi Kean,
Your classes look very interesting. I hope our schedules don't conflict so I can attend them. The two classes I will be teaching, which your readers may be interested in are:
CP2654 - Automated Testing with the AutoCAD .NET API
CP2657 - Programming AutoCAD with C#: Best Practices
Good luck in the football tournament, and have a great (well deserved) vacation. I look forward to seeing you in Vegas!
- Scott
Thinking about AU 2012 (and vacation)
Last week, I received confirmation that I’ll be presenting a few different classes at AU 2012, which will be held at the Mandalay Bay Hotel in Las Vegas from November 27-28. My main sessions, this year, are in some way focused on cloud & mobile technologies. The subject matter of the first lectu...
Hi Kean,
Thanks for posting this, although I apologize for causing you to take this detour. The moral of this story is that these days our programs (including those written for AutoCAD) are never self-contained or self-reliant. We reach out beyond our boundaries into the file system, external databases, web services, and even other COTS applications. Sometimes AutoCAD is the center of that universe, acting as a consumer of data and/or functionality provided by other systems, and sometimes it simply acts as a provider of data and/or functionality to another system. The role that AutoCAD plays is entirely dependent on the nature of the application, although at times this role may not be obvious at first.
In the case of this exercise, AutoCAD’s role is to gather a few input parameters and then act as a display canvas for 2D and 3D geometry – something AutoCAD is great at, but certainly not the only option. (Incidentally, this is basically the same role that AutoCAD played in your “Kinect” series, right?)
Anyway, my point isn’t to paint an overly simplistic view of AutoCAD, but as AutoCAD programmers, I think we need to really take a step back and think in more abstract terms about the true role AutoCAD plays in our applications. I have found that by doing this, the separation of concerns becomes crystal clear.
I look forward to your next post… :)
Architecting for the Cloud
After introducing the (apparently somewhat charged, judging from the comments) topic of moving application functionality to the cloud, and then looking at the steps of creating and implementing an ASP.NET Web API project, we’re now going to take a brief step back before looking at how we can eff...
I think an important but perhaps less obvious lesson here isn’t so much that you can consume a web service from an AutoCAD program, but how you can separate the concerns of your application into those that are dependent on the AutoCAD API, and those that are not. And whether you actually use a remote web service or not, just shifting your thought process into a “service-oriented” mode will usually result in a better design, with more loosely coupled, reusable components.
When I really pay attention to it, I’m always surprised at how little of the code in my AutoCAD programs is actually dependent on the AutoCAD API. Even more separation can be achieved through simple abstractions (like your Circle and Sphere classes). Having most of your program logic in non-AutoCAD-dependent components has significant advantages. Those components are more reusable (say, by a program that is like AutoCAD but not – if such a thing exists), they are easier to maintain (they don’t need to be changed or recompiled for new AutoCAD releases), and they can be unit tested inside of Visual Studio. Oh, and of course, they can more easily be migrated into web services later.
Exposing a RESTful web service for use inside AutoCAD using the ASP.NET Web API – Part 2
In the last post, we looked at the core technology we’re going to use to expose our web-service, along with the basic project set-up. In today’s post, we’re going to flesh out this project and see the web-service in action. At this point, I should point out that I've switched back across for VS2...
Works like a charm for me. That was really the only change to your code that I made, but I'll email you my code just in case.
Creating a custom PaletteSet class exposing a close event inside AutoCAD using .NET
In the last post, we saw some code that provided a relatively crude mechanism for finding out when a particular custom palette set gets closed by the user. In this post, we encapsulate this technique in a new class – which I’ve called PaletteSet2, for the want of a better name – that can be used...
Hi Kean,
Since your CheckPaletteSetState command method is defined inside the PaletteSet2 class, you’re allowed to access non-static events on any PaletteSet2 instance within the scope of that method. Just make your event non-static, and then change the code that fires the event to:
if (ps.PaletteSetClosed != null)
ps.PaletteSetClosed(ps, new EventArgs());
Merry Christmas!
- Scott
Creating a custom PaletteSet class exposing a close event inside AutoCAD using .NET
In the last post, we saw some code that provided a relatively crude mechanism for finding out when a particular custom palette set gets closed by the user. In this post, we encapsulate this technique in a new class – which I’ve called PaletteSet2, for the want of a better name – that can be used...
Congratulations, Kean... I almost missed your note at the end. As soon as I started reading, my thoughts went straight to that moment during your AU class and I was tempted to scroll down and paste my resume into the "comments" section. Oh well...
Moving on (and yet not)
As hinted in my last post, I have some news to share with you all. After sixteen and a half years with the ADN team (and for a reminder of my various jobs, check out this previous post or you might also watch the video on my about page), I’m moving on to pastures new. I have deeply loved my curr...
>> he has an energy level that I could probably only achieve by setting myself on fire.
Amen to that.
A quick AUpdate
So, here we are on Wednesday, day two of AU proper (although my team was busy with ADN-only sessions on Sunday and Monday). Yesterday was really fun: I was part of the “Meet the AutoCAD API Experts” panel (along with Stephen Preston, Albert Szilvasy, Mike Dickason, Bill Adkison, Davis Augustine ...
It is indeed astonishing how few code changes were necessary to make this work. As we wait for .NET 5, I have found Parallel LINQ (PLINQ) quite useful for tasks like this. I'm too lazy to learn F# at this point.
Finally working with the Async CTP for VS 2010
I’ve been planning to look at it for ages – and have certainly mentioned it before – but other things have kept on cropping up. Well last Thursday, on my train trip back from Wallisellen (the home of Microsoft Switzerland), I finally managed to take the plunge and start working with the Async CT...
I also like ReSharper (http://www.jetbrains.com/resharper). I know it's not free, but it pays for itself every day I use it.
Finally working with Visual Studio 2010
Despite having worked for some time with a number of language features previewed for VS2008 and properly released in VS2010 (F# being a prime example), I’ve finally gotten around to installing VS2010 as my main .NET code development environment. To make sure I could get code across properly into...
Scott McFarlane added a favorite at Through the Interface
Jan 19, 2011
Scott McFarlane is now following Kean Walmsley
Jan 19, 2011
I wonder if instead you could "squirt" a lisp expression to the command line. Would that make it culture-independent?
string cmd =
String.Format(
CultureInfo.InvariantCulture,
"(list {0} {1} {2}) ",
pts.Average(a => a.X),
pts.Average(a => a.Y),
pts.Average(a => a.Z)
);
Returning an average point to the AutoCAD command-line using .NET
This request came in over the weekend: There is a useful object snap in AutoCAD for the mid point of 2 selected points. I would like a midpoint (average) of 3 (or more) points. Could this work in 3D as well as 2D? It’s useful when drawing building surveys, often you triangulate a point from se...
Scott McFarlane is now following The Typepad Team
Jan 18, 2011
Subscribe to Scott McFarlane’s Recent Activity