Reading values from an iPart table in C#

Top  Previous  Next

Here is a big example:

 

       static public C3dCctData Get3dCctData (AssemblyComponentDefinition Asm3dCctDef)

       {

           AssemblyDocument CctDoc = (AssemblyDocument)Asm3dCctDef.Document;

           string sGeom = CInvHelp.GetCustomiProperty(CctDoc, "CC_FIN_GEOMETRY");

           double mmSporgenza = 0.0;

 

           ComponentOccurrences Occurences = Asm3dCctDef.Occurrences;

 

           // Find the sporgenza looking at the forcelle or tubes.

           // These are iParts and so we need to look at their tables...

           foreach (ComponentOccurrence ThisOcc in Occurences)

           {

               // Is this occurrence a part?

               ComponentDefinition ThisDef = ThisOcc.Definition;

               if (ThisDef.Type == ObjectTypeEnum.kPartComponentDefinitionObject)

               {

                   // This is a part...

                   PartComponentDefinition PartDef = (PartComponentDefinition)ThisDef;

                   PartDocument PartDoc = (PartDocument)PartDef.Document;

 

                   AutoBatSupp.Log.WriteLn(CLog.Type_e.ekLog, "   looking at:", PartDoc.DisplayName);

 

                   // Get the SAP code for this part...

                   string sPartSapCode = PartDoc.DisplayName.Substring (0,AutoBatSupp.ikNumSapChars);

 

                   // Is this an iPart?

                   if (PartDef.IsiPartMember)

                   {

                       // This is an iPart member, which I want to find out more about...

                       iPartMember Member = PartDef.iPartMember;

                       iPartFactory Factory = Member.ParentFactory;

 

                       AutoBatSupp.Log.WriteLn(CLog.Type_e.ekLog, "   is a member, the factory has ", Factory.TableRows.Count.ToString(), " columns");

 

                       // Look over all columns to find the one we are looking for...

                       int iColIndex = 0; // Errore value

                       int i = 1;

                       foreach (iPartTableColumn Col in Factory.TableColumns)

                       {

                           if (Col.Heading == "SporgLatoCurve")

                           {

                               iColIndex = i;

                               break;

                           }

                           i++;

                       }

 

                       if (iColIndex > 0)

                       {

                           // So, we know in which *column* to get the sporgenza from

 

                           // Loop over all the rows to find the one which corresponds to our part

                           iPartTableRows Rows = Factory.TableRows;

                           foreach (iPartTableRow Row in Rows)

                           {

                               iPartTableCell SapCodeCell = Row[1];

                               string sThisSapCode = SapCodeCell.Value;

                               if (sThisSapCode == sPartSapCode)

                               {

                                   iPartTableCell SporgenzaCell = Row[iColIndex];

                                   string sCellValue = AutoBatSupp.GetCleanNumberString(SporgenzaCell.Value); // Convert from "20,00 mm" to "20.00"

                                   AutoBatSupp.Log.WriteLn(CLog.Type_e.ekLog, "       cell is ", sCellValue);

                                   if (!double.TryParse(sCellValue, NumberStyles.Number, CultureInfo.InvariantCulture, out mmSporgenza))

                                   {

                                       AutoBatSupp.Log.WriteLn(CLog.Type_e.ekErr, "       could not get sporgenza ", mmSporgenza.ToString(), " from ", sCellValue);

                                   }

                                   else

                                   {

                                       AutoBatSupp.Log.WriteLn(CLog.Type_e.ekLog, "       sporgenza is ", mmSporgenza.ToString());

                                       break; // finished.

                                   }

                               }

                           }

                       }

                   }

               }

           }

 

           if (mmSporgenza == 0.0)

           {

               AutoBatSupp.Log.WriteLn(CLog.Type_e.ekErr, "Could not find sporgenza parameter");

           }

 

           // Compose all the data into a single object

           C3dCctData CctData = new C3dCctData

           {

               m_sGeom = sGeom,

               m_mmSporgenza = mmSporgenza

           };

 

           return CctData;

 

 

Enter topic text here.

Text, images and diagrams © 2021 Owen F. Ransen. All rights reserved. (But copy the source code as much as you want!)