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.
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.
Did you add the DXF file to the vault? Calling the SaveAs method will not actually add the file to the vault, even if the path points to a location in the vault.
Jim, good point. I have now added the dxf file to the vault using IEdmFolder6 AddFile-method. But still the same error.
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;
varE.SetVar(varName, config, ref varValue, false);
Michael, the error raises when in SetVar. The error message is always the same: "The file isn't checked out by you, which is required by the operation.". No matter if I've checked the file out or not.
It has been checked into the vault before you use SetVar hasn't it?
It will need to have been checked in and then checked out at least once before you can use SetVar.
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"