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
intmain(intargc,char**argv){//Redirecttheoutput(bothprogressandlog)tostdoutLogger::SetOutput(&std::cout,&std::cout);//ParsetheIFCfileprovidedinargv[1]IfcParse::IfcFilefile(argv[1]);if(!file.good()){std::cout<<"Unable to parse .ifc file"<<std::endl;return1;}autoalignments=file.instances_by_type<Ifc4x3_rc2::IfcAlignment>();autoalignment=*(alignments->begin());autonests=alignment->Nests();for(autorel_nests:*nests)//nests->size()==0sotheloopisskippedover{autorelated_objects=rel_nests->RelatedObjects();for(autorelated_object:*related_objects){autohorizontal_alignment=related_object->as<Ifc4x3_rc2::IfcAlignmentHorizontal>();autovertical_alignment=related_object->as<Ifc4x3_rc2::IfcAlignmentVertical>();if(horizontal_alignment){//dosomething}elseif(vertical_alignment){//dosomething}}}return0;}
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.
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.
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
The schema validator gives these errors
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?
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: