PrasannaNX
Automotive
- Aug 5, 2014
- 31
Hi,
I am trying to create an extension method to convert INFITF.Collection to a Generic.List.
Please refer my code below. But INFITF.Collection class doesn't have Item method to get the object.
How can i workaround this?
Reason why i need this is while looping some collection in catia CAA using for each is not working(e.g., Using for each loop to retrieve clash values from clash.conflicts always return '0') but the same is working fine with for loop.
--> Conflict example
--> Extension Method
I am trying to create an extension method to convert INFITF.Collection to a Generic.List.
Please refer my code below. But INFITF.Collection class doesn't have Item method to get the object.
How can i workaround this?
Reason why i need this is while looping some collection in catia CAA using for each is not working(e.g., Using for each loop to retrieve clash values from clash.conflicts always return '0') but the same is working fine with for loop.
--> Conflict example
Code:
Product catProd = AppInitializer.CatProdActDoc.Product;
List<Product> lstChildProd = new List<Product>();
catProd.GetAllChildrens(ref lstChildProd); --> Assume GetAllChildrens routine retrieves two components from assembly
Clashes catClshs = (Clashes)AppInitializer.CatProdActDoc.Product.GetTechnologicalObject("Clashes");
Groups catGrps = (Groups)AppInitializer.CatProdActDoc.Product.GetTechnologicalObject("Groups");
Group grpFirst = catGrps.Add();
grpFirst.AddExplicit(lstChildProd[0]);
Group grpSecond = catGrps.Add();
grpSecond.AddExplicit(lstChildProd[1]);
Clash catClsh = catClshs.Add();
catClsh.FirstGroup = grpFirst;
catClsh.SecondGroup = grpSecond;
catClsh.ComputationType = CatClashComputationType.catClashComputationTypeBetweenTwo;
catClsh.InterferenceType = CatClashInterferenceType.catClashInterferenceTypeContact;
catClsh.Compute();
//foreach (Conflict confItem in catClsh.Conflicts)
//{
// if (confItem.Type == CatConflictType.catConflictTypeClash)
// {
// Console.WriteLine(confItem.Value.ToString()); --> This statement always returns zero
// }
//}
for (int i = 1; i <= catClsh.Conflicts.Count; i++)
{
if (catClsh.Conflicts.Item(i).Type == CatConflictType.catConflictTypeClash)
{
Console.WriteLine(catClsh.Conflicts.Item(i).Value.ToString()); --> This statement is working fine
}
}
--> Extension Method
Code:
public static List<AnyObject> ConvertToList(this INFITF.Collection inpObj)
{
List<AnyObject> lstAnyObject = new List<AnyObject>();
try
{
for (int iIndex = 1; iIndex <= inpObj.Count; iIndex++)
{
lstAnyObject.Add((inpObj).Item(iIndex)); --> Item doesn't exist with collection object <Compile Error>
}
}
catch (Exception ex)
{
throw ex;
}
return lstAnyObject;
}