Check if the file is checked out.
Check if the variable is on a datacard.
Check if the option Prefer 32 bits is turned off in the project’s properties under the build tab or the application tab if you are using VB.NET
@AmenJlili: Thanks for looking into this. I think it is a vault issue. After my code failed (that I made according to your lessons on CADSharp) I went back to the example code form the PDM API help: Batch Update Card Variables Example (VB.NET). I run that code as is and the variables in the datacard of the .txt file and folder are changed as planned. I changed it to work with .sldprt files and @ configuration and the variables are not written any longer. I do see the new variable values showing up in the sql table VariableValues so the setvar function seems to be ok. But the values don’t show up in the datacard. A get latest version doesn’t help. Checking in the file sets the values in de sql table back to the values as they were and always had been on the datacard. So something goes wrong with writing the variables for a Solidworks and Office file. It does work for txt and jpg files. For debugging I use the PDMVaultBrowser that Artem (CodeStack) made. I tried with Notepad as well and that showed the same behaviour. I don’t get any errors using the batchUpdate2 function. Just that the variables don’t update.
Yes, the custom properties are set with the variables and linked to the file extensions. Our problem does seem to have to do with them though. But then not the custom property in the variable setting but in the Solidworks file.
I went back to the basis with a new clean Vault based on the Solidworks Default vault and added 1 folder, a clean .sldprt without custom properties and a txt file. I run the BatchUpdatcecardVars from the helpfile with some tweaking to make it suitable for Solidworks files and have more variables changed. (Batch Update Card Variables Example (VB.NET) - 2021 - SOLIDWORKS API Help)
The txt file works flawlessly again. Data card in explorer shows all the new variables.
The sldprt file has 2 variables that are not updated on the explorer data card.
It turned out that those are passed from the Folder to the data card of the sldprt file and are also part of the custom properties in the sldprt file.
As soon as the variable of the data card is set as a custom property in the part file it is no longer updated by the API.
Data card variables that are not linked to a custom property in the part are not shown in the data card opened by Solidworks.
Data card variables are only pushed to a custom property in the part when the value is changed by hand.
New custom properties are only made when the value on the data card is changed by hand and not by the API.
The part has been checked in and out several times. Get latest version. That makes no difference.
Here is a picture of the datacard in explorer to show what I mean:
My (variable) 9 is set by the API and is empty on the data card in Solidworks nor is it (variable and value) in the custom property of the part file
Description is set by hand and not changeable by the API. It is visible in Solidworks data card and as a variable and value in custom property
Project Name and Number are from the parent folder. Not changeable by the API. it is visible in Solidworks data card and custom property
We have PDM for more than 10 years and have quite a number of Dispatch scripts in the production vault that monitor and change variables. We use the custom properties of the model to push variables to the drawing.
Sometimes the Dispatch scripts fail so I thought I dive into the API stuff to replace the Dispatch scripts and make PDM more robust…
Is the above mentioned interaction of the API with the data card and custom properties normal/as expected?