Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

autocad - How can I improve the speed of .NET Plug-in Development?

I'm developing an AutoCAD add-in, which uses a .NET 4.6 assembly. I am finding the development process very frustrating; the API is very large and the documentation beyond getting started is all over the place and very hard to find. The only way to get anything done seems to be just prototyping functions in Visual Studio and seeing if it works. It then takes several minutes to load up AutoCAD and attach a debugger, which wrecks my prototyping workflow.

It would be very handy if I could have something like Linqpad to prototype my applications so I can find the data that I'm looking for. I'm not married to the idea of using Linqpad; however, if there's another technique I'm missing I'd love to hear about it.

I'm not sure if this is something I might achieve with the pro version but as there is no trial I can't find out.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is true, the API is indeed large, and some functionality is somewhat poorly documented. I found it difficult to get started, but once I became familiar with the core concept and functionality, I started to very much enjoy working with it as the API very powerful and easy to work with once you "get it". I am not sure what sources you have checked, but I started with this Developer Documentation. Scroll down to the training labs. I would recommend that you at least read through both ObjectARX and .NET Training labs. Spend a few days working through the .NET labs as it will save you countless hours down the line.

As for debugging, the set-up below should give you the most effective and efficient approach (here I use VS 2015 and AutoCad 2015). In the project properties, under the "Debug" tab, your settings should be as follows:

  1. Check "Start external program:" and enter the path of the AutoCad executable. This applies to other versions of AutoCad.
  2. In the "Command line arguments:" field, enter /nologo. This will significantly speed up the start-up of AutoCad.

enter image description here

To load your dll into AutoCad automatically, you can either do it through the registry (my preferred way) or through acad20xxdoc.lsp or acad.lsp (AutoCad will run these scripts by default for each document you open or when AutoCad starts respectively). You can find details in this post.

Now Pressing F5 will start AutoCad and load the debugger. You can now step through lines of code as for any other piece of code. Place a break point at the start of your code, then execute your command in AutoCad. Your break point should get hit.

Aside: /nologo can also be added to AutoCad's Desktop shortcut to speed up AutoCad for users. It can be added to the "Target:" field in the shortcut properties. i.e. "C:Program FilesAutodeskAutoCAD 2015acad.exe" /nologo

Note: A possible Gotcha! Make sure that any AutoCad dlls that your project references have their properties set to:

  1. Embed Interop Types -> False
  2. Copy Local -> False. Also make sure that there are no AutoCAD dlls (i.e. acmgd.dll or any dlls with names starting with "ac") in your Debug/Release directory. Delete any that you find. Not doing so will cause errors and crashes that will be very hard to trace down.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...