Jump to content

How to create .NET program that automate AutoCAD


Recommended Posts

Posted

I have a .NET program that extract information from autoCAD that was working fine on autoCAD 2008 but failed badly on 2011/2012. It failed on activeX can't create object or call rejected by callee

I used obj=createObject("autodesk.Application")

 

Anyone has some finished code that could safely create the object? I have search through the internet for many articles, they just don't help or incomplete.

I need VB.net code instead of c#.

 

Alex

Posted

I guess you trying something like this

 

 

 

http://www.theswamp.org/index.php?topic=39578.0

 

   '''' Const progIDstr As String = "AutoCAD.Application.18.1"'''---- 2011
   '''' Const progIDstr As String = "AutoCAD.Application.18.0"'''---- 2010
   Const progIDstr As String = "AutoCAD.Application.18.2" '''''' ---- 2012


  Dim app As AcadApplication = Nothing
       Try
           Try
               app = Marshal.GetActiveObject(progIDstr)
               app.Visible = True
           Catch
               app = New AcadApplicationClass()
               app.Visible = True
           End Try
       Catch ex As Exception         
           Return
       End Try

Posted

Thanks! but I don't have class "Marshal" or "AcadApplicationClass" available.

 

I did add Autodesk.AutoCAD.Interop & Autodesk.AutoCAD.Interop.Common

to my project reference.

Posted
Thanks! but I don't have class "Marshal" or "AcadApplicationClass" available.

 

If you have AutoCAD 2007 or at least .NET 2.0 installed than you do.

 

 

In the Link posted previously look at code in 2nd Reply

 

 

You should add

 


Imports System.Runtime.InteropServices

 

 

Marshal Class

 

 

That part of the code that uses Marshal.GetActiveObject(progIDstr) is to get AutoCAD if it is already running.

Posted

ah... I am using visual Studio 2005 with Windows XP. that is why I don't have any of those, I guess I need to upgrade.... :(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...