Menu

How to get IfcRelNests?

Help
Rick
2021-06-25
2021-07-15
  • Rick

    Rick - 2021-06-25

    The attached file uses IfcRelNests to relate IfcAlignmentHorizontal and IfcAlignmentVertical to IfcAlignment (this format began with 4x3 rc2). When extracting data from the model, IfcAlignment->Nests() returns an empty container. Here is sample code and the file I'm trying to read.

    Thanks

    int main(int argc,char** argv)
    {
       // Redirect the output (both progress and log) to stdout
       Logger::SetOutput(&std::cout, &std::cout);
    
       // Parse the IFC file provided in argv[1]
       IfcParse::IfcFile file(argv[1]);
       if (!file.good()) {
          std::cout << "Unable to parse .ifc file" << std::endl;
          return 1;
       }
    
       auto alignments = file.instances_by_type<Ifc4x3_rc2::IfcAlignment>();
       auto alignment = *(alignments->begin());
       auto nests = alignment->Nests();
       for (auto rel_nests : *nests) // nests->size() == 0 so the loop is skipped over
       {
          auto related_objects = rel_nests->RelatedObjects();
          for (auto related_object : *related_objects)
          {
             auto horizontal_alignment = related_object->as<Ifc4x3_rc2::IfcAlignmentHorizontal>();
             auto vertical_alignment = related_object->as<Ifc4x3_rc2::IfcAlignmentVertical>();
             if (horizontal_alignment)
             {
                // do something
             }
             else if (vertical_alignment)
             {
                // do something
             }
          }
       }
        return 0;
    }
    
     
    • Thomas Krijnen

      Thomas Krijnen - 2021-07-01

      Sorry for the late reply. I find it confusing as well, but you're traversing the inverse relationship in the wrong direction. The correct attribute here is IsNestedBy.

      Nests you can call on the hor/ver alignment.

      A quick headsup that the file is not very valid.

      The parser gives these errors

      [Error] Wrong number of attributes on instance with id #28
      [Error] Wrong number of attributes on instance with id #29
      

      The schema validator gives these errors

      Validating Alignment-Aplitop-2.IFC
      In #97=IfcCurveSegment(.CONTINUOUS.,#93,IfcNonNegativeLengthMeasure(0.),IfcNonNegativeLengthMeasure(497.87228283))
      IfcNonNegativeLengthMeasure(497.87228283) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #88=IfcCurveSegment(.CONTINUOUS.,#84,IfcParameterValue(-2164.89830648556),IfcNonNegativeLengthMeasure(646.6491343))
      IfcNonNegativeLengthMeasure(646.6491343) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #79=IfcCurveSegment(.CONTINUOUS.,#75,IfcNonNegativeLengthMeasure(0.),IfcNonNegativeLengthMeasure(393.90380198))
      IfcNonNegativeLengthMeasure(393.90380198) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #70=IfcCurveSegment(.CONTINUOUS.,#66,IfcNonNegativeLengthMeasure(0.),IfcNonNegativeLengthMeasure(928.81668938))
      IfcNonNegativeLengthMeasure(928.81668938) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #61=IfcCurveSegment(.CONTINUOUS.,#57,IfcParameterValue(-1099.36986773),IfcNonNegativeLengthMeasure(1099.36986773))
      IfcNonNegativeLengthMeasure(1099.36986773) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #52=IfcCurveSegment(.CONTINUOUS.,#47,IfcNonNegativeLengthMeasure(0.),IfcNonNegativeLengthMeasure(834.76720476))
      IfcNonNegativeLengthMeasure(834.76720476) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #42=IfcCurveSegment(.CONTINUOUS.,#35,IfcNonNegativeLengthMeasure(0.),IfcNonNegativeLengthMeasure(688.33801902))
      IfcNonNegativeLengthMeasure(688.33801902) not valid for <attribute ParentCurve: <entity IfcCurve>>
      Attribute <entity IfcAlignmentHorizontal>.<attribute Segments: <list [1:?] of <entity IfcAlignmentHorizontalSegment>>> not optional
      Attribute <entity IfcAlignment>.<attribute Axis: <entity IfcCurve>> not optional
      In #115=IfcCurveSegment(.CONTINUOUS.,#111,IfcNonNegativeLengthMeasure(0.),IfcNonNegativeLengthMeasure(100.))
      IfcNonNegativeLengthMeasure(100.) not valid for <attribute ParentCurve: <entity IfcCurve>>
      In #106=IfcCurveSegment(.CONTINUOUS.,#102,IfcParameterValue(-461.366),IfcNonNegativeLengthMeasure(461.366))
      IfcNonNegativeLengthMeasure(461.366) not valid for <attribute ParentCurve: <entity IfcCurve>>
      
       
  • Rick

    Rick - 2021-07-01

    Thanks for the clarification. It seems alignment->Nests() would be right because I want to know what is nested inside the alignment. Since alignment->IsNestedBy() is correct, then I'll update my brain.

    Very interesting about the file. I pulled it from bSI-InfraRoom/IFC-infra-unit-test on github.

    How do you dump the schema validation errors?

     
    • Thomas Krijnen

      Thomas Krijnen - 2021-07-15

      I find the "active" form using verbs also confusing. I would have picked something like IsPartOf and HasParts and then some property on the relationship whether it is containment/decomposition/nesting.

      The schema validation errors you can find with ifcopenshell-python. If you have it installed it's simply:

       python -m ifcopenshell.validate my_file.ifc
      
       

Log in to post a comment.