8 Replies Latest reply on May 9, 2014 5:40 AM by Hilkka Lemettinen

    Setting card variables in epdm add-in

    Hilkka Lemettinen

      I have an add-in (in c# .net) which creates dxf-files of each sheet of a drawing in a separate dxf file. I need to set some card variables for those dxf files in the same add-in. Using SetVar doesn't seem to work.

       

                IEdmFile5 fileObj = default(IEdmFile5);

                IEdmFolder5 retFolder = default(IEdmFolder5);

       

                fileObj = vault.GetFileFromPath(fileName, out retFolder);

                string filePath = Path.GetDirectoryName(fileName);

                IEdmEnumeratorVariable5 varE = (IEdmEnumeratorVariable5)fileObj.GetEnumeratorVariable(filePath);

                try

                {

                      varE.SetVar(varName, config, ref varValue, false);

                      IEdmEnumeratorVariable8 varE8 = (IEdmEnumeratorVariable8)varE;

                      varE8.CloseFile(true);

                 }

                 catch (Exception e)

                 {

                      MessageBox.Show(e.Message);

                 }

       

      The error message is "The file isn't checked out by you, which is required by the operation.". However, even the checking out (which should not be required with SetVar, I think) won't help. Any ideas?

        • Re: Setting card variables in epdm add-in
          Artem Taturevych

          The file needs to be checked out in order to set the variable - just like it behaves when setting the card variables (when file is checked in the card is grayed out). It is also required that the user who is checked the file out is the same who is setting the variable. In your add-in you have a IEdmVault5::Login or LoginAuto call. Make sure that the credentials are the credentials of the user who has checked the file out.

            • Re: Setting card variables in epdm add-in
              Hilkka Lemettinen

              I have implemented the add-in according to SolidWorks epdm add-in directions:

               

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

                  {

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

                      poInfo.mbsAddInName = "C# Add-in";

                      poInfo.mbsCompany = "My Company";

                      poInfo.mbsDescription = "Menu add-in that shows a message box.";

                      poInfo.mlAddInVersion = 1;

               

                      //Specify the minimum required version of SolidWorks Enterprise PDM

                      poInfo.mlRequiredVersionMajor = 6;

                      poInfo.mlRequiredVersionMinor = 4;

               

                      // Register a menu command

                      poCmdMgr.AddCmd(1, "C# Add-in", (int)EdmMenuFlags.EdmMenu_Nothing);

               

              The add-in for a drawing file is activated using menu command. So I have already logged in the poVault without any additional call (poVault.IsLoggedIn is true).

               

              In the add-in I save the sheets of the drawing using ModelDocExtension SaveAs-method, which leaves the file checked out by me. Still the error occurs. I even tried to check the dxf file in and then out again, but even that didn't help. It seems like there would be no effect if the file was checked in or out. Still the same error.

               

              I'm testing the add-in as a debug add-in.

            • Re: Setting card variables in epdm add-in
              Michael Dekoning

              From the API documenation:

               

              You must call the Flush method after calling SetVar to ensure that the new data gets written properly to the file or folder.

               

              Also, I typically just go ahead declare an IEdmEnumeratorVariable8 object and cast to it, so in your case:

               

              IEdmEnumeratorVariable8 varE = fileObj.GetEnumeratorVariable("") as IEdmEnumeratorVariable8;

              try

              {

                   varE.SetVar(varName, config, ref varValue, false);

                   varE.Flush();

                   varE.CloseFile(true);

              }

              • Re: Setting card variables in epdm add-in
                Hilkka Lemettinen

                Solution found. In GetEnumeratorVariable(filePath) the parameter filePath has to be an empty string or it has to include the path + file name. Only path to location is not enough. Confusingly SW API help says about that parameter:

                "Optional path to the file to access; default is location where this file is checked out"