• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 17
    Registered: ‎02-19-2007

    Event AcadDocument_Activate() in DotNET

    177 Views, 7 Replies
    01-25-2012 07:37 AM

    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

    Please use plain text.
    *Expert Elite*
    Posts: 6,456
    Registered: ‎06-29-2007

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 07:48 AM in reply to: Mitch_31

    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
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Contributor
    Posts: 17
    Registered: ‎02-19-2007

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 08:07 AM in reply to: alfred.neswadba

    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

     

     

    Please use plain text.
    *Expert Elite*
    Posts: 6,456
    Registered: ‎06-29-2007

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 08:15 AM in reply to: Mitch_31

    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
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Active Contributor
    cincir
    Posts: 32
    Registered: ‎08-12-2011

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 08:15 AM in reply to: Mitch_31

    You can use 

    public event DocumentCollectionEventHandler DocumentToBeActivated;

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

    Please use plain text.
    Contributor
    Posts: 17
    Registered: ‎02-19-2007

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 08:28 AM in reply to: cincir

     

    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.

     

    Please use plain text.
    Active Contributor
    cincir
    Posts: 32
    Registered: ‎08-12-2011

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 09:15 AM in reply to: Mitch_31

    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.

    Please use plain text.
    Mentor
    Posts: 258
    Registered: ‎01-27-2010

    Re: Event AcadDocument_Activate() in DotNET

    01-25-2012 10:18 AM in reply to: cincir

    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

     

    Please use plain text.