Drawing structure

  • I decided to dust off Visual Studio and write a quick AutoCAD app, this morning. It tackles a question received via a blog comment from Pankaj Potdar, over the weekend. I have two blocks with different attributes I want to merge them in single block, and I don't want to create any nested blocks. I haven't had much time to spend on AutoCAD, of late. Part of the reason has been work-related: I'm heads-down getting the VR/AR track in shape for the upcoming Forge DevCon, as well as spending time on new duties in Autodesk Research. The other part is…

  • This question came up during last week's accelerator, and is part of the reason I spent creating the last post: is it possible to selectively unlock certain layers for the duration of commands that have been specified by the user? Let's take an example: you have layers that should remain locked, apart from when using the MOVE command (COPY and ERASE should not work). The approach I took was to maintain a dictionary mapping command names to lists of layers to unlock. When a command is launched – which we can tell using the Document.CommandWillStart event – we check whether…

  • On Friday I visited Munich Airport: not only to catch a flight home to Switzerland but also to take a look at some AutoCAD issues frustrating the developers working on the airport's facilities management system. During the course of the day we were able to work through a number of problems – such as using COM (SendCommand()) to run a script synchronously as well as to get the fill pattern for MPolygon objects (this is apparently broken in .NET) – but there was one I had to bring home with me: when locking and unlocking layers programmatically, their geometry doesn't…

  • After showing how to automatically attach xrefs at the origin inside AutoCAD, and then redoing the approach to take care of different unit systems, I then had the request from a couple of places to look at making the xrefs overlays and adjusting their paths to be relative rather than absolute. Looking around, I found some code on the AutoCAD DevBlog that changes an attachment to an overlay, after the fact. Henrik Ericson found the code didn't work for him, but did spot the db.OverlayXref() method which did. So I went ahead and made use of that for overlays. I…

  • This is actually a redo of last week's post, just with a different title: while the approach shown worked well when creating external references to drawings using the same units, when bringing in (for instance) metric xrefs into an imperial master drawing the scale was all messed up. Thanks to Hans Lammerts for reporting the issue. The scaling ended up being straightforward to implement: the hard work was done by UnitsConverter.GetConversionFactor(), which established the scale factor to use, converting between the Units property of the new block table record and the Insunits property of the target database. Then it was…

  • This request from Thomas Longnecker languished in my inbox for several weeks before I finally found the time to work on it. It would be tremendously helpful to me if you could give an explanatory example of how to: Create a new layout, add a page-setup with plot-settings and then either delete the default viewport and create a new one or possible change the default viewport. […] Within the newly created layouts I needed to set some of the general Plot setting, mainly Paper size and Plot style table. Some of the main things for the viewport was to set…

  • I just received this interesting (and quick to solve) question from Henrik Ericson, this morning: I'm looking for a new xref command (or perhaps overriding the internal xref command) that always insert the selected xref at 0,0,0 coordinates and in World coordinate system. I'm often inserting an xref and 'nothing happens' and then I realize that I'm in a UCS. I created a simple command called XAO – for XrefAttach[At]Origin – that does just this. As a helper function I implemented a simple extension method to both attach and insert an external reference in the current space of the active…

  • In the last post we saw a "general" function to erase all the entities in a drawing that fulfill a specified condition. We used it to erase all the zero-length lines in a drawing. But as I'd mentioned at the end, I thought there was an opportunity to generalize the mechanism even further. Here's what I came up with (and I've included a suggestion by Parrish Husband to create an additional extension method for Curve.IsZeroLength()). using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.Runtime; using System;   namespace ZeroLengthEntities {   public static class Extensions   {     /// <summary>    …

  • This is a follow-up to the post where we modified the size of selected text in a drawing, to make it fit its container. I received this comment last week: instead of selecting the nested entities one by one, is it possible to make a "selectall" selection ? It turns out that the question was related to a completely different post, but by the time I realised I'd already completed most of the work. It seems a very valid question for this topic, so that's fine. 🙂 Looping through all the text – some of which may be nested inside…

  • In the last post we introduced a static C# class containing extension methods for the ObjectId and Transaction classes. The new Transaction methods allow you to more easily "lock" objects, whether because they're "system" objects you want to keep around in every drawing or because they're objects that shouldn't be purged at whim by users. Under the hood, the implementation uses Xrecords stored in the Named Objects Dictionary that contain hard-pointer references to the various locked objects. This stops the PURGE command from removing them, but also allows us to check via Database.Purge() – or our new ObjectId.IsErasable() shortcut –…