AutoCAD
-
In this earlier entry I showed some techniques for calling AutoCAD commands programmatically from ObjectARX and from VB(A). Thanks to Scott Underwood for proposing that I also mention calling commands from .NET, and also to Jorge Lopez for (in a strange coincidence) pinging me via IM this evening with the C# P/Invoke declarations for ads_queueexpr() and acedPostCommand(). It felt like the planets were aligned... ๐ Here are some ways to send commands to AutoCAD from a .NET app: SendStringToExecute from the managed document object SendCommand from the COM document object acedPostCommand via P/Invoke ads_queueexpr() via P/Invoke Here's some VB.NET code…
-
This is an interesting little problem that came in from Japan last week. Basically the issue is understanding how to call the DIMARC command programmatically from LISP using (command). The DIMARC command was introduced in AutoCAD 2006 to dimension the length of arcs or polyline arc segments. What's interesting about this problem is that it highlights different aspects of entity selection in LISP. Firstly, let's take a look at the DIMARC command (I've put the keyboard-entered text in red below): Command: DIMARC Select arc or polyline arc segment: Specify arc length dimension location, or [Mtext/Text/Angle/Partial/Leader]: Dimension text = 10.6887 The…
-
This entry was contributed by Adam Nagy, a member of DevTech EMEA based in Prague. The question is really a combination of two problems: Selecting a subentity Selecting a nested entity Selecting a subentity First we should clarify what a subentity is: A subentity is a pseudo entity which is a logical part of a real entity. In our sample drawing the solid is the real entity [AcDb3dSolid] and the edge is the pseudo entity (there is no AcDbEdge class). In AutoCAD we rely on IDs called GS (short for graphics system) markers to get to these subentities. The ObjectARX…
-
I had a nice surprise this weekend. Jorge Lopez, an old friend and colleague, had been reading this blog entry and decided to create a Visual Studio AddIn that allows you to see resbufs content expanding automatically while debugging. Jorge and I go back a long way - he used to work in DevTech (before it was called that) in our Americas team, back when I was based in Europe the first time. He later went on to join AutoCAD Engineering, and was one of the key contributors to AutoCAD's COM Automation API (although back then it was called either…
-
Someone asked by email how to get the block import code first shown last week and further discussed in yesterday's post working with AutoCAD 2006. I've been using AutoCAD 2007 for this, but to get it working there are only a few changes to be made. Firstly you'll need to make sure you have the correct versions of acmgd.dll and acdbmgd.dll referenced into the project (you should be able to tell from their path which version of AutoCAD they were installed with). Secondly you'll need to modify your code slightly, as WblockCloneObjects() has changed its signature from 2006 to 2007.…
-
I didn't spend as much time as would have liked talking about the code in the previous topic (it was getting late on Friday night when I posted it). Here is a breakdown of the important function calls. The first major thing we do in the code is to declare and instantiate a new Database object. This is the object that will represent our in-memory drawing (our side database). The information in this drawing will be accessible to us, but not loaded in AutoCAD's editor. Database sourceDb = new Database(false, true); Very importantly, the first argument (buildDefaultDrawing) is false. You…
-
We're going to use a "side database" - a drawing that is loaded in memory, but not into the AutoCAD editor - to import the blocks from another drawing into the one active in the editor. Here's some C# code. The inline comments describe what is being done along the way. Incidentally, the code could very easily be converted into a RealDWG application that works outside of AutoCAD (we would simply need to change the destDb from the MdiActiveDocument's Database to the HostApplicationServices' WorkingDatabase, and use a different user interface for getting/presenting strings from/to the user). using System; using Autodesk.AutoCAD;…
-
Since Visual LISP was introduced, developers have taken advantage of its ability to call COM Automation interfaces (whether AutoCAD's or other applications'). The addition of this functionality to the LISP platform created many new development possibilities - previously you were able to call through to ObjectARX applications defining LISP functions, but enabling Automation access from LISP suddenly allowed developers to access any other application adopting the COM standard its API, such as Microsoft Excel. A quick note on error handling in LISP... Traditionally LISP applications have defined their own (*error*) function to trap errors during execution. During this function they…
-
Thanks to Alexander Rivilis for this topic (he submitted a comment to my previous post that got me thinking about this addendum). When you're asking AutoCAD to execute commands by submitting them to its command-line, it helps to make sure no command is currently active. The accepted approach is to send two escape characters to the command-line... this is adopted by our menu & toolbar macros that consistently start with ^C^C in MNU and now CUI files. Why two? The first is to cancel the "most active" command, and the second is to drop out of either the dimension mode…
-
It's quite common to want to call commands from one or other of AutoCAD's programming environments. While it's cleanest (from a purist's perspective) to use an API to perform the task you want, the quickest way - and the one which will appeal to the pragmatists (and the lazy) among us is often to call a sequence of commands. And there are, of course, a few places in AutoCAD where APIs have not been exposed, so scripting commands is the only way to achieve what you want. Let's take the simple example of adding a line. Here's what you'd do…