Jump to content
Kruxe

How to Get Application Events - (Moved)

Recommended Posts

Hey guys,

AutoIT noob here, I was wondering if you guys could help me figure something out i have been struggling with for quite some time now. Posted is an example of VB code tasked with listening to an application and performing an action once a specific event takes place in the application. I have tried so many different ways to do the same in Autoit but have had absolutely no luck in grabbing the app events. I was wondering how you guys would go about setting something like this up in autoit and if you could please explain in detail i would really appreciate it!

 

Public Class Form1
    Dim PCDApp As PCDLRN.Application
    Public WithEvents PartEvents As PCDLRN.PartProgram
    Public WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
    Dim xlApp As Excel.Application
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        PCDApp = CreateObject("PCDLRN.Application")
        AppEvents = PCDApp.ApplicationEvents
        PartEvents = PCDApp.ActivePartProgram

    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Start()
    End Sub
    Sub Start()
        ' This is the subroutine to run to start the script
        Me.Hide()
        HideExcel()
    End Sub
    Private Sub HideExcel()
        xlApp = CreateObject("Excel.Application")
        Dim intAnswer As Integer
        intAnswer = MsgBox("Do you want to make Excel invisible? For this test, you should click Yes. It will become visible when you open a measurement routine.", vbYesNo, "Hide Excel?")

        If intAnswer = vbYes Then
            xlApp.Visible = False
        Else
            xlApp.Visible = True

        End If

        LaunchPCDMIS()
    End Sub
    Sub LaunchPCDMIS()
        PCDApp.Visible = True
    End Sub

    Private Sub AppEvents_OnOpenPartProgram(PartProg As PartProgram) Handles AppEvents.OnOpenPartProgram
        ' Event subroutine. This activates when you OPEN a measurement routine.
        PartProg = PCDApp.ActivePartProgram
        xlApp.Visible = True
        MsgBox("Measurement routine " & PartProg.Name & " opened. Excel should also be visible.")
    End Sub

    Private Sub AppEvents_OnStartExecution(PartProg As PartProgram) Handles AppEvents.OnStartExecution
        ' Event subroutine. This activates when you START EXECUTION of the measurement routine.
        MsgBox("STARTING EXECUTION OF " & PartProg.Name & ". Click OK to continue.")
    End Sub

    Private Sub AppEvents_OnEndExecution(PartProg As PartProgram, TerminationType As Integer) Handles AppEvents.OnEndExecution
        ' Event subroutine. This activates when you END EXECUTION of the measurement routine.
        MsgBox("ENDING EXECUTION OF " & PartProg.Name & ". Click OK to continue.")
    End Sub

End Class

 

Share this post


Link to post
Share on other sites

As a start please have a look at my Excel Example Scripts in my signature. 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-10-10 - Version 1.5.2.1) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-30 - Version 1.6.2.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Share this post


Link to post
Share on other sites

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team


"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites

@water coming back to this post after some time and im still struggling with it. Im not grasping how i am supposed to set the code up in autoit to be like the VBA code above. I am not familiar with VBA but maybe one of you can what i have gotten so far is this and honestly don't know if its even close..

 

Local $DmisApp = ObjCreate("PCDLRN.Application")
Local $AppEvent = $DmisApp.ApplicationEvents
Local $ActivePartProgram = $DmisApp.ActivePartProgram

ObjEvent($AppEvent, "Worksheet_","OnStartExecution")

While 1

    sleep(10)

WEnd

Func Worksheet_Change()

    MsgBox("","","yes")

EndFunc

 

Share this post


Link to post
Share on other sites

Guys,

I don't think this is as simple as following these examples or, maybe it is! lol. The application I'm trying to capture the events from is kind of setup weird and I think autoit can do it but my syntax is probably incorrect.

the event I am trying to listen for is "OnStartExecution". I have posted a link to the Object Hierarchy chart and hopefully it can explain batter than i can on here. Also in this post is what i have so far for code but I have had absolute 0 success with it.

Local $DmisApp = ObjCreate("PCDLRN.Application")
Local $ActivePartProgram = $DmisApp.ActivePartProgram
Local $AppEvent = $DmisApp.ApplicationEvents

While 1

ObjEvent($AppEvent,"ExEvent_")

Sleep(10)

WEnd
; ...

Func ExEvent_()

   MsgBox("","","EventFired")

EndFunc

 https://docs.hexagonmi.com/pcdmis/2019.1/en/helpcenter/mergedProjects/automationobjects/object_hierarchy_chart.htm

Share this post


Link to post
Share on other sites
Imports PCDLRN

Public Class PCDMIS
    Dim DmisApp As PCDLRN.Application
    Dim DmisPartPrograms As PCDLRN.PartPrograms
    Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
    Private Sub PCDMIS_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            DmisApp = CreateObject("PCDLRN.Application")
            DmisApp.Visible = True
            DmisApp.WaitUntilReady(1000)
            DmisPartPrograms = DmisApp.PartPrograms
            AppEvents = DmisApp.ApplicationEvents
        Catch ex As Exception
            MsgBox(ex.StackTrace)
            Environment.Exit(0)
        End Try
    End Sub
    Private Sub OpenProg_Click(sender As Object, e As EventArgs) Handles OpenProg.Click
        Try
            Hide()
            DmisPartPrograms.Open("", "CMM1")
        Catch ex As Exception
            MsgBox(ex.StackTrace)
        End Try
    End Sub
    Private Sub AppEvents_OnStartExecution(PartProg As PartProgram) Handles AppEvents.OnStartExecution
        MsgBox("Execution started:  " & PartProg.Name)
    End Sub

So this is capturing the event just fine using VB, but i don't want to use VB, i want to use auuutooooiiiiitttt lol

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...