Yeah, that's on me. That's an experimental file and i clipped it before the portion i rewrote.
The file i'm looking at is a bunch of nuts/bolts from content center. The powers that be want to be able to set some values on a per-project basis. In 2023, we found we can do this by adding instance properties, but i'm having trouble exporting those to our ERP setup, so i'm just trying to access the data. Which i'm not having any success in accessing from the BOM component. So, this is the original section I rewrote for c# - the NativeObject gets the red lines under it as it doesn't seem to exist there...
if (aBomRow.ComponentOccurrences[1].Type == ObjectTypeEnum.kComponentOccurrenceObject)
{
if (aBomRow.ComponentOccurrences[1].OccurrencePropertySetsEnabled)
{
ipropset = aBomRow.ComponentOccurrences[1].OccurrencePropertySets[1];
MessageBox.Show("a");
}
}
else if (aBomRow.ComponentOccurrences[1].Type == ObjectTypeEnum.kComponentOccurrenceProxyObject)
{
MessageBox.Show("n");
ipropset = aBomRow.ComponentOccurrences[1].NativeObject.OccurrencePropertySets[1];
foreach (Inventor.Property p in ipropset)
{
MessageBox.Show(p.Name);
}
}
else
{
MessageBox.Show("c");
}
As for the code i'm trying to add it into that is this:
foreach (BOMRow aBomRow in BomRows)
{
ComponentDefinition oCompDef = aBomRow.ComponentDefinitions[1];
//PartDocument oPartDoc = (PartDocument)oCompDef.Document;
Document oPartDoc = (Document)oCompDef.Document;
//now that we a have a part document, get it's properties.
UnitsOfMeasure UOM = oPartDoc.UnitsOfMeasure;
PropertySet prjPropertySet = (PropertySet)oPartDoc.PropertySets["Design Tracking Properties"];
string oldPN = Convert.ToChar(34) + prjPropertySet["Part Number"].Value.ToString() + Convert.ToChar(34);
//oldPN = oldPN.Length < 7 ? oldPN.PadLeft(7, '0') : oldPN;
string desc = Convert.ToChar(34) + prjPropertySet["Description"].Value.ToString().Replace(@"""", @Anonymous"""") + Convert.ToChar(34);
string stk = prjPropertySet["Stock Number"].Value.ToString();
string itemNum = aBomRow.ItemNumber;
string qty = aBomRow.TotalQuantity.ToString();
string len = GetColumnValue(oPartDoc, "length");
if (!string.IsNullOrEmpty(len))
{
double dlen = UOM.ConvertUnits((double)UOM.GetValueFromExpression(len, UnitsTypeEnum.kInchLengthUnits),
UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits);
dlen = dlen / 2.54f;
dlen = Math.Round(dlen, 4, MidpointRounding.AwayFromZero);
len = dlen.ToString();
}
string wid = GetColumnValue(oPartDoc, "width");
if (!string.IsNullOrEmpty(wid))
{
double dwid = UOM.ConvertUnits((double)UOM.GetValueFromExpression(wid, UnitsTypeEnum.kInchLengthUnits),
UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kInchLengthUnits);
dwid = dwid / 2.54f;
dwid = Math.Round(dwid, 4, MidpointRounding.AwayFromZero);
wid = dwid.ToString();
}
string pdims =(!string.IsNullOrEmpty(wid) ? wid + " x " + len : len );
//string shopNotes = Convert.ToChar(34) + GetColumnValue(oPartDoc, "shop1");
//shopNotes = shopNotes + ((GetColumnValue(oPartDoc, "shop2").Length > 0) ? "\n" + GetColumnValue(oPartDoc, "shop2") : "" + Convert.ToChar(34));
//shopNotes = shopNotes + ((GetColumnValue(oPartDoc, "shop3").Length > 0) ? "\n" + GetColumnValue(oPartDoc, "shop3") : "" + Convert.ToChar(34));
string shopNotes = Convert.ToChar(34) + GetColumnValue(oPartDoc, "shop1").Replace(@"""", @Anonymous"""") + " " +
GetColumnValue(oPartDoc, "shop2").Replace(@"""", @Anonymous"""") + " " +
GetColumnValue(oPartDoc, "shop3").Replace(@"""", @Anonymous"""") + Convert.ToChar(34);
string parentNumber = string.IsNullOrEmpty(parentNum) ? itemNum : parentNum + "." + itemNum;
if (GetColumnValue(oPartDoc, "item create") == "Yes" || GetColumnValue(oPartDoc, "item create") == "True")
{
sBomTable.Rows.Add(new object[] { itemNum, oldPN, stk, desc, qty, pdims, shopNotes });
}
if (aBomRow.ChildRows != null)
{
if (GetColumnValue(oPartDoc, "item create") == "Yes" || GetColumnValue(oPartDoc, "item create") == "True")
{
ParseBOMLevel(aBomRow.ChildRows, -3, itemNum);
}
else
{
//skip it
}
}
}