LINQ
-
After seeing a basic approach to sort arrays of ObjectIds using LINQ – and then refactoring that to be a shared extension method to be used on arrays of ObjectIds – today we're going to see that code refactored, once again, to work with types of data other than strings (up until now we could only sort objects based on string properties such as class and layer names). One solid approach for creating operations that can deal with different types of object – while maintaining type safety – is to use template classes, which are known as generic classes in…
-
In the last post we took a look at one technique to sort a list of ObjectIds by the associated objects' layer and type. In this post we're going to refactor the commonality to have a single extension method that allows us to sort a list of ObjectIds based on any string property. Here's the updated C# code: using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.Linq; namespace ProcessObjectsInOrder { public static class Extensions { /// <summary> /// Sorts an array of ObjectIds based on a string property and order.…
-
I received this interesting question by email from Henrik Ericson, last week. Is it possible to sort the selected objects (only 3dFaces in my case) in a SelectionSet by their layers? I want to process all the objects, one layer at a time. In other words, first all objects on layer A, and then all objects on layer B and then C and so on. In my case it isn't necessary to process the layers alphabetically. It's especially interesting as I'd just been thinking of approaches for sorting toolbars based on an index property, to get the code in this…
-
After seeing how we can use Cylon.js to control Sphero's Ollie and BB-8 robots from a browser, and then using the same mechanism from inside a custom AutoCAD command, today we're going to drive these cute little bots based on AutoCAD geometry. The idea is that we'll decompose regular curves – whether lines, arcs, polylines or splines – and use the "segments" as movement instructions for our robots. The approach is simple enough: we'll iterate along the length of each selected curve and generate a set of instructions – really just a set of angles – for the associated bot.…
-
It seems like I've been living in JavaScript land (and no, I deliberately didn't say "hell" – it's actually been fun 🙂 for the last few weeks, between one thing or another. But I think I've finally put the finishing touches on the last of the JavaScript API samples I've prepared for AU 2014. This sample was inspired by Jim Awe – an old friend and colleague – who is working on something similar for another platform. So I can't take any credit for the way it works, just for the plumbing it took to make it work with AutoCAD.…
-
Another interesting question came in by email, this week. Fredrik Skeppstedt, a long-time user of the TXTEXP Express Tool, wanted to perform a similar operation using C#: to explode text objects – as TXTEXP does – but then be able to manipulate the resulting geometry from .NET. TXTEXP is an interesting command: in order to explode text objects, it actually exports them to a Windows Metafile (.WMF) using the WMFOUT command, and then reimports the file back in using WMFIN. This, in itself, is trickier than it sounds, as WMFOUT creates the graphics in the file relative to the top…
-
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 Bruno kindly allowed me to post his code and my suggestions for changes. In today's post, we're going to look at both the code and my suggestions, while in the next post (in this mini-series, at least) we'll look at a simple execution framework that can allows you…
-
A comment on the last post made me think it's probably worth diving into LINQ a bit further, as there's clearly interest out there. Now I don't actually use LINQ very much but whenever I do I tell myself I ought to use it more – it's really very useful. A lot of LINQ is derived from the world of Functional Programming – in that it allows you to use higher order functions to manipulate data – and it's really just another way in which .NET languages have been influenced by FP (and have evolved to incorporate its techniques in…
-
I looked back and couldn't find a post covering this particular topic and so decided to put something together. It may well have been covered elsewhere (I admit to not having looked) but I felt like throwing some code together, either way. 🙂 To perform a Boolean operation between Solid3d objects inside AutoCAD, you can use Solid3d.BooleanOperation() on the primary Solid3d, passing in the secondary one. We want to implement commands for Unite (or Union), Intersect (Intersection) and Subtract (Subtraction). Only the last of these needs us to select a primary object explicitly – as the other two operations are…
-
Another really interesting, developer-oriented feature in AutoCAD 2013 is something we've been calling "Dynamic .NET". I don't know whether that's official branding, or not – I suspect not – but it's the moniker we've been using to describe this capability internally and to ADN members. The capability is based on an addition to .NET in version 4.0: to complement (or perhaps just as part of) the integration of the Dynamic Language Runtime into the core .NET Framework, various interfaces – including IDynamicMetaObjectProvider – were provided to developers to let their objects participate in "dynamic" operations. Providers of APIs therefore now…