Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 18, 2024
1 parent 31f2fc7 commit 047c028
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions jupytercad_freecad/freecad/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,32 @@ def save(self, objects: List, options: Dict, metadata: Dict) -> None:
# Add the Color property if it doesn't exist
if prop == "Color":
try:
color_value = tuple(jcad_prop_value) if isinstance(jcad_prop_value, (list, tuple)) else (0.5, 0.5, 0.5)
if all(isinstance(x, (int, float)) for x in color_value):
fc_obj.addProperty("App::PropertyColor", "Color", "Base", "A custom color property")
color_value = (
tuple(jcad_prop_value)
if isinstance(jcad_prop_value, (list, tuple))
else (0.5, 0.5, 0.5)
)
if all(
isinstance(x, (int, float)) for x in color_value
):
fc_obj.addProperty(
"App::PropertyColor",
"Color",
"Base",
"A custom color property",
)
setattr(fc_obj, "Color", color_value)
logger.info(f"Added Color property to object '{obj_name}'.")
logger.info(
f"Added Color property to object '{obj_name}'."
)
else:
logger.error(f"Invalid color value: {jcad_prop_value} for object '{obj_name}'")
logger.error(
f"Invalid color value: {jcad_prop_value} for object '{obj_name}'"
)
except Exception as e:
logger.error(f"Failed to add Color property to object '{obj_name}': {e}")
logger.error(
f"Failed to add Color property to object '{obj_name}': {e}"
)

OfflineRenderingUtils.save(
fc_file,
Expand Down

0 comments on commit 047c028

Please sign in to comment.