Results 1 to 5 of 5

Thread: ACAD application window events.

  1. #1
    Member
    Join Date
    2015-11
    Posts
    38
    Login to Give a bone
    0

    Default ACAD application window events.

    In C# is there a way to catch the AutoCAD application window events...?
    Im interested in capturing the event that fires when the application window is resized.

    Any and all help appreciated.

    (C# / AutoCAD 2011/12)

  2. #2
    Member
    Join Date
    2015-11
    Posts
    38
    Login to Give a bone
    0

    Default Re: ACAD application window events.

    I've found a way to catch these events but now have a minor problem to solve. The code below only returns the first running version of the AutoCAD application and I would like to have more than one instance of AutoCAD running...

    So, the ideal solution would be to get the AutoCAD application object from the .net dll that’s running.... Is there a way to do this??

    OR does anyone know how to get the processid or something that uniquely identifies the AutoCAD application object that is currently running the .net DLL??

    Code:
    //Obtain AutoCAD application
      acApp = (AcadApplication)Marshal.GetActiveObject(progID);
    //Register WindowMovedOrResized event handler
      acApp.WindowMovedOrResized +=
         new _DAcadApplicationEvents_WindowMovedOrResizedEventHandler
        (acApp_WindowMovedOrResized);
    //Register WindowChanged event handler
      acApp.WindowChanged +=
        new _DAcadApplicationEvents_WindowChangedEventHandler
        (acApp_WindowChanged);
    
    //WindowChanged Event Handler
    void acApp_WindowChanged(AcWindowState WindowState){
    //react to window state change
    }
    //WindowMovedOrResized Event Handler
    void acApp_WindowMovedOrResized(int HWNDFrame, bool bMoved){
    //react to move or resize
    }
    
    //Make sure event handlers are removed.
    acApp.WindowMovedOrResized -=
      new _DAcadApplicationEvents_WindowMovedOrResizedEventHandler
      (acApp_WindowMovedOrResized);
    acApp.WindowChanged -=
      new _DAcadApplicationEvents_WindowChangedEventHandler
      (acApp_WindowChanged);

    (NOTE the code is incomplete and needs 'fleshing out' with the using directives etc. so you can't just cut and paste it into a new project... I’ve built a little demo of it working and will post if anyone is interested.)

  3. #3
    Administrator Ed Jobe's Avatar
    Join Date
    2000-11
    Location
    Turlock, CA
    Posts
    6,420
    Login to Give a bone
    0

    Default Re: ACAD application window events.

    If you get the app object by class id, then its going to be generic and pointing to the current instance. Use the current instance's Application object. Here it is in vb. AcadApplication is the COM Interop version of the .net app.

    Dim app As AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication
    Last edited by Ed Jobe; 2011-11-17 at 10:34 PM.
    C:> ED WORKING....


    LinkedIn

  4. #4
    Member
    Join Date
    2015-11
    Posts
    38
    Login to Give a bone
    0

    Default Re: ACAD application window events.

    Thanks for the reply Ed.

    Modified the code to your suggestion - solves the issue for multiple AutoCAD sessions.

    I have another issue now;

    Launch AutoCAD, Netload .DLL, click the 'Restore Down' on the AutoCAD window, the event WindowChanged does not fire... subsequent clicks of 'Maximise','Restore Down' fires the event every time but never the first time. This occurs when the AcadApp window starts in either Max or Restore Down states.....

    Any Ideas???

  5. #5
    Member
    Join Date
    2015-11
    Posts
    38
    Login to Give a bone
    0

    Default Re: ACAD application window events.

    Well it looks like after hours of looking through the object browser I've found a solution and it works flawlessly...

    Question is, is this ok to use??
    Code:
    using Autodesk.AutoCAD.Internal.Reactors;
    Code:
    ApplicationEventManager cadWinEvnts =
       Autodesk.AutoCAD.Internal.Reactors.ApplicationEventManager.Instance();
    Code:
    cadWinEvnts.ApplicationMainWindowMoved +=
       new ApplicationMainWindowMovedEventHandler(cadWinEvnts_ApplicationMainWindowMoved);
    Code:
    void cadWinEvnts_ApplicationMainWindowMoved(object sender, EventArgs e)
            {
                //Do Somthing
            }

Similar Threads

  1. Application Events
    By pandeysanjay.sun558358 in forum Dot Net API
    Replies: 0
    Last Post: 2011-11-17, 12:38 PM
  2. Application Events Revit 2010
    By Phillip_Miller in forum Revit - API
    Replies: 6
    Last Post: 2009-02-26, 11:39 PM
  3. Hanging application acad.exe (Event ID 1002)
    By paul.leyer in forum AutoCAD 3D (2007 and above)
    Replies: 2
    Last Post: 2008-06-27, 01:42 PM
  4. ACAD.EXE - APPLICATION ERROR ADT 2007
    By doyle.84974 in forum ACA General
    Replies: 7
    Last Post: 2007-11-14, 09:30 PM
  5. What events would you attend? Local events
    By pauljordan in forum CAD Management - General
    Replies: 10
    Last Post: 2006-09-28, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •