.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Marshal.GetActiveObject not working in Autocad 2024

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
josborneW959Y
401 Views, 5 Replies

Marshal.GetActiveObject not working in Autocad 2024

Looks like this code doesn't work in Autocad 2024.

 

*Moderator Edit* Post your code in a code window.

 

// Get a running instance of AutoCAD
  try
  {      acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId);
  }
  catch // An error occurs if no instance is running

 

 

 

As referred in
https://help.autodesk.com/view/OARX/2024/ESP/?guid=GUID-C8C65D7A-EC3A-42D8-BF02-4B13C2EA1A4B

 

It works for older versions of Autocad but not for Autocad 2024.

 

Am I missing something? Any help?

5 REPLIES 5
Message 2 of 6
Ed.Jobe
in reply to: josborneW959Y

Are you sure that you are passing the correct value of strProgId?

From Help:

Note: The ProgID for COM application access to AutoCAD 2024 is AutoCAD.Application.24.3.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 3 of 6
josborneW959Y
in reply to: Ed.Jobe

Super sure! My code is almost same as Autodesk sample. It doesn't work... any tip?

 

I'm running it from inside Autocad by the way.

 

Edited:  Also this code was created around version 2017/18, and worked perfectly fine in old Autocad versions.

Message 4 of 6
Ed.Jobe
in reply to: josborneW959Y


@josborneW959Y wrote:

Super sure! My code is almost same as Autodesk sample. It doesn't work... any tip?


The call should look like

 


  {      acAppComObj = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.24.3");
  }

 

 


@josborneW959Y wrote:

I'm running it from inside Autocad by the way.


Why? You only need that if your code is running out-of-process. If your code is running inside acad, then you already know that the program is running. Just use the Application object or the AcadApplication object if you are using the COM api.

 

using acApp = Autodesk.AutoCAD.ApplicationServices.Application
using acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 5 of 6
kdub_nz
in reply to: Ed.Jobe

 

 . . . and it never hurts if you name the variables for COM objects so they're easily identifiable and distinguishable.


// Called Kerry in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 6 of 6
josborneW959Y
in reply to: Ed.Jobe

It worked... I forgot to update references, when I did old GetActiveObject also worked. My fault...

 

Thanks!!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


AutoCAD Beta