hexagon logo

Start PC-DMIS in Operator Mode via Code

I would like to start PC-DMIS in operator mode, specifically to disable the Edit Window. Here is the snippet of the C# code:
app = (PCDLRN.Application)Activator.CreateInstance(Type.GetTypeFromProgID("PCDLRN.Application"));
progs = app.PartPrograms;
events = app.ApplicationEvents;
app.Visible = true;
app.OperatorMode = true;

Unfortunately, the user can still open the Edit Window (View -> Edit Window) to make changes to the program. Does anyone have a sample code that does what I'm trying to do?

Thanks.
  • We created a tool that uses the API to automatically export the measurement to a specific format after the program is executed. To ensure a robust connection between the PC-DMIS application and the tool, we need to run the tool and then start PC-DMIS application.

  • 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 part program 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")


    Hope this helps.
  • Yes, thanks for posting the solution. It works! However, using the AutomationStartupOption.txt file, I'm seeing a difference in the PC-DMIS behavior when exiting the application. Open PC-DMIS in operator mode ("C:\Program Files\Hexagon\PC-DMIS xxx\Launcher\HexagonLauncher.exe" LauncherPC-DMIS.config /o), it forces the PC to sign out the user when exiting the application. Using the AutomationStartupOption.txt and automation, it does not. Have you observed similar behavior as well? I would like to sign out the user. Is there a way to do so? Thanks!
  • No clue - it "should" behave the same as when starting it with command-line switches. Are you starting PC-DMIS using your application, or is it already started when your app connects to it?

    Maybe try closing your app (that started PC-DMIS) before closing PC-DMIS to see if it will logoff?
  • Verify that the setting OMLogout in Settings Editor is set to TRUE
  • Verified that the setting OMLogout in Settings Editor is indeed set to TRUE. Tried closing the app before closing PC-DMIS. The behavior still exists.
  • I would like to start PC-DMIS in operator mode, specifically to disable the Edit Window. Here is the snippet of the C# code:
    app = (PCDLRN.Application)Activator.CreateInstance(Type.GetTypeFromProgID("PCDLRN.Application"));
    progs = app.PartPrograms;
    events = app.ApplicationEvents;
    app.Visible = true;
    app.OperatorMode = true;
    

    Unfortunately, the user can still open the Edit Window (View -> Edit Window) to make changes to the program. Does anyone have a sample code that does what I'm trying to do?

    Thanks.


    Loop your code non-stop! As soon as the operator opens the Edit window the loop should be coming around the bend to hide it again before operator can even distinguish the text in the Edit window. Not the best solution but a multi threader never hurt no one.

    Edit:
    Grab a hold of the window handle and simulate the exit button (they're not 'send-keys' though). Did something similar though it was to use the ESC key to exit absolutely anything sub-menu opened in PcDmis like it would in MasterCam, Solidworks, etc everyone else!

    Use of Microsoft Spy++ and http://www.pinvoke.net/ should get you moving quickly.

    Here's more: https://www.codeproject.com/Articles/141842/Automate-your-UI-using-Microsoft-Automation-Framew

    It's called "UI Automation" btw I just remembered.
  • Just look for the PCDLRN.Application all the time. As soon as app = null/nil/nothing in your code above, trigger a computer logoff in your app.