hexagon logo

Automation Issue with .NET

When opening and executing PC-DMIS programs from a Windows VB.Net application, on SOME machines SOME of the time, the main PC-DMIS window will not display.
Only the PC-DMIS Execution Window is displayed - PC-DMIS User Prompts are essentially unavailable. In this case, closing PC-DMIS via task manager is the only solution.

My open and Execute construct are (essentially) the following:

PCDMISapplication = New PCDLRN.Application
PCDprograms = PCDMISapplication.PartPrograms
PCDMISapplication.Visible = True
PCDpartPrg = PCDMISprograms.Open(pathAndFilename, machineName)
Threading.Thread.Sleep(2000) ' Wait while program opens
PCDMISapplication.WaitUntilReady(200)
PCDpartPrg.Visible = True
PCDpartPrg.EXECUTE()


I suspect the solution is to add a variable the Thread.Sleep() and WaitUntilReady() methods and increase the times until this stops. But that doesn't explain the random nature.

Another Thought: Since I'm also handling some PartProgram Object events, I'm tempted to put the PCDpartPrg.Visible = True in a regularly fired event. But this seems like wikkid overkill. Again, I'd just like to understand the nature of this random problem.

Any thoughts?

Thanks,
Dan (in DFW - supposedly)
  • When opening and executing PC-DMIS programs from a Windows VB.Net application, on SOME machines SOME of the time, the main PC-DMIS window will not display.
    Only the PC-DMIS Execution Window is displayed - PC-DMIS User Prompts are essentially unavailable. In this case, closing PC-DMIS via task manager is the only solution.

    My open and Execute construct are (essentially) the following:

    PCDMISapplication = New PCDLRN.Application
    PCDprograms = PCDMISapplication.PartPrograms
    PCDMISapplication.Visible = True
    PCDpartPrg = PCDMISprograms.Open(pathAndFilename, machineName)
    Threading.Thread.Sleep(2000) ' Wait while program opens
    PCDMISapplication.WaitUntilReady(200)
    PCDpartPrg.Visible = True
    PCDpartPrg.EXECUTE()
    


    I suspect the solution is to add a variable the Thread.Sleep() and WaitUntilReady() methods and increase the times until this stops. But that doesn't explain the random nature.

    Another Thought: Since I'm also handling some PartProgram Object events, I'm tempted to put the PCDpartPrg.Visible = True in a regularly fired event. But this seems like wikkid overkill. Again, I'd just like to understand the nature of this random problem.

    Any thoughts?

    Thanks,
    Dan (in DFW - supposedly)


    Dan, I'm a complete idiot when it comes to VBA but it sounds like to me that some machines are being forced into operator mode. I know there is actually a VBA registry setting for Blade Runner but I'm not sure how you would go about finding a solution to this for your problem if in fact this is what's going on.
  • Subscribed to see if the problem is solved.

    - Josh in DFW (really)
  • I've had issues with similar before - is it actually not visible, or is it just not getting the focus (i.e. coming to the front)?
  • Also, although it's not the supposed better method I have better luck using the old COM method of...

    PCDAPP = createobject("pcdrln.application.7.1")
  • The problem is solved - or at least it's not recurring in the limited machines' testing I've done.

    The solution was related to one (or a combination of some) of three things below.

    1) Re-Install of most current version of PC-DMIS (64 bit) on my TestPC (that almost always runs PC-DMIS offline).
    2) Set the PC-DMISapplicationObject.OperatorMode=False before calling PC-DMISapplicationObject.Visible or PC-DMISapplicationObject.SetActive methods.
    3) Check PC-DMISapplicationObject.Visible with an event during PC-DMIS program Execution. Iff False, set Visible=True and call SetActive.

    Re: #3 above, limited testing/logging shows repeated True values for my event check of PC-DMISapplicationObject.Visible.

    BTW, anyone know significance of the Application.SetActive() return value (boolean)? If FALSE, does PC-DMIS fails to set the main window 'Active'? There's little info in the PCDMISbasic.chm file...


    Thanks Everyone for your suggestions.
  • Hey Dan,

    I don't recall ever running into the issue your having, but there are a couple of things I do differently that may help you:

    1. Wait until PC-DMIS is fully instantiated and initialized before setting any application properties or sending commands;
    2. Use COM methods (CreateObject/GetObject) as mentioned by NinjaBadger - I've experienced some strange behaviors when trying to use PCDLRN's New() constructor.



    An abbreviated version of my start functions would look like this:

    [COLOR="#008000"]'Application property scoped as needed[/COLOR]
    [COLOR="#0000FF"]Public Property[/COLOR] pcdApp [COLOR="#0000FF"]As[/COLOR] PCDLRN.[COLOR="#008080"]Application[/COLOR]
    
    
    [COLOR="#0000FF"]Public Function[/COLOR] StartPCDMIS(IsVisible [COLOR="#0000FF"]As Boolean[/COLOR]) [COLOR="#0000FF"]As Boolean[/COLOR]
    
       [COLOR="#0000FF"]Try[/COLOR]
          [COLOR="#008000"]'GetObject used to start PC-DMIS or grab an existing instance[/COLOR]
          [B]pcdApp = [COLOR="#0000FF"]DirectCast[/COLOR](GetObject([COLOR="#B22222"]""[/COLOR],[COLOR="#B22222"]"PCDLRN.Application"[/COLOR]), PCDLRN.[COLOR="#008080"]Application[/COLOR])[/B]
    
          pcdApp.WaitUntilReady(60)
          Threading.Thread.Sleep(2000)
    
          [COLOR="#0000FF"]If[/COLOR] pcdApp [COLOR="#0000FF"]Is Nothing Then Return False[/COLOR]
    
          [COLOR="#008000"]'Visible property not addressed until after WaitUntilReady and Thread.Sleep[/COLOR]
          [B]pcdApp.Visible = IsVisible[/B]
    
          [COLOR="#0000FF"]Return[/COLOR] ([COLOR="#0000FF"]Not[/COLOR] pcdApp [COLOR="#0000FF"]Is Nothing[/COLOR])
    
       [COLOR="#0000FF"]Catch[/COLOR] ex [COLOR="#0000FF"]As Exception[/COLOR]
          [COLOR="#0000FF"]Throw New[/COLOR] [COLOR="#008080"]Exception[/COLOR]([COLOR="#B22222"]"Start PC-DMIS : "[/COLOR] + ex.Message)
       [COLOR="#0000FF"]End Try[/COLOR]
    
    [COLOR="#0000FF"]End Function[/COLOR]
  • I had issues with pc-dmis coming to the front (it was visible, just behind my main form)

    This was usually just in the first instance, after I'd given it the focus (by clicking on it in the task bar) it would be shown and hidden as programmed to.

    It wasn't always either. I tried all manor of showing/hiding and SetActive with no joy. Offline it always worked, online it was hit and miss.


    In the end I used this method to make it reliably come to the front.


            Dim prc As Process = Process.GetProcessesByName("PCDLRN").FirstOrDefault
            Dim element As AutomationElement = AutomationElement.FromHandle(prc.MainWindowHandle)
            If Not element Is Nothing Then
                element.SetFocus()
            End If