I’m trying to update datacard values so it will reflect in my revision table.
this test code doesn’t change the datacard even though GetVarFromDb shows the right value.
public void TestDataCard()
{
FileInfo file = new FileInfo(@"C:\PDM_VAULT\Test 1\Test mbs drawing.SLDDRW");
pdmFile = _vault.GetFileFromPath(file.FullName, out retFolder);
swEnumeratorVariable = pdmFile.GetEnumeratorVariable();
swEnumeratorVariable.SetVar(DataCardFields.RevTeable_Revision, "@", "04");
swEnumeratorVariable.Flush();
swEnumeratorVariable.SetVar(DataCardFields.RevTeable_Description, "@", "testing");
swEnumeratorVariable.Flush();
IEdmEnumeratorVariable6 evars2 = swEnumeratorVariable as IEdmEnumeratorVariable6;
evars2.GetVarFromDb(DataCardFields.RevTeable_Revision, "@", out object retValue);
evars2.GetVarFromDb(DataCardFields.RevTeable_Description, "@", out object retValue2);
Evars = swEnumeratorVariable as IEdmEnumeratorVariable10;
Evars.CloseFile(true);
}
longer story, if I’m writing the values the way I usually do (iterate through all configurations and changing), it reflects the change in the datacard, but not in the revision table (I also see all values in all revisions when checked in, but if I check out “@” configuration is empty). if I change the value manually everything works
this is the longer code:
public void IterateDataCard(FileInfo file)
{
swEnumeratorVariable = default(IEdmEnumeratorVariable5);
retFolder = default(IEdmFolder5);
cfgList = default(EdmStrLst5);
pos = default(IEdmPos5);
pdmFile = _vault.GetFileFromPath(file.FullName, out retFolder);
swEnumeratorVariable = pdmFile.GetEnumeratorVariable();
cfgList = pdmFile.GetConfigurations();
pos = cfgList.GetHeadPosition();
}
public void WriteDataCard(FileInfo file, string variableName, string newValue = null) // TODO: do all changes in one loop and then flush
{
IterateDataCard(file);
Vault vault = new Vault();
pdmFile = _vault.GetFileFromPath(file.FullName, out retFolder);
(string pnString, string descString) = vault.FilenameToDataCard(file);
while (!pos.IsNull)
{
swEnumeratorVariable = pdmFile.GetEnumeratorVariable();
cfgName = cfgList.GetNext(pos);
object value;
if (variableName == DataCardFields.Material)
{
swEnumeratorVariable.SetVar(variableName, cfgName, null, true);
}
if (variableName == DataCardFields.PartNo)
{
newValue = pnString;
}
if (variableName == DataCardFields.Description)
{
newValue = descString;
}
if (variableName == DataCardFields.DESIGN)
{
//newValue = vault.GetCurrentDesigner();
newValue = "user"; //TODO CHANGE!!!!!
}
if (variableName == DataCardFields.ProjectNumber || variableName == DataCardFields.Project)
{
string path = Path.GetDirectoryName(file.FullName);
// Normalize path and split into parts
string normalizedPath = Path.GetFullPath(path);
string[] parts = normalizedPath.Split(Path.DirectorySeparatorChar);
// Find "PDM_VAULT" and get the next folder
for (int i = 0; i < parts.Length; i++)
{
if (parts[i].Equals("PDM_VAULT", StringComparison.OrdinalIgnoreCase) && i + 1 < parts.Length)
{
string targetFolder = parts[i + 1];
// Extract Project number and project name using regex
Match match = Regex.Match(targetFolder, @"(.*?)\s*-\s*(.*)");
if (match.Success)
{
string projectNumber = match.Groups[1].Value.Trim();
string projectName = match.Groups[2].Value.Trim();
if (variableName == DataCardFields.ProjectNumber)
{
newValue = projectNumber;
}
if (variableName == DataCardFields.Project)
{
newValue = projectName;
}
}
else
{
Debug.WriteLine("Pattern not found.");
}
break;
}
}
}
try
{
//Debug.WriteLine($"Checked out by: {pdmFile.LockedByUserID}");
pdmFile.Refresh();
if (!pdmFile.IsLocked)
{
pdmFile.LockFile(retFolder.ID, 0);
//Debug.WriteLine($"Checked out by: {pdmFile.LockedByUserID}");
}
IsReadable(file);
IsWritable(file);
//swEnumeratorVariable.SetVar(DataCardFields.RevTeable_Revision, "@", "04", true);
//swEnumeratorVariable.SetVar(DataCardFields.RevTeable_Description, "@", "testing", true);
swEnumeratorVariable.SetVar(variableName, cfgName, newValue, true);
IEdmEnumeratorVariable8 swEnumeratorVariable2 = (IEdmEnumeratorVariable8)swEnumeratorVariable;
swEnumeratorVariable2.CloseFile(true);
//pdmFile.UnlockFile(0, "Updated Datacard");
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
//if (variableName == DataCardFields.Revision)
//{
//IEdmFile13 pdmFile = (IEdmFile13)_vault.GetFileFromPath(file.FullName, out retFolder);
//Workflow wf = new Workflow();
//wf.StartWorkflow(pdmFile, retFolder, "Legacy Revision", "ECO Design");
//}
Debug.WriteLine($"In Configuration {cfgName}, Variable '{variableName}': is now {this.ReadDataCard(file, variableName)}");
}
IEdmEnumeratorVariable8 swEnumeratorVariable1 = (IEdmEnumeratorVariable8)swEnumeratorVariable;
swEnumeratorVariable1.CloseFile(true);
//pdmFile.UnlockFile(0, "Updated Datacard");
}