Not sure if this is the right place but here goes anyway...
I currently have a Windows VB.net app that uses COM to open/save/close and manipulate drawings in AutoCAD...
Here's how I open a drawing
AutoCAD_CurrentDwg = AutoCAD_Instance.Documents.Open(strAutoCADFilePath
I work with various blocks and their attributes like so
Dim AutoCAD_Block_Attributes As Object = AutoCAD_Block_Reference.GetAttributes For Each Me.AutoCAD_Block_Attribute In AutoCAD_Block_Attributes Dim strAutoCAD_Block_Attribute_TagString As String = AutoCAD_Block_Attribute.TagString AutoCAD_Block_Attribute.TextString = strSomeDB_Value
As I mentioned, this runs external to AutoCAD but I was wondering if it would be beneficial to re-write the app to run within AutoCAD... also, I believe that COM is "obsolete"? Should I not be using it?
Doing some reading, I think that my app could be revised to run inside AutoCAD via NETLOAD, using ObjectARX? One concern I have is that my app right now works with many versions of AutoCAD, not need to re-issue because my DIM statements are generic...
Private AutoCAD_Instance As Object Private AutoCAD_CurrentDwg As Object Private AutoCAD_Document As Object
Am I in the right forum? Thoughts?
You're in the right forum to ask about migrating your code to .NET. Some general points to start you off ...
- If you want to control AutoCAD from an external application, then COM is still the way to go. We're not removing the AutoCAD ActiveX (COM) API, but we've not been enhancing it particularly, either.
- If your automation is making a lot of calls to AutoCAD (doing a lot of heavy lifting) then you'll see significant performance improvements if you bring that heavy lifting code inside the AutoCAD process. COM marshalling across process boundaries is a huge overhead (e.g. on my machine its a factor of 30 difference between making the same COM API call out-of-process compared to in-process).
- Your .NET code should be compatible between versions across at least the three year binary compatibility cycle (e.g. AutoCAD 2010-2012). Outside of that, you may have to create different builds for different AutoCAD versions.
- If your current code does what you need as fast as you need it to, then I wouldn't bother migrating it at this time. (Spend your time writing something new instead :-).
Believe it or not, the type of application you have is actually better off as an out-of-process COM client, verses an in-process dll, because you can start and close AutoCAD repeatedly without loosing control, and you can execute an in-process script to do work within each document/session. You could write the parts of your app that deal with a single document as a command that you can start from an out-of-process client, but controlling the whole batch processing from an in-process server can be more difficullt, because AutoCAD will progressively consume memory and not release all of it when a single session is used to repeatedly open and close many files.
I'm not sure if I want my application to control AutoCAD as an external application - I do know that I want it to serve as a processor of many individual drawings by importing/exporting data to/from each drawing and an MS Access database...
My app opens drawings and accesses the related records in an Access database, manipulating the attributes of various Block References in said drawings... it is also capable of reversing the process...
Not sure if my app is making lots of calls but it could be... I do know that it is manipulating numerous blocks and iterating through their attributes, as follows:
'Process EACH Block Attribute to IDENTIFY the Reference Attribute Value For Each Me.AutoCAD_Block_Attribute In AutoCAD_Block_Attributes 'AutoCAD Attribute NAME matches ADG specified Reference Attribute If (AutoCAD_Block_Attribute.TagString = strAutoCADReferenceAttribute) Then 'Flag AutoCAD Block Reference Attribute as FOUND bAutoCAD_Block_ReferenceAttribute_Found = True strAutoCAD_Block_ReferenceAttributeValue = AutoCAD_Block_Attribute.TextString 'If the AutoCAD Block Reference Attribute is EITHER NOT specified OR '.' If (strAutoCAD_Block_ReferenceAttributeValue = "" Or strAutoCAD_Block_ReferenceAttributeValue = ".") Then AutoCAD_Block_Attribute.TextString = "*FAILED*" End If Exit For End If Next
Not sure if this is defined as "heavy-lifting"...
The code does do what I want but I am primarily exploring the migration because it could run faster... when iterating through many large blocks (particularly, those with lots of attributes), it is a tad slow... wondering if it could be faster...
Here is a blog post that can help you evaluate some pros and cons :
Starting AutoCAD 2013, you can do such batch processing of drawings using the accoreconsole. Using this you can also invoke commands from your custom plugins that work on those drawings.
It is hard to say which method (COM / .Net plugin / accoreconsole) will be the fastest, but since you are working with multiple drawings, use of accoreconsole seems ideal.
Here is a DevTV on this topic :
Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register