Title: project.append_asset drops material surface styles when the material is reached via IfcMaterialLayerSetUsage · Issue #8662 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: project.append_asset drops material surface styles when the material is reached via IfcMaterialLayerSetUsage · Issue #8662 · IfcOpenShell/IfcOpenShell
X Title: project.append_asset drops material surface styles when the material is reached via IfcMaterialLayerSetUsage · Issue #8662 · IfcOpenShell/IfcOpenShell
Description: Summary ifcopenshell.api.project.append_asset drops a material's surface style (IfcMaterial.HasRepresentation → IfcMaterialDefinitionRepresentation → IfcStyledItem → IfcSurfaceStyle) when the material is reached through an IfcMaterialLay...
Open Graph Description: Summary ifcopenshell.api.project.append_asset drops a material's surface style (IfcMaterial.HasRepresentation → IfcMaterialDefinitionRepresentation → IfcStyledItem → IfcSurfaceStyle) when the mater...
X Description: Summary ifcopenshell.api.project.append_asset drops a material's surface style (IfcMaterial.HasRepresentation → IfcMaterialDefinitionRepresentation → IfcStyledItem → IfcSurfaceStyle) when the m...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/8662
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"project.append_asset drops material surface styles when the material is reached via IfcMaterialLayerSetUsage","articleBody":"## Summary\n\n`ifcopenshell.api.project.append_asset` drops a material's **surface style**\n(`IfcMaterial.HasRepresentation` → `IfcMaterialDefinitionRepresentation` →\n`IfcStyledItem` → `IfcSurfaceStyle`) when the material is reached through an\n**`IfcMaterialLayerSetUsage`** — i.e. real wall/slab *occurrences*. The materials\nthemselves are appended, but arrive with `HasRepresentation == ()`, so they lose their\ncolour.\n\nIn Bonsai this shows up when appending an object (e.g. via\n`bpy.ops.bim.append_library_element_by_query()` /\n`bpy.ops.bim.append_library_element()`): the object's materials come across but the\nstyles assigned to those materials do not.\n\nIt only reproduces when the material sits in a set reached via a **usage**. A single\ndirectly-assigned material, or a type product carrying a bare `IfcMaterialLayerSet`,\nboth preserve their styles — which is why it can be easy to miss.\n\n## Minimal reproduction (pure `ifcopenshell`, no Bonsai)\n\n```python\nimport ifcopenshell\nimport ifcopenshell.api.root, ifcopenshell.api.context, ifcopenshell.api.material\nimport ifcopenshell.api.style, ifcopenshell.api.project, ifcopenshell.api.type\nimport ifcopenshell.api.owner.settings\n\n# Bare-script owner-history stubs (Bonsai sets these up for you).\nifcopenshell.api.owner.settings.get_user = lambda ifc: None\nifcopenshell.api.owner.settings.get_application = lambda ifc: None\n\n# --- Library: a wall type + occurrence sharing one styled material ---\nlib = ifcopenshell.api.project.create_file() # IFC4\nifcopenshell.api.root.create_entity(lib, ifc_class=\"IfcProject\")\nctx = ifcopenshell.api.context.add_context(lib, context_type=\"Model\")\n\nwall_type = ifcopenshell.api.root.create_entity(lib, ifc_class=\"IfcWallType\")\nwall = ifcopenshell.api.root.create_entity(lib, ifc_class=\"IfcWall\")\nifcopenshell.api.type.assign_type(lib, related_objects=[wall], relating_type=wall_type)\n\nmaterial = ifcopenshell.api.material.add_material(lib, name=\"Material\")\nstyle = ifcopenshell.api.style.add_style(lib) # IfcSurfaceStyle\nifcopenshell.api.style.assign_material_style(lib, material=material, style=style, context=ctx)\n\nlayer_set = ifcopenshell.api.material.add_material_set(lib, set_type=\"IfcMaterialLayerSet\")\nlayer = ifcopenshell.api.material.add_layer(lib, layer_set=layer_set, material=material)\nifcopenshell.api.material.edit_layer(lib, layer=layer, attributes={\"LayerThickness\": 0.1})\n\n# Type gets the bare layer set; the occurrence wraps it in a usage, like real walls.\nifcopenshell.api.material.assign_material(lib, products=[wall_type], material=layer_set)\nusage = lib.create_entity(\"IfcMaterialLayerSetUsage\", ForLayerSet=layer_set,\n LayerSetDirection=\"AXIS2\", DirectionSense=\"POSITIVE\", OffsetFromReferenceLine=0.0)\nlib.create_entity(\"IfcRelAssociatesMaterial\", GlobalId=ifcopenshell.guid.new(),\n RelatedObjects=[wall], RelatingMaterial=usage)\n\nassert material.HasRepresentation, \"sanity: library material is styled\"\n\n# --- Append the occurrence into a fresh project ---\nf = ifcopenshell.file(schema=lib.schema)\nifcopenshell.api.root.create_entity(f, ifc_class=\"IfcProject\")\nifcopenshell.api.context.add_context(f, context_type=\"Model\")\nifcopenshell.api.project.append_asset(f, library=lib, element=wall)\n\nm = f.by_type(\"IfcMaterial\")[0]\nprint(\"appended material HasRepresentation:\", m.HasRepresentation)\nprint(\"appended IfcSurfaceStyle :\", f.by_type(\"IfcSurfaceStyle\"))\n```\n\n**Expected**\n```\nappended material HasRepresentation: (#..=IfcMaterialDefinitionRepresentation(...),)\nappended IfcSurfaceStyle : [#..=IfcSurfaceStyle(...)]\n```\n\n**Actual**\n```\nappended material HasRepresentation: ()\nappended IfcSurfaceStyle : []\n```\n\n## Root cause\n\nIn `append_asset.py`, `Usecase.add_element`:\n\n1. The occurrence's `RelatingMaterial` is an `IfcMaterialLayerSetUsage` →\n `IfcMaterialLayerSet`. `file_add` **forward-copies** the whole usage → set → layers →\n materials subgraph into the project. `file_add` only copies *forward* attributes;\n inverse attributes (`HasRepresentation`, `HasProperties`, …) are handled separately by\n `check_inverses`, which runs from `add_element`'s subgraph traversal.\n2. When that traversal reaches the layer set, `get_existing_element` matches the fresh\n forward-copy as \"existing\" (via `material_sets_are_equal`), so it takes the\n `if existing_element:` branch — which **does not extend the traversal queue into the\n set**. The member `IfcMaterial`s are therefore never visited, `check_inverses` never\n runs on them, and `IfcMaterial.HasRepresentation` (which carries the surface style) is\n never transplanted.\n3. A subsequent type append short-circuits even earlier: the set is already in\n `added_elements`, so `add_element` returns immediately.\n\n## Regression origin\n\nThis is a regression from the material-set **reuse** feature:\n\n- `b4740b6949` — *append_asset to also match material sets by the name #6762*\n- `a17b0604e1` — *api.project.append_asset deduplicate material sets* (added\n `material_sets_are_equal`)\n\nBefore those, appended materials kept their styles.\n\n## Notes\n\n- Not a Bonsai import bug — Bonsai's `import_material_styles` / `create_style` are correct;\n the IFC simply arrives style-less.\n- A fix (descend into a matched-existing material set so member materials get\n `check_inverses`, keyed off `MATERIAL_SETS` so constituent/profile sets benefit too) plus\n a regression test are prepared and will be submitted as a PR.\n\nEnvironment: `ifcopenshell` 0.8.0 (current `v0.8.0`); reproduced on Windows, IFC4 (schema-agnostic).\n","author":{"url":"https://github.com/theoryshaw","@type":"Person","name":"theoryshaw"},"datePublished":"2026-07-16T22:03:36Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/8662"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:48ddc86f-5e99-c0bc-fbef-38f25d825432 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C21A:222D8A:249793:33A3DD:6B046952 |
| html-safe-nonce | 1432129c4a5bc540ffd73b683552d317b66b8736989a243dce6cdfe46592f2d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjFBOjIyMkQ4QToyNDk3OTM6MzNBM0REOjZCMDQ2OTUyIiwidmlzaXRvcl9pZCI6IjU3MDcxMjQ2NDg5MDc2NjM2OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c36d0aaccdb9aff7b9c4218c54f9af1a17e6d1ccf49f2ccbbc20676612633b44 |
| hovercard-subject-tag | issue:4906346156 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/8662/issue_layout |
| twitter:image | https://opengraph.githubassets.com/233ce31a6d69cdb880f8b9aac6e843e975862e51ba9c92d1baf1a948d2f855d6/IfcOpenShell/IfcOpenShell/issues/8662 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/233ce31a6d69cdb880f8b9aac6e843e975862e51ba9c92d1baf1a948d2f855d6/IfcOpenShell/IfcOpenShell/issues/8662 |
| og:image:alt | Summary ifcopenshell.api.project.append_asset drops a material's surface style (IfcMaterial.HasRepresentation → IfcMaterialDefinitionRepresentation → IfcStyledItem → IfcSurfaceStyle) when the mater... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | theoryshaw |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width