mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 23:36:20 +00:00
Fix PythonOCC >=7.8.0 compatibility in serialize_shape function
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 <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
import inspect
|
||||||
import random
|
import random
|
||||||
import operator
|
import operator
|
||||||
import warnings
|
import warnings
|
||||||
@@ -225,10 +226,24 @@ def serialize_shape(shape):
|
|||||||
shapes.SetFormatNb(2)
|
shapes.SetFormatNb(2)
|
||||||
|
|
||||||
shapes.Add(shape)
|
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"):
|
if hasattr(shapes, "WriteToString"):
|
||||||
return shapes.WriteToString()
|
try:
|
||||||
else:
|
# Try to get the method signature
|
||||||
return shapes.Write()
|
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(
|
def create_shape_from_serialization(
|
||||||
|
|||||||
Reference in New Issue
Block a user