Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

INFITF.Collection class doesn't have Item method.

Status
Not open for further replies.

PrasannaNX

Automotive
Joined
Aug 5, 2014
Messages
31
Location
IN
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
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;
        }
 
First of all, converting to a list for INFITF.Collection can be done with a simple one-liner:
Code:
catCollection.Cast<AnyObject>().ToList()

Secondly, you're not "using CAA". You're using Automation (same API as CATScript or VBA) just from another language.

Lastly, you can't work around this. There are indeed collections in CATIA that doesn't implement iterator pattern (for..each loop).
Just admit it, cast such collections to their interfaces and use Item().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top