Category: Autocad .Net API

This documents the work I’ve done on the Autocad API.

I will be posting code and helpful methods which you might find of use.

Thank you!

  • Add If Layer is Missing (AutoCAD .net)

    A very handy method. Often detailers will ask for something to be placed on a particular layer. But since they are using a 100 different drawing templates without any consistency nor standards, the onus is on you to impose that standard on them. So you’d have to check for a layer and add it if it doesn’t already exist. Anyways, that’s enough griping: here is the code:

  • Ignore White Lines in Selection Filter (AutoCAD .net API)

    Lines of a certain color.
    We want to select line times of a certain color.

    We want a selection filter which simply ignores certain types of colors.

    Here is the ‘simple’ result I came up with:

  • Jigging with SHIFT, CTRL and Mouse Wheel Functionality (AutoCAD .net API)

    If writing software then make it easy for your users.
    User Input is critical. You gotta make the user experience amazing.

    Any AutoCAD programmer knows that things which an algorithm may take a million years and infinite computational power to do can sometimes be easily done by a human being instantly. In the same way it is sometimes much easier to give a human being the ability to choose: then you can get an optimum result without complex algorithms.

    This post is a code snipped of how you can utilise the CTRL + SHIFT + Mouse Wheel (up/down) mechanisms in order to produce different desired results when operating a custom jig.

    Here is the code:

     

    So when the appropriate user input happens, then the jig can respond accordingly. Yes it’s true – the OOP purists will say: “you’re passing a concrete type in there” – I can always change it later if I want.

  • Offsetting Truss Lines from Intersecting Fire Collars (Bubble Deck + Video Demo)

    The effective point of this blog is to demonstrate the use of a jig – not just any old jig – but a jig which accepts user inputs using the CTRL + SHIFT + MOUSE-WHEEL (up or down) to change the jig’s behaviour. When the jig is finished running, everything returns back to normal.

    This is best demonstrated with a video:

    Move Intersecting Truss by Panel Thickness (with Jig) from Tek1 on Vimeo.

    We use this jig and command as part of our Bubble Deck tools dll.

    The reason we utilise tools like this:

    This allows us to turn over shop drawings faster, more efficiently. This allows our precast fabricator to massively improve their working capital position:

    • Their factory staff is always utilised – they don’t have massive overheads of 50 guys sitting on the factory floor twiddling their thumbs,
    • They can get in and out of jobs quickly – minimising their liabilities and expenses and also collecting revenues faster,
    • Faster revenue has huge benefits in terms of interest saved vs interest earned – especially for the developer. If you can allow the developer to finish the job a couple of weeks earlier you save on: construction costs, and also, as before, their interest expenses and their liquidity also improves. That’s worth its weight in gold.
    • There is nothing worth more than: accurate drawings, done quickly. That’s what we strive for.
  • Thoughts About the AutoCAD API (AutoCAD .net API)

     

    Get your API working hard for you. Like worker bees.
    Get your API working hard for you. Like worker bees.

    I got thinking about the AutoCAD APIs (ObjectARX/.NET) – they’re virtually the same – the .NET API is basically a wrapper to the ObjectARX API (with some differences). If you want the full power of low level calls then you gotta go with ObjectARX. But then using .NET comes with a very powerful benefit – a host of libraries and code readily available to utilize. If you’re talking UI then WPF is waiting for you if you go down the .NET path, but not so with ObjectARX.

    Anyways, when you think about the API  there are a few issues that you gotta manage:

    1. The opening and closing and disposing of Objects.

    And the main operations that come to mind are the following:

    1. Adding Items to the database.
    2. Removing Items from the database.
    3. Editing existing items from the database.
    4. Getting Items from the database.
    5. If this happens do that (Events) which ties into all of the above.

    Is it just me or does smack of a RESTful API? Well not quite, because we can store state in variables, both within the drawing, and in variables within our classes (temporary).

    These are the steps:

    1. Identify a resource.
    2. Operate on that resource.

    We can go about this in a few ways:

    1. Using extension methods. This means that we have already identified the relevant resource and we act on it.
    2. Static Methods where then operate on those resource. (I use resource in the sense that Fielding uses it).
    • GetResource( parameters)
    • Action(parameters)

    We shouldn’t have to worry about all the lower level stuff.

    Perhaps a better wrapping API can be written incorporating this. I know Mr Wolfgang Tertinek has wrote about it extensively in his blog. It’s a good approach, but perhaps common tasks e.g. changing a layer of an object can be incorporated in this model. Ideally this should be written simply with core level logic without direct use of a particular dll.

    • .e.g something like this: SelectionFilter.Create(layer: “test”, types: [BlockReference, Mtext]) – without going into the specifics of setting type filters etc. A DSL much like Active Record for handling these types of queries.
  • WPF User Interface for Precast Panel Comparison

    This utilises WPF to compare panels, isolate changes and make better decisions.

     

    See below for a demonstration:

    WPF – Eliminating Errors using Cross Checking from Tek1 on Vimeo.

     

     

     

  • On Line Equality (AutoCAD .net API)

    Some lines may be more equal than other lines? The AutoCAD .net API's EqualTo method may disagree with your interpreation of equality. Here are the results;
    Some lines may be more equal than other lines? The AutoCAD .net API’s EqualTo method may disagree with your interpretation of equality. Here are the results;

  • A Poor Man’s Line Jig (well, there’s actually no jigging here) – (AutoCAD .net API)

     

    What are these guys doing, you ask? I suspect that they are jigging a line. They are probably doing it this way because they didn't read the ObjectARX documentation. Well actually, you don't need to. Just use the poor man's jig.
    What are these guys doing, you ask? I suspect that they are jigging a line. They are probably doing it this way because they didn’t read the ObjectARX documentation. Well actually, you don’t need to. Just use the poor man’s jig.

     

    I wanted to implement a jig for drawing a Line – but strictly speaking I didn’t want the line itself – I wanted its two points, yet I wanted all the features that come with jigging: snaps, polar tracking, and a nice line leading from the base point to the cursor, which shows you where you were, and where you are going. I was originally going to jig it all myself – and all of this to obtain two coordinates in a manner that would allow the user to see what was actually going on. Jiggig takes a lot of effort. It was only then that I realised I could get the same result, but with a massive short cut:

    Here is a poor man’s Line Jig – at the end of it, you’ll have the two points you are after, but without the effort. If required, you can encapsulate all the logic in it’s own class, so that the client doesn’t have to bother too much with the implementation details.

    Poor man’s line jig.

     

            [CommandMethod(“GetPoints”)]

    public static void GetPoints()

    {

    Document doc = Application.DocumentManager.MdiActiveDocument;

    Database db = doc.Database;

    Editor ed = doc.Editor;

     

    PromptPointResult pprOrigin = ed.GetPoint(“Click for point.”);

     

    if (pprOrigin.Status == PromptStatus.OK)

    {

    PromptPointOptions promptPointOptions = new PromptPointOptions(“Please get secondPoint”);

    promptPointOptions.UseBasePoint = true;

    promptPointOptions.BasePoint = pprOrigin.Value; ;

     

    PromptPointResult ppr = ed.GetPoint(promptPointOptions);

     

    if (ppr.Status == PromptStatus.OK)

    {

    ed.WriteMessage(“Congrats!”);

    }

    }

    }

     

  • Steps to Mastery of the API (AutoCAD .net API)

    These are steps. When you get to the top, you'll be an AutoCAD master programmer.
    These are steps. When you get to the top, you’ll be an AutoCAD master programmer.

    I’ve compiled a list. There’s actually quite a bit involved. I don’t think you can get away with simply not knowing anything about unamanged ObjectARX world. Here is the list below – which I will update. If you see any notable topics which I have missed, please feel free to add a note and I will update the list.