Tuesday, July 31, 2007

Getting Started

Instead of spending time on discussing the concepts and theories behind AutoCAD.Net programming, I think we should better start with some sample code. It defenitely helps us to raise the confindence level. The thrill of watching our first program output in a new technology will defenitely last long and help us to gain momentum and energy for further exploration. So here goes our first program. Please remember that I am also a beginner in this field. So the code may not be of professional standard and may contain errors. I highly appreciate your suggestions for the improvement of these code snippets.

The following code displays a welcome message in the AutoCAD Text Editor window.




Here is the a text version of the code if you want to copy and paste it in your editor. The above one is a screenshot from the code editor window. I used that image for a better understanding of the code. Once you copy the following code and paste it in Visual C# editor, it should arrange it in the manner shown above. So next post onwards, I may not include a screenshot.

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
namespace AcadNetSamples
{
public class Commands
{
[CommandMethod("Hello")]
public static void SayHello()
{
Document doc=Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
ed.WriteMessage("\nHello and welcome to AutoCAD.Net world...!!");
}
}
}
Here goes a few thing to be taken care before you start using it.
  • You must have set reference to AutoCAD managed class libraries acmgd.dll and acdbmgd.dll . Otherwise the AutoCAD specific objects and methods will not get detected.
  • If you are using Visual C# editor, then you can use Solution Explorer window to add reference to the above files. If you are using a command line version of compiler (CSC.EXE), then use /r option to set reference. (Type CSC/? in the command line to get help on compiler options)
  • The project type has to be a Class Library in order to use it inside AutoCAD. If you start with VS Editor, the choose project template 'Class Library' in the beginning. If you use Command line, then choose /t:library option to compile it as a library project.

Those are the essentials and once you build the output, load the dll file (here AcadNetSamples.dll) from autocad using netload command. Type "Hello" in the command prompt and if everything goes right, you will see the following message.

"Hello and welcome to AutoCAD.Net world...!!"

Monday, July 30, 2007

AutoCAD.Net Programming - VB.Net or C# ?

As far as I have seen, the prerequisite for Dot Net programming is not the proficiency in any of the supporting languages, but a very good understanding of Dot Net Framework and Framework Class Libraries (FCL). There are several supporting languages (still counting) which enables you choose your favourite one. Of all those, the most popular ones are VB.Net and C#. Learning both of them seems to be a tough task (for me, even learning one of them seems to be a herculean task..!!). So I started searching on net for finding advantage of one over the other. I kept on reading till I saw these two links laying side by side in the same website.

Top 10 reasons VB.NET is better than C#
and
Top 10 reasons C# is better than VB.NET

Apparently, they all are same in case of productivity. Choosing a language depends mainly on how much the user is comfortable with it. Personally thinking, I had exposure to VBA and JavaScript in the past. In case of VB.Net, it is known as an entirely different language from VB. C# is a new language developed exclusively for Dot Net Framework. So the options are clear. Both are new languages and doesn't carry any benefits from learning its ancestors. Finally I decided to go for C# over VB.Net as it was becoming more popular among the Dot Net Developers. Moreover, some popular AutoCAD programmer blogs like Through the Interface (It's really a nice place) inspired me to choose C# over VB.Net. I found some very good DevHood training modules for beginners to start with C# and DotNet.

I found this training modules simple and elegant and good enough to give a start on C#. There are some advanced topics under the Training Modules link. I am planning to look at it when I get enough time to do so.

That's all about Microsoft.Net and C#. Now for doing AutoCAD.Net programming, we need to know something more than that. The easiest thing is to download AutoCAD 2007.Net Training.zip file from AutoCAD Developer Center. Go through the AutoCAD 2007 Managed C#.NET Training.3.doc and try it. If you come across any problems, visit forums like Autodesk AutoCAD.Net discussion group. There are many people out there to guide you through proper direction.

That's all I have done so far apart from doing a few basic programs. By the way, If you would like to download Microsoft Visual C# Express Edition (It's free) just follow the link.

Saturday, July 28, 2007

Hello World...!!

Hi,
My primary objectives are to learn, contribute and communicate knowledge, experience and wisdom with all of you. I beleive this blog will help me to accomplish that (ad?)venture. Mostly, I will be concentrating on AutoCAD Programming & Customization. That said, I will never hesitate to jump upon a subject, if I find it intersting and worth mentioning.

Thanks for visiting my blog.

:-)