Event AcadDocument_Activate() in DotNET

Event AcadDocument_Activate() in DotNET

Anonymous
Not applicable
1,904 Views
7 Replies
Message 1 of 8

Event AcadDocument_Activate() in DotNET

Anonymous
Not applicable

Hi all,

I'm looking for a way to autostart my dotnet macro according to a certain drawing opening.

 

I know how to auto netload my dll

I know in vba using events to start the macro when my drawing is opened :

 

Private Sub AcadDocument_Activate()
   Start.MyVbaMacro
End Sub

 

But how do I manage it in DotNET? I don't want to use vbaenabler...

 

Thanks,

Michel

0 Likes
1,905 Views
7 Replies
Replies (7)
Message 2 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I know in vba using events to start the macro when my drawing is opened

To get EventHandler defined you first have to load an application. At least within one application you don't have a chance to get loaded only for specific drawings as the descission "load the DLL or not" has to be done by a program and so it has to be loaded at least the part that defines the EventHandler.

 

To automatically get dotNET applications loaded look to >>>this blog<<< to see how you can load a dotNET-DLL automatically.

 

And one primitive method (if you don't want to make changes to the registry) could be to write a LISP-command into the ACAD.LSP so the DLL get loaded with AutoCAD-startup:

(command "_-NETLOAD" "\\mypath\\mydll.dll")

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 8

Anonymous
Not applicable

Thanks for the answer Alfred, the blog is helpfull...

 

AutoNetloading my dll is OK.

 

My problem is :

 

1) I open a specific drawing

2) my macro autostarts only when this specific drawing is opened.

 

In vba, I add vba code (AcadDocument_Activate) in this specific drawing, which trigger my macro.

 

Is it possible to add dotnet events in a spécific dwg?? It seems no... Is there another way??

 

Cheers,

Michel

 

 

0 Likes
Message 4 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> Is it possible to add dotnet events in a spécific dwg??

No, you can load your DLL with the application with a defined event handler that catches every drawing-open ... then check if the DWG is a drawing of interest or not, so run your commands for this DWG (or not).

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 8

cincir
Enthusiast
Enthusiast

You can use 

public event DocumentCollectionEventHandler DocumentToBeActivated;

 event of Application.DocumentManager. but you must run it in ApplicationContext.

0 Likes
Message 6 of 8

Anonymous
Not applicable

 

Hummm, Lovely DotNet automations ;-(((

 

I don't know the name of that drawing... Perhaps the user had to rename it according to naming convention purpose...

 

I think I'm going to make a classic Menu Button, and check first if the drawing contains the prerequisites...

 

Thanks for help.

M.

 

0 Likes
Message 7 of 8

cincir
Enthusiast
Enthusiast

if not my memory serves me wrong Database object has some fields for user defined values. you can check them also to determine if it is proper Document to process.

 

you are welcome.

0 Likes
Message 8 of 8

Anonymous
Not applicable

hi. i think you can use the var USERI1, USERI2 ... 5

this saved in the drawing so you need to check a value in this var when the doc opened

 

0 Likes