Add documentation and APIs to support crawling the model
As my questions in StackOverflow explain (Q1, Q2) I'm trying to write an exported from IFC to a simpler format like OBJ For that the glTF example was very useful (thanks @agviegas!)
But there's still an unresolved problem of how can I access all types in a given IFC as opposed to what all examples focus on which is given a list of types, how do I access them in the IFC.
I was able to get close to getting all types in the following code, but I still can't make it work for multiple reasons:
const allTypes = {}
ifcLoader.ifcManager.getSpatialStructure(bimModel.modelID).then(ifcProject => {
let currentElement = ifcProject
const children = [...currentElement.children]
const ids = []
while (children.length) {
currentElement = children.pop()
children.push(...currentElement.children)
if (!currentElement.children.length) {
console.log(currentElement.type, typeof currentElement.type)
allTypes[currentElement.type] = true
ids.push(currentElement.expressID)
}
}
Object.keys(allTypes).forEach(type => {
this.getGeometriesOfType(type).then(geometries => {
// enjoy the geometries
})
})
})
Mainly because currentElement.type returns the string 'IFCDOOR' and not the enum (int) IFCDOOR as Q2 says
I'm not familiar enough with the project, but maybe during parsing of the IFC the list of types can be maintained and then easily accessed through the ifcManager/ifcProject without having to reiterate everything recursively.
Hi,
About your Question 2
if you're expecting the following result : where {key : IFCENTITY: int , ...}

