Force Quit using vb for v2012

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Force Quit using vb for v2012

    More script help please.

    Searching this forum, there was a related topic which included a link to another forum which I cant access.

    Operators continue to open a second program. This second program is to align a fixture and only uses manual points
    Firstly, I was thinking of forcing the program "Quit" in vbscript. code:
    Code:
    Sub Main()
    Dim PCDMISW, PCDPartPrograms, PCDPartProgram, PCDCommands, PCDCommand
    Set PCDMISW = CreateObject ("PCDLRN.Application")
    Set PCDPartPrograms = PCDMISW.PartPrograms
    Set PCDPartProgram = PCDMISW.ActivePartProgram
    Set PCDCommands = PCDPartProgram.Commands
    PCDPartProgram.ExecutionWindow.Stop()
    PCDPartProgram.ExecutionWindow.CancelExecution()
    PCDPartProgram.Quit()
    End Sub
    The above code doesn't work (unsurprisingly).. What have I done wrong?

    Searching methods and event, is it possibly to use script to force the alignment program as the active program; "Activate()"
    Can I get guidance on this too?

    TIA,
    p

  • #2
    You can't use the internal basic scripting to quit (or close) the active program because you're essentially trying to close the program that called the script. You would need to use an external application to maybe watch the PC-Dmis application events and look for addition programs being opened. You should, however, be able to check how many programs are open and then cancel execution and prompt the user if there are more than one.
    Neil Challinor
    PC-DMIS Product Owner

    T: +44 870 446 2667 (Hexagon UK office)
    E: [email protected]

    Comment


    • #3
      Why not just just put a label and a comment at the bottom of your program and then at the top make a GOTO so the operator will hit the comment when they execute the program and only you will know to avoid it.

      Code:
      [B]GOTO/PROG_END[/B]
      PNT1 =FEAT/CONTACT/VECTOR POINT/DEFAULT,CARTESIAN
      THEO/<0,0,0>,<0,0,1>
      ACTL/<0,0,0>,<0,0,1>
      TARG/<0,0,0>,<0,0,1>
      SHOW FEATURE PARAMETERS=NO
      SHOW CONTACT PARAMETERS=NO
      PNT2 =FEAT/CONTACT/VECTOR POINT/DEFAULT,CARTESIAN
      THEO/<0,0,0>,<0,0,1>
      ACTL/<0,0,0>,<0,0,1>
      TARG/<0,0,0>,<0,0,1>
      SHOW FEATURE PARAMETERS=NO
      SHOW CONTACT PARAMETERS=NO
      PNT3 =FEAT/CONTACT/VECTOR POINT/DEFAULT,CARTESIAN
      THEO/<0,0,0>,<0,0,1>
      ACTL/<0,0,0>,<0,0,1>
      TARG/<0,0,0>,<0,0,1>
      SHOW FEATURE PARAMETERS=NO
      SHOW CONTACT PARAMETERS=NO
      [B]PROG_END[/B] =LABEL/
      COMMENT/OPER,NO,FULL SCREEN=YES,AUTO-CONTINUE=NO,
      [B]DO NOT RUN THIS PROGRAM!
      IT IS ONLY FOR FIXTURE ALIGNMENT![/B]

      Comment


      • #4
        Thanks guys.

        @LazerJay,
        They need to run the fixture alignment but the problem is that the second program opens OFFLINE and when the operator takes the actual points, they are not recorded.
        It's painful - the operators take all the points in the correct order, then go back to the PC and click "Continue" 7 times (cos its offline and manual hits), the program "finishes" and then they run the production program (order new SM25-1) :|

        @Neil,
        Any pointers on how I can do that?

        Many thanks again lads!

        Comment


        • #5
          perinho , this should do it. If you open this app, it will either open or connect to PC-Dmis (depending on if it is already open or not) and then sit in the background watching for multiple open programs. If a second program is opened on top of an existing one, it will close all programs and re-open the latest one on-line. Follow this link to download the executable file https://sendit.hexagon.com/message/l...N3JQZg5Kc4yGkf. It will be only be available until Dec 5th 2020.

          Here is the source code for reference.
          Code:
          Public Class Form1
          Dim LblTxt As String
          Dim MsgTxt As String
          Dim PrgNm As String
          Dim ThereCanBeOnlyOne As Boolean
          Dim PCDapp As PCDLRN.Application
          Dim PPs As PCDLRN.PartPrograms
          Dim PP As PCDLRN.PartProgram
          Dim ExecutionWindow As PCDLRN.ExecutionWindow
          Dim WithEvents PCD_EVENTS As PCDLRN.ApplicationObjectEvents
          
          Declare Auto Function FindWindow Lib "USER32.DLL" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
          Public Function PCDExists() As Boolean
          Dim lpclassname As String
          Dim Result As Integer
          PCDExists = True
          lpclassname = "WilcoxAssociatesIncPC-DMISWndClass"
          Result = FindWindow(lpclassname, vbNullString)
          If Result = 0 Then
          PCDExists = False
          End If
          End Function
          
          Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          Me.Visible = True
          ThereCanBeOnlyOne = True
          Me.TopMost = True
          LblTxt = "When PC-Dmis is launched using this app, it will sit in the background" & vbNewLine & "checking how many programs are open." & vbNewLine & vbNewLine
          LblTxt = LblTxt & "If more than one part program is opened, all programs will be closed" & vbNewLine & "and the most recently opened program" & vbNewLine
          LblTxt = LblTxt & "will be re-opened online"
          Label1.Text = LblTxt
          Label2.BackColor = Color.Orange
          Label2.Text = "Connencting to PC-Dmis - please wait"
          PCDapp = CreateObject("PCDLRN.application")
          PCDapp.WaitUntilReady(600)
          PCDapp.Visible = True
          PPs = PCDapp.PartPrograms
          
          If PCDExists() = True Then
          Me.TopMost = False
          Me.SendToBack()
          
          Label2.Text = "CONNECTED"
          Label2.BackColor = Color.LawnGreen
          Else
          Me.TopMost = True
          Label2.Text = "NOT READY"
          Label2.BackColor = Color.Red
          End If
          
          Timer1.Enabled = True
          Timer1.Interval = 500
          End Sub
          
          Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          If PPs.Count <> 0 Then
          PP = PCDapp.ActivePartProgram
          End If
          If PPs.Count > 1 Then
          PP = PCDapp.ActivePartProgram
          PrgNm = PP.FullName
          ThereCanBeOnlyOne = False
          MsgTxt = "You opened multiple programs." & vbNewLine & "Only the first program can connect to the machine." & vbNewLine
          MsgTxt = MsgTxt & "All subsequently opened programs are offline" & vbNewLine & vbNewLine
          MsgTxt = MsgTxt & "All programs were closed." & vbNewLine & "and your most recently opened one was re-opened online"
          Me.TopMost = True
          Label1.Text = MsgTxt
          PPs.CloseAll()
          PP = PPs.Open(PrgNm, "cmm1")
          End If
          End Sub
          
          Private Sub KillPCD()
          For Each Process In System.Diagnostics.Process.GetProcesses()
          If InStr(UCase(Process.ProcessName), "PCDLRN") > 0 Then
          Process.Kill()
          End If
          Next
          End Sub
          
          Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          KillPCD()
          Me.Close()
          End Sub
          End Class
          Neil Challinor
          PC-DMIS Product Owner

          T: +44 870 446 2667 (Hexagon UK office)
          E: [email protected]

          Comment


          • #6
            KillPCD()

            When Skynet takes over, PC-DMIS will come looking for you, neil.challinor
            PC-DMIS CAD++ 2o19 R1 SP11

            Comment


            • #7
              neil.challinor
              Serious stuff! Thank you so much. This is basically doing the job for the operator - they'll be redundant soon. lol
              Myself along with 'em.

              Comment

              Related Topics

              Collapse

              Working...
              X