hexagon logo

Program to Open PC-DMIS

I am currently attempting to write a program (VB.NET) that will have a PC-DMIS program's file name passed to it. This program should then start PC-DMIS if it isn't already running, and open the program that was passed to it. If PC-Dmis is already running, then it should open the program that was passed to it. Then, the program should close, leaving PC-DMIS running. I also want PCDMIS to be opened as Operator Mode.

I am attempting to do this by referncing PCDLRN within the program. Hwoever, I am having little luck with the .OperatorMode=true method.

The reason I am attempting to do this in VB.NET is I will then follow up with some additional programming (saving info to a DB and what not) that would be cumbersome as a .VBS etc.

This PCDMIS 2011 MR1 and VB.NET 2010 (.NET 4.0)

Imports System.IO


Public Class Form1

    Public PCDApp As PCDLRN.Application
    Public PCDPartPrograms As Object
    Public PCDPartProgram As Object

    Public fileName As String = "C:\Work\31580 - 1 - 12345.PRG"


    Private Sub Application_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        If File.GetAttributes(fileName) = FileAttributes.ReadOnly Then
            File.SetAttributes(fileName, FileAttributes.Normal)
        End If

        StartApplication(fileName)

    End Sub ' Application_Load



    Public Sub StartApplication(ByVal _fileName As String)

        PCDApp = CreateObject("PCDLRN.Application")
        PCDPartPrograms = PCDApp.PartPrograms

        PCDApp.Visible = True
        PCDPartPrograms.Open(_fileName, "CMM1")

    End Sub


End Class
  • We could do that, but the PLM system (Dassault Systemes' SmarTeam) we are looking to store the files in changes files to "Read Only", which PC-DMIS has a fit about. So, that flag needs to be cleared. Also, I am looking to introduce some logging that will compliment the execution which I want to tie into the application. For whatever reason, the application seems to be working fine in that regard now. But, now I am getting a strange behavior when I run the application with Operator Mode Turned off. When PC-DMIS exits, the PCDLRN is still running in Task Manager.

    Here is the entire code:

    Imports System.IO
    
    Public Class Form1
    
        Public PCDApp As PCDLRN.Application
        Public PCDPartPrograms As Object
        Public PCDPartProgram As Object
    
        Public fileName As String = "C:\SmarTeam\Work\3337 - 11100.087574.PRG"
        'Public fileName As String = "C:\SmarTeam\Work\31580 - 1 - 12345.PRG"
    
    
        Private Sub Application_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            File.SetAttributes(fileName, FileAttributes.Normal)
    
            StartApplication(fileName)
            EndForm()
        End Sub ' Application_Load
    
    
        Public Sub StartApplication(ByVal _fileName As String)
    
    
            On Error Resume Next
            PCDApp = System.Runtime.InteropServices.Marshal.GetActiveObject("PCDLRN.Application")
    
            If PCDApp Is Nothing Or Err.Number <> 0 Then
                PCDApp = CreateObject("PCDLRN.Application")
            End If
    
            PCDPartPrograms = PCDApp.PartPrograms
    
            PCDApp.Visible = True
            PCDApp.SetActive()
            PCDApp.Maximize()
    
            ''PCDApp.OperatorMode = True
            'CheckBox1.Checked = True
    
            PCDPartProgram = PCDPartPrograms.Open(_fileName, "CMM1")
    
        End Sub
    
    
        Private Sub EndForm()
            Me.Close()
        End Sub
    
    
        Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
    
            PCDApp.OperatorMode = CheckBox1.Checked
    
        End Sub
    
    End Class
    
    
  • Would this make any difference?

    Change
    Public PCDApp As PCDLRN.Application

    to
    Public PCDApp As Object
  • If you do this manually (not using your application) does it display the same behaviour?
  • ... the PLM system (Dassault Systemes' SmarTeam) we are looking to store the files in changes files to "Read Only", which PC-DMIS has a fit about. ...


    PC-DMIS 2012 with 'autosave' turned off seems to work OK with write protected .PRG files - no 'fits', just a friendly reminder if you try to overwrite the file.

    Edit: 'DocumentRecovery' is what I meant with 'autosave'...
  • If you do this manually (not using your application) does it display the same behaviour?


    No. Launching PCDMIS manually does not mimic this behavior.
  • This issue has been resolved. The COM objects were not being disposed of properly.

            Public PCDApp As PCDLRN.Application
            Public PCDPartPrograms As Object = Nothing
            Public PCDPartProgram As Object = Nothing
    
            ...
    
            System.Runtime.InteropServices.Marshal.ReleaseComObject(PCDPartProgram)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(PCDPartPrograms)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(PCDApp)
    
  • Great! Thanks for providing the solution and not just "fixed it"!

  • That definitely works with VBA in Excel 2010. Fascinating - I can switch PC-DMIS in and out of Operator mode without exiting! Opens new vistas for my own controlling program (written in Delphi Pascal).


    So, I got tired of my whole machine logging out when my application crashed trying to start PCDMIS in Operator Mode. Here is a key in the PCDMIS registry that stops that behavior. Set it to 'False' and save.
  • This issue has been resolved. The COM objects were not being disposed of properly.

            Public PCDApp As PCDLRN.Application
            Public PCDPartPrograms As Object = Nothing
            Public PCDPartProgram As Object = Nothing
    
            ...
    
            System.Runtime.InteropServices.Marshal.ReleaseComObject(PCDPartProgram)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(PCDPartPrograms)
            System.Runtime.InteropServices.Marshal.ReleaseComObject(PCDApp)
    


    hey brian, i just went through this too, instead of marshaling everything, you can set
    PCDAPP.UserExit = true
    that this will actually close pc-dmis when you use
    PCDAPP.Close()