10 Replies Latest reply on Feb 16, 2017 12:43 PM by Joel Seerey

    deactivating a data card button unless file is checked out

    Joel Seerey

      Hello,

      I have recently created my first EPDM add-in, it is a button on the data card which retrieves a part number and writes it to the configuration specific data card that the button was pressed in.

      the only issue i am having is that this button is still active when the file is checked in, this means that anybody could press the button and increment the part number value without having that value written to the data card.

       

      does anybody know how to activate a button only when the file is checked out and only to the checked out user?

       

      thanks

        • Re: deactivating a data card button unless file is checked out
          Tim Webb

          Hi Joel,

          The way I manage this is to let the button be pressed but once I have the file object, access the IsLocked property. If True, then keep going but if False, either exit the code quietly or tell the user to check the file out.

           

          Take a look at the PDM API help at the "IsLocked Property" for the IEdmFile5 object. Code samples from the "Access File Card Variables" from the PDM API help.

           

                    'Example in vb.net

                    Dim aFile As IEdmFile5

                    aFile = vault2.GetFileFromPath(ListBox.Items(0).ToString())

                    'Get card variables only from a file checked into the vault

                    If Not aFile.IsLocked Then 'exit here (or show message box), the file is not checked out

                        ...code to exit or show messagebox

           

                    //Example in c#

                    IEdmFile5 aFile = default(IEdmFile5);

                    IEdmFolder5 ppoRetParentFolder = null;

                    aFile = vault2.GetFileFromPath(ListBox.Items[0].ToString(), out ppoRetParentFolder);

                    //Get card variables only from a file checked into the vault

                    if (!aFile.IsLocked) //exit here (or show message box), the file is not checked out

                        ...code to exit or show messagebox

           

          If the file is not checked out, either exit quietly without any action OR show a messagebox telling them what to do next like "Please check out this file to use this function" or something along those lines.

           

          Hope this helps,

          Tim

          Believe in the Q!

          https://equivaq.com/

                           

            • Re: deactivating a data card button unless file is checked out
              Michael Dekoning

              Tim,

              Next time I'll wait a few minutes to see if you reply.

              • Re: deactivating a data card button unless file is checked out
                Joel Seerey

                thanks tim,

                that is exactly what i want, ive been trying to go a little further and have it check that the user who presses the button is the user with the file checked out but for some reason now i just get error codes whether the part is checked in correctly or not.

                i have been doing this in C#  here is my code

                 

                using System;

                using System.Collections.Generic;

                using System.Text;

                using EdmLib;

                using Microsoft.VisualBasic;

                 

                namespace hello_button

                {

                    public class Class1 : IEdmAddIn5

                    {

                        private IEdmVault5 vault1;

                        IEdmSerNoGen7 serialNbrs;

                      

                        public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)

                        {

                            //Specify information to display in the add-in's Properties dialog box

                            poInfo.mbsAddInName = "hello button";

                            poInfo.mbsCompany = "honey bee";

                            poInfo.mbsDescription = "says hello";

                            poInfo.mlAddInVersion = 1;

                            poInfo.mlRequiredVersionMajor = 6;

                            poInfo.mlRequiredVersionMinor = 4;

                 

                            //Notify the add-in when a file data card button is clicked

                            poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton);

                        }

                        public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)

                        {

                            //Respond only to a specific button command

                            //The button command to respond to begins with "MyButton:" and ends with the name of the

                            //variable to update in the card

                            if (poCmd.mbsComment == "hey dude")

                            {

                                // set vault

                                EdmVault5 vault1 = default(EdmVault5);

                                vault1 = (EdmVault5)poCmd.mpoVault;

                                // set seriel number to use

                                serialNbrs = (IEdmSerNoGen7)vault1.CreateUtility(EdmUtility.EdmUtil_SerNoGen);

                                IEdmSerNoValue serialNbrValue = default(IEdmSerNoValue);

                                // set file

                                IEdmFile9 aFile = default(IEdmFile9);

                                aFile = (IEdmFile9)poCmd.mpoVault;

                                // set current user

                                IEdmUserMgr5 userMgr = default(IEdmUserMgr5);

                                userMgr = (IEdmUserMgr5)vault1;

                                IEdmUser5 user = default(IEdmUser5);

                                user = userMgr.GetLoggedInUser();

                                // set user who has file checked out

                                IEdmUser5 lockuser = default(IEdmUser5);

                                lockuser = aFile.LockedByUser;

                 

                                if (user == lockuser)

                                {

                                    serialNbrValue = serialNbrs.AllocSerNoValue("seriel number addin test", 0, " ", 0, 0, 0, 0);

                                    dynamic serialNbrValueValue = serialNbrValue.Value;

                                    IEdmEnumeratorVariable5 vars = default(IEdmEnumeratorVariable5);

                                    vars = (IEdmEnumeratorVariable5)poCmd.mpoExtra;

                                    vars.SetVar("PartNumber", "", serialNbrValue.Value);

                 

                 

                                    System.Windows.Forms.MessageBox.Show(serialNbrValue.Value.ToString());

                 

                                

                                }

                                else

                                {

                                    System.Windows.Forms.MessageBox.Show("file is not checked out by you");

                                }

                            }

                            }

                 

                          

                        }

                 

                 

                    }

              • Re: deactivating a data card button unless file is checked out
                Michael Dekoning

                I don't know of a way to disable the button for a file that is checked in. However, your add-in could check to see if the file is checked out by the current user, and if not, display a message to the user instead of incrementing the part number.