diff --git a/src/Mod/Assembly/App/BomObject.cpp b/src/Mod/Assembly/App/BomObject.cpp index 49dc7e2a1f..d6aaf051e2 100644 --- a/src/Mod/Assembly/App/BomObject.cpp +++ b/src/Mod/Assembly/App/BomObject.cpp @@ -239,6 +239,16 @@ void BomObject::addObjectToBom(App::DocumentObject* obj, size_t row, std::string else if (columnName == "Quantity") { setCell(App::CellAddress(row, col), std::to_string(1).c_str()); } + else if (columnName.starts_with(".")) { + // Column names that start with a dot are considered property names + // Extract the property name + std::string baseName = columnName.substr(1); + + auto propertyValue = getBomPropertyValue(obj, baseName); + if (!propertyValue.empty()) { + setCell(App::CellAddress(row, col), propertyValue.c_str()); + } + } else { // load custom data if any. for (auto& el : dataElements) { @@ -252,6 +262,48 @@ void BomObject::addObjectToBom(App::DocumentObject* obj, size_t row, std::string } } +std::string BomObject::getBomPropertyValue(App::DocumentObject* obj, std::string baseName) +{ + App::Property* prop = obj->getPropertyByName(baseName.c_str()); + + if (!prop) { + Base::Console().Warning("Property not found: %s\n", baseName.c_str()); + return "N/A"; + } + + // Only support a subset of property types for BOM + if (auto propStr = dynamic_cast(prop)) { + return propStr->getValue(); + } + else if (auto propLength = dynamic_cast(prop)) { + auto unit = propLength->getUnit().getString(); + auto value = std::to_string(propLength->getValue()); + return value + " " + unit; + } + else if (auto propVolume = dynamic_cast(prop)) { + auto unit = propVolume->getUnit().getString(); + auto value = std::to_string(propVolume->getValue()); + return value + " " + unit; + } + else if (auto propQuantity = dynamic_cast(prop)) { + auto unit = propQuantity->getUnit().getString(); + auto value = std::to_string(propQuantity->getValue()); + return value + " " + unit; + } + else if (auto propFloat = dynamic_cast(prop)) { + return std::to_string(propFloat->getValue()); + } + else if (auto propInt = dynamic_cast(prop)) { + return std::to_string(propInt->getValue()); + } + else if (auto propBool = dynamic_cast(prop)) { + return propBool->getValue() ? "True" : "False"; + } + + Base::Console().Warning("Property type not supported for: %s\n", prop->getName()); + return "Not supported"; +} + AssemblyObject* BomObject::getAssembly() { for (auto& obj : getInList()) { diff --git a/src/Mod/Assembly/App/BomObject.h b/src/Mod/Assembly/App/BomObject.h index 9b6666878d..e93cae4188 100644 --- a/src/Mod/Assembly/App/BomObject.h +++ b/src/Mod/Assembly/App/BomObject.h @@ -94,6 +94,9 @@ public: std::vector dataElements; std::vector obj_list; + +private: + std::string getBomPropertyValue(App::DocumentObject* obj, std::string baseName); };