IfcOpenShell / IfcOpenShell

Open source IFC library and geometry engine
GNU Lesser General Public License v3.0
1.85k stars 731 forks source link

Confused with property reading |c++ #3910

Open deliciousteas opened 1 year ago

deliciousteas commented 1 year ago

I think i get trouble with utilizing ifcopenshell in c++. 🤔my goal is trying to get ifcDuceSegment all instance's property,especially about its size、length、area and so on. I have two ideas now, but I'm not sure which is appropriate.

  1. The first is to start with the IsDefinedBy method of the IfcDuctSegment, find the set of properties related to the IfcDuctSegment, and then query the instance properties according to the guid?

  2. The second is to find ifc properties stored in quantity_set and property_set based on IFC documents, I have found classes such as IfcQuantityLength, but I don't know how to relate these properties to IfcDuctSegment instances?

I'm not sure if this idea is correct for IFC code and documentation, but welcome to talk!!_👂👂👂

Here is my code to get attribute from IfcDuctSegment: `IfcSchema::IfcQuantityLength::list::ptr length = file.instances_by_type(); IfcSchema::IfcElementQuantity::list::ptr elementquantity= file.instances_by_type();

for (IfcSchema::IfcElementQuantity::list::it it = elementquantity->begin(); it != elementquantity->end(); ++it)
{
    //遍历所有isntance
    const IfcSchema::IfcElementQuantity* master = *it;
    std::cout << master->data().toString() << std::endl;

    std::cout << std::endl;
}
IfcSchema::IfcDuctSegment::list::ptr ductsegment = file.instances_by_type<IfcSchema::IfcDuctSegment>();
for (IfcSchema::IfcDuctSegment::list::it it = ductsegment->begin(); it != ductsegment->end(); ++it)
{

    const IfcSchema::IfcDuctSegment* master = *it;
    std::cout << master->data().toString() << std::endl;
    std::cout<<std::endl;
    outputFile << master->data().toString() << std::endl;
    ::Ifc4::IfcRelDefinesByProperties::list::ptr RelProperty = master->IsDefinedBy();

    for (auto property : *RelProperty)
    {
        std::cout << property->data().toString() << std::endl;

    }
    std::cout << std::endl;
    ::Ifc4::IfcRelDefinesByType::list::ptr typetest=master->IsTypedBy();
    for (auto type : *typetest)
    {
        std::cout << type->data().toString() << std::endl;

    }
}`
aothms commented 1 year ago
for (auto property : *RelProperty) {
    // This is *not* the propery set yet, this is the relationship that ties property set to the element. So use RelatingPropertyDefinition to go the pset. This can be an IfcPropertySet or an IfcElementQuantity.
    std::cout << property->RelatingPropertyDefinition()->data().toString() << std::endl;
}
::Ifc4::IfcRelDefinesByType::list::ptr typetest=master->IsTypedBy();
if (typetest && typetest->size()) {
    // Properties can also be associated to the type, which unfortunately works differently.
    auto psets = (*typetest->begin())->RelatingType()->HasPropertySets();
    if (psets) {
        for (auto& pset : *psets) {
            std::cout << pset->data().toString() << std::endl;
        }
    }
}
deliciousteas commented 1 year ago

It's amazing to hear back from you and your guidance helped me a lot in my research!!👍👍👍👍 In the next step, I will expand the code test for all attributes and some attributes extraction according to the research needs, of course, I will also test the differences between SPF and HDF5 formats.📄📄📄

Moult commented 1 year ago

@deliciousteas it's great that this is helping! Would you be interested in helping writing some beginner hello world style docs for C++? Our docs page are pretty lonely in the C++ portion :) https://blenderbim.org/docs-python/ifcopenshell.html

deliciousteas commented 12 months ago

@Moult it's ok .Shall I contact you by email?

Moult commented 11 months ago

If you'd like dion@thinkmoult.com or you can just submit a PR directly here :)