You could check the web-ifc-api there is a helper method for inspiration here.
Just as an exemple
let IfcElements = {
103090709: 'IFCPROJECT',
4097777520: 'IFCSITE',
4031249490: 'IFCBUILDING',
3124254112: 'IFCBUILDINGSTOREY',
3856911033: 'IFCSPACE',
1674181508: 'IFCANNOTATION',
25142252: 'IFCCONTROLLER',
32344328: 'IFCBOILER',
76236018: 'IFCLAMP',
90941305: 'IFCPUMP',
177149247: 'IFCAIRTERMINALBOX',
182646315: 'IFCFLOWINSTRUMENT',
263784265: 'IFCFURNISHINGELEMENT',
264262732: 'IFCELECTRICGENERATOR',
277319702: 'IFCAUDIOVISUALAPPLIANCE',
310824031: 'IFCPIPEFITTING',
331165859: 'IFCSTAIR',
342316401: 'IFCDUCTFITTING',
377706215: 'IFCMECHANICALFASTENER',
395920057: 'IFCDOOR',
402227799: 'IFCELECTRICMOTOR',
413509423: 'IFCSYSTEMFURNITUREELEMENT',
484807127: 'IFCEVAPORATOR',
486154966: 'IFCWINDOWSTANDARDCASE',
629592764: 'IFCLIGHTFIXTURE',
630975310: 'IFCUNITARYCONTROLELEMENT',
635142910: 'IFCCABLECARRIERFITTING',
639361253: 'IFCCOIL',
647756555: 'IFCFASTENER',
707683696: 'IFCFLOWSTORAGEDEVICE',
738039164: 'IFCPROTECTIVEDEVICE',
753842376: 'IFCBEAM',
812556717: 'IFCTANK',
819412036: 'IFCFILTER',
843113511: 'IFCCOLUMN',
862014818: 'IFCELECTRICDISTRIBUTIONBOARD',
900683007: 'IFCFOOTING',
905975707: 'IFCCOLUMNSTANDARDCASE',
926996030: 'IFCVOIDINGFEATURE',
979691226: 'IFCREINFORCINGBAR',
987401354: 'IFCFLOWSEGMENT',
1003880860: 'IFCELECTRICTIMECONTROL',
1051757585: 'IFCCABLEFITTING',
1052013943: 'IFCDISTRIBUTIONCHAMBERELEMENT',
1062813311: 'IFCDISTRIBUTIONCONTROLELEMENT',
1073191201: 'IFCMEMBER',
1095909175: 'IFCBUILDINGELEMENTPROXY',
1156407060: 'IFCPLATESTANDARDCASE',
1162798199: 'IFCSWITCHINGDEVICE',
1329646415: 'IFCSHADINGDEVICE',
1335981549: 'IFCDISCRETEACCESSORY',
1360408905: 'IFCDUCTSILENCER',
1404847402: 'IFCSTACKTERMINAL',
1426591983: 'IFCFIRESUPPRESSIONTERMINAL',
1437502449: 'IFCMEDICALDEVICE',
1509553395: 'IFCFURNITURE',
1529196076: 'IFCSLAB',
1620046519: 'IFCTRANSPORTELEMENT',
1634111441: 'IFCAIRTERMINAL',
1658829314: 'IFCENERGYCONVERSIONDEVICE',
1677625105: 'IFCCIVILELEMENT',
1687234759: 'IFCPILE',
1904799276: 'IFCELECTRICAPPLIANCE',
1911478936: 'IFCMEMBERSTANDARDCASE',
1945004755: 'IFCDISTRIBUTIONELEMENT',
1973544240: 'IFCCOVERING',
1999602285: 'IFCSPACEHEATER',
2016517767: 'IFCROOF',
2056796094: 'IFCAIRTOAIRHEATRECOVERY',
2058353004: 'IFCFLOWCONTROLLER',
2068733104: 'IFCHUMIDIFIER',
2176052936: 'IFCJUNCTIONBOX',
2188021234: 'IFCFLOWMETER',
2223149337: 'IFCFLOWTERMINAL',
2262370178: 'IFCRAILING',
2272882330: 'IFCCONDENSER',
2295281155: 'IFCPROTECTIVEDEVICETRIPPINGUNIT',
2320036040: 'IFCREINFORCINGMESH',
2347447852: 'IFCTENDONANCHOR',
2391383451: 'IFCVIBRATIONISOLATOR',
2391406946: 'IFCWALL',
2474470126: 'IFCMOTORCONNECTION',
2769231204: 'IFCVIRTUALELEMENT',
2814081492: 'IFCENGINE',
2906023776: 'IFCBEAMSTANDARDCASE',
2938176219: 'IFCBURNER',
2979338954: 'IFCBUILDINGELEMENTPART',
3024970846: 'IFCRAMP',
3026737570: 'IFCTUBEBUNDLE',
3027962421: 'IFCSLABSTANDARDCASE',
3040386961: 'IFCDISTRIBUTIONFLOWELEMENT',
3053780830: 'IFCSANITARYTERMINAL',
3079942009: 'IFCOPENINGSTANDARDCASE',
3087945054: 'IFCALARM',
3101698114: 'IFCSURFACEFEATURE',
3127900445: 'IFCSLABELEMENTEDCASE',
3132237377: 'IFCFLOWMOVINGDEVICE',
3171933400: 'IFCPLATE',
3221913625: 'IFCCOMMUNICATIONSAPPLIANCE',
3242481149: 'IFCDOORSTANDARDCASE',
3283111854: 'IFCRAMPFLIGHT',
3296154744: 'IFCCHIMNEY',
3304561284: 'IFCWINDOW',
3310460725: 'IFCELECTRICFLOWSTORAGEDEVICE',
3319311131: 'IFCHEATEXCHANGER',
3415622556: 'IFCFAN',
3420628829: 'IFCSOLARDEVICE',
3493046030: 'IFCGEOGRAPHICELEMENT',
3495092785: 'IFCCURTAINWALL',
3508470533: 'IFCFLOWTREATMENTDEVICE',
3512223829: 'IFCWALLSTANDARDCASE',
3518393246: 'IFCDUCTSEGMENT',
3571504051: 'IFCCOMPRESSOR',
3588315303: 'IFCOPENINGELEMENT',
3612865200: 'IFCPIPESEGMENT',
3640358203: 'IFCCOOLINGTOWER',
3651124850: 'IFCPROJECTIONELEMENT',
3694346114: 'IFCOUTLET',
3747195512: 'IFCEVAPORATIVECOOLER',
3758799889: 'IFCCABLECARRIERSEGMENT',
3824725483: 'IFCTENDON',
3825984169: 'IFCTRANSFORMER',
3902619387: 'IFCCHILLER',
4074379575: 'IFCDAMPER',
4086658281: 'IFCSENSOR',
4123344466: 'IFCELEMENTASSEMBLY',
4136498852: 'IFCCOOLEDBEAM',
4156078855: 'IFCWALLELEMENTEDCASE',
4175244083: 'IFCINTERCEPTOR',
4207607924: 'IFCVALVE',
4217484030: 'IFCCABLESEGMENT',
4237592921: 'IFCWASTETERMINAL',
4252922144: 'IFCSTAIRFLIGHT',
4278956645: 'IFCFLOWFITTING',
4288193352: 'IFCACTUATOR',
4292641817: 'IFCUNITARYEQUIPMENT',
3009204131: 'IFCGRID'
};
modelID = ifcapi.OpenModel(ifcData);
const result = {};
const elements = Object.keys(IfcElements).map((e) => parseInt(e));
for(let i = 0; i < elements.length; i++) {
const element = elements[i];
const lines = await ifcapi.GetLineIDsWithType(modelID, element);
const size = lines.size();
//@ts-ignore
for (let i = 0; i < size; i++) result[lines.get(i)] = element;
}
console.log(result);
@agviegas is it possible to add a getter IfcApi.properties.getTypes(). here or giving public access to getAllTypesOfModel(modelID: number)
So currently the workaround I have is this:
const typesMapReversed = Object.entries(ifcLoader.ifcManager.typesMap)
.reduce((acc, [key, value]) => {
acc[value] = Number(key)
return acc
}, {})
Which doesn't make a lot of sense in my opinion but it works
I definitely would love having something like getAllTypesOfModel exposed as from reading the code and my limited understanding of IFC I have no idea how to rip-off (and it sounds to me like a basic enough functionality).
I can imagine I'm not the first person to try and get a list of object types present in the model in a way that I can then access them as well.
We could perhaps make a function to get all types present in a file (and all elements)? π€
@bergden-resonai btw did you know there is also IfcConvert, an IfcOpenShell based open source CLI / lib that you can use to convert IFCs to OBJ?
@Moult Thanks! I actually tried using IfcOpenShell originally but in my specific use-case I needed to integrated this to a web application, and eventually I want to allow the user to select types and subsets they want to save/convert
::take
π’π’π’
::take
Hi, @BSchafer01! Thanks for taking this bounty! The due date is November 23, 2022 UTC.
If you need to submit some pull requests (PR) to complete the tasks, make sure that the last and only the last PR has a title that either starts with the bounty ID or is exactly the same as the bounty name. After the PR is merged, this bountyβs status will automatically changed to done.
If you do not need to make a PR, tell the manager @agviegas to run ::done command after your tasks is confirmed to be done.
Good luck!
Can I recommend that getting all types isn't exactly what you're after given the original usecase? I might recommend that you're after getting the representations of a context. Because there may be types without a geometry or occurrences without a type.
::done
::done
π’π’π’
::done
Hi, @BSchafer01! Thanks for your contributions! Please submit an expense to IFC.js Open Collective. Then, tell us the invoice number via the ::expense::_____ command (replace the _____ with the invoice number).
::expense::106176
π’π’π’
::expense::106176
Hi, @BSchafer01! Thanks for the confirmation! Weβll proceed to review the expense. Once itβs approved, the payment will be scheduled.
πππ
Hi, @BSchafer01! Thanks for your contributions! The reward of this bounty has been transferred to your Open Collective account.
@bergden-resonai by the way, great news! You can now use IfcOpenShell on the web via WASM, so that's also now an option. https://twitter.com/BlenderBIM/status/1589938011764318209