hexagon logo

PC-Dmis Automation C#

So I retired as of last July, but had all this stuff about PC-Dmis Automation which I've finally got around to uploading. Don't know it it is of any interest, but here it is.

The zip file has to Visual Studio project folders, both written in C#. One folder is a Class Library which has all the code for connecting with and dynamically interacting with PC-Dmis. The second folder is a C# application with uses the Class Library to connect and interact with PC-Dmis.

I also included two documents one explains how to setup the two Projects the other is about the application program.

Rather than trying to anticipate every possible question, the provided documents should be sufficient for someone familiar with visual studio and C#. Otherwise, I'll watch for questions to show up here. I can't promise to answer every question, given the complexity of what the answer might require. But I have taken phone calls and zoom opens up the possibility to demo live.

Good Luck

https://drive.google.com/drive/folders/1EDMe0GvN6TC_0Fcr_7Zt7_UqH-EV_8o2?usp=sharing
Parents
  • In this tutorial we look at how our C# application can use the PC-Dmis wrapper to interact with PC-Dmis.

    In the previous tutorial we finished with a global variable in the C# DmisMenu application called 'CMMsession' which is an instance of 'PcdmisHelper' wrapper. In the wrapper, we have another global variable called 'pcdSession' which is an instance of the PCDLRN.Application class.

    The variable 'pcdSession' represents the running PC-Dmis application.
    The variable 'CMMSession' represents the instance of the PcdmisHelper wrapper class.

    To demonstrate an interaction between the C# application and PC-Dmis we'll set up the application to cause PC-Dmis to perform the simple action of becoming visible and invisible to the user.

    We first consider what method is available in the PCDLRN to cause PC-Dmis to be visible. By looking at the PC-Dmis programing documentation we find under the PC-Dmis Object Library - Application Object members - Public Properties, a property call 'Visible'.



    From the documentation we can see that this a Boolean property of the 'Application' object and that is both readable and writable. By setting it to true or false we can make PC-Dmis visible and non-visible.

    Using this information we add the following code to the PcdmisHelper class.

    1        /// <summary>
    2        /// Make the Pcdmis session visable.
    3        /// </summary>
    4        public bool Visible
    5        {
    6            get { if (pcdSession != null) return pcdSession.Visible; return false; }
    7            set { if (pcdSession != null) pcdSession.Visible = value; }
    8        }
    


    In C# this method is known as a class property which has a getter and a setter.

    Line 4: the name of this PcdmisHelper class property is 'Visible'

    Line 6: This is the getter method for the property for when this property is used on the right side of an assignment statement (we'll see this later in the tutorial).
    The code between the curly brackets uses the global variable pcdSession (which represents an instance of PCDLRN.Application object) to access and return the Boolean value of the member property 'Visible' of the actively running PC-Dmis application. If 'pcdSession' for some reason happens to be null, meaning it's not connected to a running copy of PC-Dmis, it will return a default value of FALSE.

    Line 7: This is the setter method for the property for when this property is used on the left side of an assignment statement. (we'll see this later in the tutorial).
    The code between the brackets assigns the Boolean value used on the right side of an assignment statement to the PCDLRN.Application member property 'Visible'. This will immediately cause the PC-Dmis Window to appear or disappear to the user.

    Now that we have added this method to the PcdmisHelper wrapper, let's see how to use this new wrapper method in the 'DmisMenu' application.

    On the 'MainForm' form window we added a button named 'btnPcdmisWindow'. Set the text label property of the button to 'View Pcdmis Window'. Set the 'Click' event of the button to 'btnPcdmisWindow_Click'

    In Mainform.cs we add the following event handler method.

    1        private void btnPcdmisWindow_Click(object sender, EventArgs e)
    2        {
    3            if (CMMsession.Visible == true)
    4            {
    5                CMMsession.Visible = false;
    6                return;
    7            }
    
    9            CMMsession.Visible = true;
            }
    


    This method handles the click event when the user clicks on the 'View Pcdmis Window' button. The method uses the PcdmisHelper wrapper object CMMsession to both GET and SET the Visible property of the wrapper.

    Line 3: Use the Visible property of the wrapper to access and get the value of the running PCDLRN.Application (pcdSession) 'Visible' member.

    Line 5: Use the Visible property of the wrapper to set the value of the running PCDLRN.Application 'Visible member to false if the current value of this member is true.

    Line 9: Otherwise, if the current value of the PCDLRN.Application 'Visible' member is false, set it to true.

    This concludes the tutorial on using the PcdmisHelper wrapper to control the active PC-Dmis program.

    At this point a legitimate question would be; Why use a wrapper in the first place?

    For several reasons:
    1. To hide the details and complexity of working with the PCDLRN objects. For example, consider the following code which handles the creation of a PC-Dmis subprogram file.

            /// <summary> Opens a new Pcdmis subprogram </summary>
            /// <remarks>
            /// The opened subprogram is ready to have assignments, tolerances and
            /// points written into it by the user DotNet application.
            /// </remarks>
            /// <param name="subName">Name of subprogram without path or extension.</param>
            /// <returns>
            /// Returns a PcdmisSubProgram object that has methods for writing to
            /// the Pcdmis subprogram.
            /// </returns>
            public PcdmisSubProgram CreateSubroutineProgram(string subName)
            {
                if (SessionIsAvailable)
                {
                    try
                    {
                        this.CloseAll();
                    }
                    catch (Exception ex)
                    {
                        ExceptionMessages = ExceptionMessages + ex.Message;
                    }
    
                    // Make sure the original is deleted before initializing a new subprogram.
                    PurgeSubProgram(subName);
    
                    pcdPartProgram = pcdPartPrograms.Add(AppProgSubrName(subName), PCDLRN.UNITTYPE.MM,
                        pcdDefaultMachine, DefaultProbeName);
    
                    return new PcdmisSubProgram(pcdPartProgram, subName);
                }
    
                return null;
            }
    


    From the user application point of view, creating a PC-Dmis subprogram file only requires calling the wrapper method 'CreateSubroutineProgram' with the subprogram name as a parameter. The wrapper handles all the house keeping required before creating a PC-Dmis subprogram. Obtains the correct path location for the subprogram file, then sets up the correct parameter list for creating an instance of a PCDLRN.PartProgram that represents a PC-Dmis subprogram. The wrapper also wraps the PCDLRN.PartProgram with a wrapper (PcdmisSubprogram.cs source code) that has convenient methods for adding PC-Dmis assignment commands to the subprogram in their correct PC-Dmis syntax.

    This achieves the goal of writing once, reusing many.
Reply
  • In this tutorial we look at how our C# application can use the PC-Dmis wrapper to interact with PC-Dmis.

    In the previous tutorial we finished with a global variable in the C# DmisMenu application called 'CMMsession' which is an instance of 'PcdmisHelper' wrapper. In the wrapper, we have another global variable called 'pcdSession' which is an instance of the PCDLRN.Application class.

    The variable 'pcdSession' represents the running PC-Dmis application.
    The variable 'CMMSession' represents the instance of the PcdmisHelper wrapper class.

    To demonstrate an interaction between the C# application and PC-Dmis we'll set up the application to cause PC-Dmis to perform the simple action of becoming visible and invisible to the user.

    We first consider what method is available in the PCDLRN to cause PC-Dmis to be visible. By looking at the PC-Dmis programing documentation we find under the PC-Dmis Object Library - Application Object members - Public Properties, a property call 'Visible'.



    From the documentation we can see that this a Boolean property of the 'Application' object and that is both readable and writable. By setting it to true or false we can make PC-Dmis visible and non-visible.

    Using this information we add the following code to the PcdmisHelper class.

    1        /// <summary>
    2        /// Make the Pcdmis session visable.
    3        /// </summary>
    4        public bool Visible
    5        {
    6            get { if (pcdSession != null) return pcdSession.Visible; return false; }
    7            set { if (pcdSession != null) pcdSession.Visible = value; }
    8        }
    


    In C# this method is known as a class property which has a getter and a setter.

    Line 4: the name of this PcdmisHelper class property is 'Visible'

    Line 6: This is the getter method for the property for when this property is used on the right side of an assignment statement (we'll see this later in the tutorial).
    The code between the curly brackets uses the global variable pcdSession (which represents an instance of PCDLRN.Application object) to access and return the Boolean value of the member property 'Visible' of the actively running PC-Dmis application. If 'pcdSession' for some reason happens to be null, meaning it's not connected to a running copy of PC-Dmis, it will return a default value of FALSE.

    Line 7: This is the setter method for the property for when this property is used on the left side of an assignment statement. (we'll see this later in the tutorial).
    The code between the brackets assigns the Boolean value used on the right side of an assignment statement to the PCDLRN.Application member property 'Visible'. This will immediately cause the PC-Dmis Window to appear or disappear to the user.

    Now that we have added this method to the PcdmisHelper wrapper, let's see how to use this new wrapper method in the 'DmisMenu' application.

    On the 'MainForm' form window we added a button named 'btnPcdmisWindow'. Set the text label property of the button to 'View Pcdmis Window'. Set the 'Click' event of the button to 'btnPcdmisWindow_Click'

    In Mainform.cs we add the following event handler method.

    1        private void btnPcdmisWindow_Click(object sender, EventArgs e)
    2        {
    3            if (CMMsession.Visible == true)
    4            {
    5                CMMsession.Visible = false;
    6                return;
    7            }
    
    9            CMMsession.Visible = true;
            }
    


    This method handles the click event when the user clicks on the 'View Pcdmis Window' button. The method uses the PcdmisHelper wrapper object CMMsession to both GET and SET the Visible property of the wrapper.

    Line 3: Use the Visible property of the wrapper to access and get the value of the running PCDLRN.Application (pcdSession) 'Visible' member.

    Line 5: Use the Visible property of the wrapper to set the value of the running PCDLRN.Application 'Visible member to false if the current value of this member is true.

    Line 9: Otherwise, if the current value of the PCDLRN.Application 'Visible' member is false, set it to true.

    This concludes the tutorial on using the PcdmisHelper wrapper to control the active PC-Dmis program.

    At this point a legitimate question would be; Why use a wrapper in the first place?

    For several reasons:
    1. To hide the details and complexity of working with the PCDLRN objects. For example, consider the following code which handles the creation of a PC-Dmis subprogram file.

            /// <summary> Opens a new Pcdmis subprogram </summary>
            /// <remarks>
            /// The opened subprogram is ready to have assignments, tolerances and
            /// points written into it by the user DotNet application.
            /// </remarks>
            /// <param name="subName">Name of subprogram without path or extension.</param>
            /// <returns>
            /// Returns a PcdmisSubProgram object that has methods for writing to
            /// the Pcdmis subprogram.
            /// </returns>
            public PcdmisSubProgram CreateSubroutineProgram(string subName)
            {
                if (SessionIsAvailable)
                {
                    try
                    {
                        this.CloseAll();
                    }
                    catch (Exception ex)
                    {
                        ExceptionMessages = ExceptionMessages + ex.Message;
                    }
    
                    // Make sure the original is deleted before initializing a new subprogram.
                    PurgeSubProgram(subName);
    
                    pcdPartProgram = pcdPartPrograms.Add(AppProgSubrName(subName), PCDLRN.UNITTYPE.MM,
                        pcdDefaultMachine, DefaultProbeName);
    
                    return new PcdmisSubProgram(pcdPartProgram, subName);
                }
    
                return null;
            }
    


    From the user application point of view, creating a PC-Dmis subprogram file only requires calling the wrapper method 'CreateSubroutineProgram' with the subprogram name as a parameter. The wrapper handles all the house keeping required before creating a PC-Dmis subprogram. Obtains the correct path location for the subprogram file, then sets up the correct parameter list for creating an instance of a PCDLRN.PartProgram that represents a PC-Dmis subprogram. The wrapper also wraps the PCDLRN.PartProgram with a wrapper (PcdmisSubprogram.cs source code) that has convenient methods for adding PC-Dmis assignment commands to the subprogram in their correct PC-Dmis syntax.

    This achieves the goal of writing once, reusing many.
Children
No Data