AutoCAD .NET -> Pouring quick set epoxy in your keyboard if it could
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Am I the only one that is finding customizing AutoCAD using .NET to be a huge pain? Is the effort required to get AutoCAD to do what you want it to justified? I say NO!
I started off programming AutoCAD by experimenting and taking in all I could at AU virtual a couple of years ago. I remember at the time learning from these classes and practicing what they taught as if it was a religion. From the start I saw posts by Tony T. and others that extolled the Object ARX documentation and pressuring aspiring .NET programmers to study and understand the deep dark details of how AutoCAD works. At the time with my limited programming experience I thought that this was how the programming world works. I remember one AU Virtual class where the presenter was showing how to put the transaction manager code into a snippet so it is easy to insert whenever you need it.
I wrote code, it ended up a huge spaghetti mess and then I took a step away from AutoCAD themed coding to learn more about coding design and architecture instead. Now after learning how coding now works in the real world today, the AutoCAD .NET API and the Autodesk documention is HORRIBLE!!
I have been writing code using many frameworks and technologies and it takes 10X longer to accomplish something working with AutoCAD vs trying to do anything else. Even getting a LOB app going using PRISM with MEF, Entity Framework, Generic Repository, Enterprise framework for logging and validation, and Microsoft Sync for occasionally connected applications (and some ASP .NET services as well for good measure) is VASTLY easier to accomplish knowing nothing then it is to build a add-on for AutoCAD that say opens drawings, plops in blocks from files, saves and closes said file, and repeat.
The biggest problem is that the .NET API drags all the ugly from AutoCAD's core right up front and center, and THIS IS WRONG. I do not care how the plumbing was routed, how the electrical was put in or how many litres of water goes down the drain when the toilet is flushed. If you were around a few years ago, Tony T was replying to every question and lambasting everyone to learn more about the plumbing of AutoCAD (ie study in depth the Object ARX documentation). The posts seemed to take on a tone of "You &^$*&^$ .NET programmers, it is not that easy"
IT SHOULD BE! If you look at the progress made over the last ten years and learn about proper coding practices and architecture you will see a huge effort has been made to improve software development. I have read many an article about a coding topic where the author states that 10 years ago he himself was writing horrible spaghetti code, not intentionally (he did not know better), and then presents a topic that makes an effort at reducing the problem.
If you want to understand how to make better code look up SOLID design principles and Group of Four design patterns. (Of which I am sure none of the AutoCAD .NET API even tries to hint at following)
In the end it becomes clear that separation of concerns is important. If I want to insert a block into a drawing it SHOULD be a straight-forward practice. I should not have to work with the transaction plumbing, or the document lock electrical work.
There should be a contract between AutoCAD and my program (interfaces, facades, etc (see design patterns)) where I can write AutoCAD.Insert("Blockname.dwg", options) and the professionals at Autodesk have all the plumbing and wiring done correctly behind the scenes.
Why does every programmer need to have intimate knowledge about how AutoCAD works and every programmer repeat thousands of times the transaction code? Does ANYONE ask this question?
All material on .NET programming with AutoCAD should come with a disclaimer (I think Kean meantioned this in a post, and it may have been in ONE AU notes document) that states proper design practice should be implemented and how they show to do things is not what you would want to do in practice.
I have re-written my code and all the AutoCAD related code is placed neatly in its own corner away from my algorithms. It is coded in such a way that I could rip it out and use paint as long as I implement the Paint.Insert to replace the AutoCAD.Insert as exemplified above. I have created a library that suits my needs so it is now all simple calls to do things, and I do not need to worry about tables and dictionaries and definitions and transactions and document locks when all I am trying to do is place a block and update an attribute.
The transaction manager code appears ONCE in my code, yes, only one time. Which is mind boggling if you read any AU virtual material, since I am sure each class has several if not tens or hundreds of transaction manager clips spread throughout. This would be fine if there was a note, or a hint, or anything that says this is to learn how it works, but do not make it this way. In fact a AU or AU virtual class should be avaialable that shows how you should be structuring your code and what efforts you should be making.
I am ranting because I am once again trying to achieve something with AutoCAD, and once again it is proving to be a huge pain compared to any other programming.
I basically started trying to make applications with AutoCAD, and my programming experience before this was small apps where architecture did not matter as much due to the small size. I fought with the API around every corner to do every little thing since you need to know so much about how the original programmers made things. I was BLOWN AWAY when I got into frameworks (Fluent Entity Framework, PRISM, MEF etc) and saw HOW EASY it was to do things that really are very complex when compared to inserting a block and updating attributes (which ironically AutoCAD .NET makes as hard as possible)
If you are going to work with AutoCAD .NET programming you should figure out what you want to do and abstract all the functionality away properly so you can focus on getting things done rather than mucking around with ancient coding paradigms.
Of course this is my own personal opinion based on my journey over the last few years of programming. Does anyone else see any of this or am I just crazy from staring at too many drawings and too much code? I am surprised (maybe I did not look hard enough) that the above has not been brought up. Is it really just me or are there some code smells (look it up if you have not heard this) coming from this API?
)