hexagon logo

Launch PC-DMIS in Operator Mode through VB

I searched through the forum and couldn't find a solution for my issue.

I was wondering if it is possible to launch pc-dmis in operator mode from a script.

I made a front end GUI and wanted to be able to display pc dmis (in operator mode) while it's running a program. Right now I just hide everything besides the Execution window.

I'll attach the code I'm using to start pc dmis if it helps

TIA

Sub PCDMISProgramRun()


Dim PCDApp, PCDPartProgram, PCDProgramCommand


''

Set PCDApp = CreateObject("PCDLRN.Application") 'Opens PC-DMIS

    If Not PCDApp.WaitUntilReady(300) Then
        MsgBox "Machine did not initialize, Exiting"
        Exit Sub
    End If

    PCDApp.Visible = False
  • From the pcd basic manual (aka never used it myself but hey I found info in the help guide!):

    To start PC-DMIS using Automation from another application, use CreateObject or GetObject to return an Application object.
    Launching PC-DMIS With Startup Options

    Because of an inherent weakness in the way Microsoft designed the CreateObject function, the CreateObject doesn't allow startup parameters. This means when the code executes it will launch PC-DMIS always in ONLINE mode.
    However, there is a way around this. Your code can dynamically create a special startup file that will cause PC-DMIS to launch with specific startup options.
    In order to launch PC-DMIS via automation with a startup file you must do the following:
    • Create a text file named AutomationStartupOptions.txt.
    • Create a single line of text in the file with the available startup options. The PC-DMIS specific startup options include the following:
    /f - Launches in Offline mode.
    /o - Launches in Operator mode.
    /d - Launches in Debug mode.
    /r - Launches in Reverse Axes mode
    /postin - Launches in import mode. PC-DMIS will automatically import a specified file.
    /postout - Launches in export mode. PC-DMIS will automatically export a specified file.
    The line of text would look like this: /f /o /d /r /postin /postout
    • Launch PC-DMIS via automation.
    When PC-DMIS starts, it checks to see if the AutomationStartupOptions.txt file exists. If it does, then it uses the file to set the necessary flags. However, when PC-DMIS closes, it will delete the text file. This means that the code you use to launch PC-DMIS must also create the needed text file on the fly or must rename an existing file to AutomationStartupOptions.txt. See the "Example Code from C++" below.
    Automating in Online Mode: If you are trying to launch PC-DMIS in online mode, please note that the AutomationStartupOptions.txt file should not contain the /f startup parameter. Also, the machine parameter specified when using the Open or New methods of the PartPrograms object determines whether or not the measurement routine will run in offline or online modes. Of online mode, this parameter should be "CMM1".

    Example

    Dim App as Object.
    Set App = CreateObject("Pcdlrn.Application")

    C++ example:
    // Create my startup file
    
      int nIndex;
    
      CString szFileName, szLine(_T("/f"));
    
      GetModuleFileName (AfxGetInstanceHandle(), szFileName.GetBuffer (_MAX_PATH), _MAX_PATH);
    
      szFileName.ReleaseBuffer();
    
      nIndex = szFileName.ReverseFind('\\');
    
      szFileName = szFileName.Left(nIndex);
    
      szFileName += _T("\\AutomationStartupOptions.txt");
    
      CStdioFile StartupFile;
    
      if( StartupFile.Open(szFileName, CFile::modeCreate|CFile::modeWrite|CFile::typeText) )
    
      {
    
        StartupFile.WriteString(szLine);
    
        StartupFile.Close();
    
      }
    


    In other words create the text file where ever PCDLRN.exe resides.
  • Awesome, that works perfectly.

    Thank you for your help.

    Solution:

    I inserted this code to create the text file before launching PC-DMIS

    Dim scrObj
        Dim textObj
    
        Set scrObj = CreateObject("Scripting.FileSystemObject")
        Set textObj = scrObj.CreateTextFile("C:\Program Files\Hexagon\PC-DMIS 2019 R1 64-bit\AutomationStartupOptions.txt", True)
        textObj.WriteLine ("/o")
        textObj.Close


  • As an alternative, couldn't you start PC-DMIS in Operator mode with the Shell (or Excec, or whatever it's called in VB) function, and then use GetObject to connect to it?
    I haven't tried it with Basic, but can definitely do it like that with my compiled Delphi Pascal programs.
  • As an alternative, couldn't you start PC-DMIS in Operator mode with the Shell (or Excec, or whatever it's called in VB) function, and then use GetObject to connect to it?
    I haven't tried it with Basic, but can definitely do it like that with my compiled Delphi Pascal programs.


    Yeah that would work and it is called Shell.


    I think you can even just use CreateObject to get hold of an already open instance of PC-Dmis
  • As an alternative, couldn't you start PC-DMIS in Operator mode with the Shell (or Excec, or whatever it's called in VB) function, and then use GetObject to connect to it?
    I haven't tried it with Basic, but can definitely do it like that with my compiled Delphi Pascal programs.


    Yes that does work as well, I just tested it. The shell method takes a little less code to do so I'll use that in startup now

    The reason I use the CreateObject method is because of connecting to an already open PC-DMIS like stated.

    Thanks for your suggestions


  • Yes that does work as well, I just tested it. The shell method takes a little less code to do so I'll use that in startup now

    The reason I use the CreateObject method is because of connecting to an already open PC-DMIS like stated.

    Thanks for your suggestions


    I think everyone is talking about GetObject() instead of CreateObject() if I'm not mistaken and yes you can also iterate thru the list of running processes and tag your Pcd Object to it... kinda what GetObject() is.

    PcDmis ONLY runs one pcdlrn instance so most of us do just fine with CreateObject() but if for example you're doing some work with Excel and while debugging you notice more than one instance of Excel process that's because Excel allows more than one process to be ran at a time (good spot to use GetObject() first else if not found use CreateObject() assuming no other Excel workbooks are to be open while your executable is running).

    Helpful link:
    https://docs.microsoft.com/en-us/off...bject-behavior
  • This is what I used.

    Dim PCDApp
    PCDApp = CreateObject("PCDLRN.Application")
    If PCDApp.Visible = False Then
    PCDApp.OperatorMode = True
    PCDApp.Visible = True
    End If