From da9be7cff0f8ac8bc888b273a1d5f4703463ba81 Mon Sep 17 00:00:00 2001 From: smr <67860835+smr02@users.noreply.github.com> Date: Thu, 28 Aug 2025 23:27:57 +0200 Subject: [PATCH] Fix PythonOCC >=7.8.0 compatibility in serialize_shape function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves issue #6099: PythonOCC >=7.8.0 changed WriteToString() method signature, causing TypeError in ifcopenshell.geom.serialise(). This fix uses signature inspection to detect the method signature: - For PythonOCC < 7.8.0: Use WriteToString() (no parameters) - For PythonOCC >= 7.8.0: Fall back to Write() method - Graceful handling of signature inspection failures 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../ifcopenshell/geom/occ_utils.py | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py b/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py index eb3fa7ac52..7d19981a8b 100644 --- a/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py +++ b/src/ifcopenshell-python/ifcopenshell/geom/occ_utils.py @@ -18,6 +18,7 @@ from __future__ import annotations +import inspect import random import operator import warnings @@ -225,10 +226,24 @@ def serialize_shape(shape): shapes.SetFormatNb(2) shapes.Add(shape) + + # Check if WriteToString method exists and has the correct signature + # In PythonOCC >= 7.8.0, WriteToString signature changed and requires additional arguments if hasattr(shapes, "WriteToString"): - return shapes.WriteToString() - else: - return shapes.Write() + try: + # Try to get the method signature + sig = inspect.signature(shapes.WriteToString) + # If WriteToString has no parameters (just self), use it + # This works for PythonOCC < 7.8.0 + if len(sig.parameters) == 0: + return shapes.WriteToString() + except (ValueError, TypeError): + # If signature inspection fails, fall through to Write() method + pass + + # Fall back to Write() method for newer PythonOCC versions (>= 7.8.0) + # or when WriteToString is not available/compatible + return shapes.Write() def create_shape_from_serialization(