.NET

Reply
Valued Contributor
jsurpless
Posts: 83
Registered: ‎08-12-2008
Message 1 of 5 (295 Views)

Converting COM-based Application

295 Views, 4 Replies
11-05-2012 04:57 AM

Hi everyone

 

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?

 

Thanks!

 

-Justin

Board Manager
StephenPreston
Posts: 362
Registered: ‎05-22-2006
Message 2 of 5 (278 Views)

Re: Converting COM-based Application

11-05-2012 01:55 PM in reply to: jsurpless

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 :-).

 

 

Cheers,

Stephen Preston
Autodesk Developer Network
Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 3 of 5 (267 Views)

Re: Converting COM-based Application

11-05-2012 07:26 PM in reply to: jsurpless

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.

Valued Contributor
jsurpless
Posts: 83
Registered: ‎08-12-2008
Message 4 of 5 (253 Views)

Re: Converting COM-based Application

11-06-2012 05:26 AM in reply to: StephenPreston

Hi Stephen

 

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...

ADN Support Specialist
Balaji_Ram
Posts: 660
Registered: ‎03-21-2011
Message 5 of 5 (202 Views)

Re: Converting COM-based Application

11-09-2012 09:25 AM in reply to: jsurpless

Hi Justin,

 

Here is a blog post that can help you evaluate some pros and cons :

http://through-the-interface.typepad.com/through_the_interface/2006/09/com_vs_net_in_a.html

 

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 :

http://adndevblog.typepad.com/autocad/2012/04/getting-started-with-accoreconsole.html

 

http://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console...

 

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community