AnsweredAssumed Answered

C# PDM Add-in : How to optimize below code to make process faster.

Question asked by Dipak Shah on Jan 22, 2020
Latest reply on Jan 30, 2020 by Mario Zahren

Hello Everyone,

 

I really need your 2-5 minutes on this. Can you please assist me in following code , how can optimise thismore , as its causing heavy loading in process when add-in is calling.

 

Actually i implemented add-in (C#) and its called when changing state of file in PDM Vault.

 

Mario Zahren Amen Allah Jlili Jesse Seger 

public void OnCmd(ref EdmCmd poCmd, ref EdmCmdData[] ppoData)
{
try
{
switch (poCmd.meCmdType)
{
case EdmCmdType.EdmCmd_PostState:
{
Dictionary<string, Dictionary<string, string>> myDictDict = new Dictionary<string, Dictionary<string, string>>();
IEdmVault5 vault_iedm5 = new EdmVault5();
IEdmEnumeratorVariable8 EnumVarObj = default(IEdmEnumeratorVariable8);
EdmStrLst5 cfgList = default(EdmStrLst5);
IEdmPos5 pos = default(IEdmPos5);
object VarObj = null;
foreach (EdmCmdData AffectedFile in ppoData)
{
var result_file_ext = ((EdmCmdData)AffectedFile).mbsStrData1.Split('.').Last();
string file_state = AffectedFile.mbsStrData2.ToString();
var ext_lower = result_file_ext.ToLower();

if (file_state == "Released for Manufacture" && ext_lower == "sldprt" || ext_lower == "sldasm")
{
var confName = AffectedFile.mbsStrData1;
var result_file_name = ((EdmCmdData)AffectedFile).mbsStrData1;
IEdmFile5 actual_file = vault_iedm5.GetFileFromPath(result_file_name, out IEdmFolder5 folder);
EnumVarObj = (IEdmEnumeratorVariable8)actual_file.GetEnumeratorVariable();
cfgList = actual_file.GetConfigurations();
pos = cfgList.GetHeadPosition();
string cfgName = null;
while (!pos.IsNull)
{
cfgName = cfgList.GetNext(pos);
if (cfgName != "@" && !myDictDict.ContainsKey(cfgName))
{
string Description = "";
EnumVarObj.GetVar("Description", cfgName, out VarObj);
if (VarObj == null)
{
EnumVarObj.GetVar("Description", "@", out VarObj);
}
if (VarObj != null)
{
Description = VarObj.ToString();
}

EnumVarObj.GetVar("DrawnDate", cfgName, out VarObj);
string DrawnDate = "";
if (VarObj == null)
{
EnumVarObj.GetVar("DrawnDate", "@", out VarObj);
}
if (VarObj != null)
{
DrawnDate = VarObj.ToString();
}

EnumVarObj.GetVar("DrawnBy", cfgName, out VarObj);
string DrawnBy = "";
if (VarObj == null)
{
EnumVarObj.GetVar("DrawnBy", "@", out VarObj);
}
if (VarObj != null)
{
DrawnBy = VarObj.ToString();
}


var values = new Dictionary<string, string>
{
{"Description", Description},
{"DrawnDate", DrawnDate},
{"DrawnBy", DrawnBy},
};
myDictDict.Add(cfgName, values);
}
}
}
}
}

   

Outcomes