hexagon logo

Creating and Controlling Input Dialog with C#

I using C# to interact with PCDLRN.dll. Currently, our programs have a manual alignment at the beginning and then a comment that pauses execution prior to switching to direct computer control mode. What I am trying to do is, after manual alignment when the program is switching to direct computer control, I want to be able to press a button on my web app that clicks OK on the comment prompt that continues the DCC alignment and continues on with the program. I found references to a Comment method that has a "PressOkButton" function but I can't figure out how to use that in tandem with the Application or PartProgram that I have in memory.

Any thoughts on how to approach this via C#?
  • Just send an ENTER or SPACE keypress (if the messagebox has focus, that is) from your app?
  • My first attempt was to use the built in .NET Automation tools to find the window and click the button. However, I noticed that there are supposedly built in PCDMIS functions that should be able to control this so I wanted to try that first.
  • Do you have any examples of how to use this? VB or C# preferably? I have an instance of the Application and the PartProgram but in the object hierarchy it says that PCDMessageBox is a parent of Application and Program so I have no idea how to access the message box.
  • hi,

    here is an event that gives you the msgbox object when it pops up
    https://docs.hexagonmi.com/pcdmis/20...oxOpen_EV.html


    as soon as you have the object you can press buttons with this function
    https://docs.hexagonmi.com/pcdmis/20...essButton.html


    by the way:
    I have no popup after the manual alignment is done, what is that good for you?
  • Update: I figured out how to do this with the built in C# AutomationUI. I don't know if there is a VB equivalent. I am not sure which version I prefer so I listed them both just in case you're a crazy person like me and you like options. Also pay attention to the whitespace in the string "Execution " because it's important.

    Loop Version
                    var windowNames = new string[] { "PC-DMIS CAD++ 2021.1 (release) - Offline", "Execution ", "PC-DMIS Message", "OK" };
    
                    AutomationElement currentLayer = AutomationElement.RootElement;
                    foreach(var windowName in windowNames)
                    {
                        if(currentLayer == null)
                        {
                            throw new NullReferenceException($"Automation Element not found windowName: {windowName}");
                        }
                        var condition = new PropertyCondition(AutomationElement.NameProperty, windowName);
                        currentLayer = currentLayer.FindFirst(TreeScope.Children, condition);
                    }
    
                    var invokePattern = currentLayer.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                    invokePattern.Invoke();
    


    Imperative Version
    
                    Condition condition = new PropertyCondition(AutomationElement.NameProperty, "PC-DMIS CAD++ 2021.1 (release) - Offline");
                    AutomationElement pcdWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, condition);
    
                    condition = new PropertyCondition(AutomationElement.NameProperty, "Execution ");
                    AutomationElement executionWindow = pcdWindow.FindFirst(TreeScope.Children, condition);
    
                    condition = new PropertyCondition(AutomationElement.NameProperty, "PC-DMIS Message");
                    AutomationElement pcdMessageWindow = executionWindow.FindFirst(TreeScope.Children, condition);
    
                    condition = new PropertyCondition(AutomationElement.NameProperty, "OK");
                    AutomationElement okButton = pcdMessageWindow.FindFirst(TreeScope.Children, condition);
    
                    var invokePattern = currentLayer.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;
                    invokePattern.Invoke();