import sys
from build123d import import_step
import build123d as b3d
print("build123d", b3d.__version__)
step = sys.argv[1]
shape = import_step(step)
print("type", type(shape).__name__)
print("volume", shape.volume)
bbox = shape.bounding_box()
print("bbox.size", tuple(round(v,2) for v in (bbox.size.X, bbox.size.Y, bbox.size.Z)))
# bbox center (always works)
try:
    c = bbox.center()
    print("bbox.center()", (round(c.X,2), round(c.Y,2), round(c.Z,2)))
except Exception as e:
    print("bbox.center FAIL", type(e).__name__, e)
# the failing call
try:
    c = shape.center()
    print("shape.center()", (round(c.X,2), round(c.Y,2), round(c.Z,2)))
except Exception as e:
    print("shape.center() FAIL", type(e).__name__, e)
# workaround: collapse to solids compound
try:
    from build123d import Compound
    solids = shape.solids()
    print("n_solids", len(solids))
    comp = Compound(children=solids)
    c = comp.center()
    print("Compound(solids).center()", (round(c.X,2), round(c.Y,2), round(c.Z,2)))
except Exception as e:
    print("solids workaround FAIL", type(e).__name__, e)
