// Make list of all harnesses.
// You can use both harnesses and cable units for report derivation. Its common base is the DerivationSource class.
List<DerivationSource> sources = variant.GetAllWireHarnessInfos().Cast<DerivationSource>().ToList();
// You could add all cable units as well.
// sources.AddRange(variant.GetAllCableUnitInfos().Cast<DerivationSource>());
// Select an Aggregated BOM report type.
// We use the "Name" property, because it does not depend on localization. "LocalizedName" does.
// To see see all the report type names, list all report types using Report.GetReportTypes().
ReportType reportType = Report.GetReportTypes().Where(n => n.Name == "AggregatedBOMReporter").FirstOrDefault();
// Create a new Aggregated BOM report from all harnesses in a variant.
Report report = variant.CreateReport("My new report name", sources, reportType);
// Save the project so the new report is saved into the project structure.
project.Save();
// Open the report.
report.Open(false, false);
// Get a report data. This action is slow as the object with all the data is constructed each time the property is accessed.
// Note that we get ReportData object once and then use it for all the queries.
ReportData reportTable = report.Data;
// You can simply get the report dimensions. Please note that unused columns are also included.
Console.WriteLine($"The report has {reportTable.ColumnCount} columns and {reportTable.RowCount} rows.");
// Print all the used columns' names.
//Console.Write("Report has following used columns: ");
Console.WriteLine("Report has following used columns: ");
foreach (ColumnDescription column in reportTable.Columns)
{
// Print only used columns.
if (column.Used)
Console.Write($"{column.Name}; ");
}
Console.WriteLine();
// Pick a column with a name "Length".
ColumnDescription lengthColumn = reportTable.Columns.Where(n => n.Name == "Length").FirstOrDefault();
// Print the whole column:
Console.WriteLine("Length column:");
for (int i = 0; i < reportTable.RowCount; i++)
{
// You can use ColumnDescription for indexing.
Property value = reportTable[i, lengthColumn];
// Empty fields are set to null.
if (value != null)
Console.Write($"{value.ToString()}; ");
else
Console.Write("<empty>; ");
}
Console.WriteLine();
// Print the first row:
Console.WriteLine("First row:");
for (int i = 0; i < reportTable.ColumnCount; i++)
{
// You can use coordinates for indexing. Note that unused columns are also present in the table.
Property value = reportTable[0, i];
// Empty fields are set to null.
if (value != null)
Console.Write($"{value.ToString()}; ");
else
Console.Write("<empty>; ");
}
Console.WriteLine();
// WRONG! Constructing whole table when accessing each field in a row.
//for (int i = 0; i < reportTable.ColumnCount; i++)
//{
// // You can use coordinates for indexing.
// Property value = report.Data[0, i]; // <<< SLOW! Getter of the Data property constructs the whole table each time!
// // Empty fields are set to null.
// if (value != null)
// _context.ConsoleOutput(value.ToString());
//}
// Close the report.
report.Close();