Now I've hit upon an annoying problem.
Using the VBA implementation of BOMQuery() I have the following: C#.NET class (that I call and talk to/from iLogic):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Inventor;
namespace BOMTool
{
public class Class1
{
public static Inventor.Application m_inventorApplication;
public List<BomRowItem> BomList = new List<BomRowItem>();
public static Inventor.Application InventorApplication
{
get
{
return Class1.m_inventorApplication;
}
set
{
Class1.m_inventorApplication = value;
}
}
public void BeginReformatBomForExcel(ref List<BomRowItem> InventorBomList)
{
var grouped = InventorBomList.OrderBy(x => x.BomRowType).GroupBy(x => x.BomRowType);
MessageBox.Show("InventorBomList.Count= " + InventorBomList.Count);
int SubAssemblyInt = 1;
int DetailedPartsInt = 200;
int COTSContentImportedInt = 500;
foreach (var group in grouped)
{
foreach (BomRowItem item in group)
{
switch (item.BomRowType)
{
case 1: //Specifications = no item number
item.ItemNo = 0;
BomList.Add(item);
break;
case 2: // Sub assemblies = 1 to 199
item.ItemNo = SubAssemblyInt;
SubAssemblyInt++;
BomList.Add(item);
break;
case 3: // Detailed Parts = 200 to 500
item.ItemNo = DetailedPartsInt;
DetailedPartsInt++;
BomList.Add(item);
break;
case 4: // COTS Parts/Content Centre/Imported Components = 500 to 999
item.ItemNo = COTSContentImportedInt;
COTSContentImportedInt++;
BomList.Add(item);
break;
default:
break;
}
}
}
BomList.OrderBy(x => x.ItemNo);
MessageBox.Show("BomList.Count= " + BomList.Count);
InventorBomList = BomList;
}
public void UpdateInventorPartsList(BOMRowsEnumerator oBOMROWs, List<BomRowItem> oSortedPartsList)
{
MessageBox.Show("Reached UpdateInventorPartsList Sub");
long i = 0;
ComponentDefinition oCompdef = default(ComponentDefinition);
for (i = 1; i <= oBOMROWs.Count; i++) {
BOMRow oRow = oBOMROWs.Item(i);
oCompdef = oRow.ComponentDefinitions.Item(1);
var itemNo = (from BomRowItem a in oSortedPartsList where a.FileName == oCompdef.Document.FullFileName select a.ItemNo);
MessageBox.Show("New Item number = " + itemNo.ToString());
MessageBox.Show("Existing Item number: " + oRow.ItemNumber);
}
}
}
public class BomRowItem
{
public string FileName { get; set; }
public string PartNo { get; set; }
public string Descr { get; set; }
public string Rev { get; set; }
public long ItemNo { get; set; }
public string Material { get; set; }
public long Qty { get; set; }
public string Vendor { get; set; }
public string Comments { get; set; }
public long BomRowType { get; set; }
}
}
which works as designed until I get to the line that reads:
BOMRow oRow = oBOMROWs.Item(i)
whereupon the compiler complains that:
"Inventor.BOMRowsEnumerator' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'Inventor.BOMRowsEnumerator' could be found"
which is odd because it works in iLogic and vba.
Have I missed something stupid or is this a bug?
Scratch all that, I'm a dumba$$- if I'd read the vba correctly the section in question should be like this, below:
public void UpdateInventorPartsList(BOMRowsEnumerator oBOMROWs, List<BomRowItem> oSortedPartsList)
{
MessageBox.Show("Reached UpdateInventorPartsList Sub");
long i = 0;
ComponentDefinition oCompdef;
foreach (BOMRow oRow in oBOMROWs)
{
oCompdef = oRow.ComponentDefinitions[1];
var itemNo = (from BomRowItem a in oSortedPartsList where a.FileName == oCompdef.Document.FullFileName select a.ItemNo);
MessageBox.Show("New Item number = " + itemNo.ToString());
MessageBox.Show("Existing Item number: " + oRow.ItemNumber);
}
}
Props to this post for letting me see the error of my ways.
Ho hum. More caffeine required, stat!