Skip to content

Commit

Permalink
🐛 Fix save cad unit
Browse files Browse the repository at this point in the history
  • Loading branch information
je-cook committed Nov 18, 2024
1 parent e089f59 commit 3899524
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 29 deletions.
20 changes: 1 addition & 19 deletions bluemira/codes/_freecadapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1594,9 +1594,7 @@ def wrapper(objs: Part.Feature, filename: str, *, tessellate: float = 0.5, **kwa
return wrapper


def save_as_STP(
shapes: list[apiShape], filename: str = "test", unit_scale: str = "metre"
):
def save_as_STP(shapes: list[apiShape], filename: str = "test"):
"""
Saves a series of Shape objects as a STEP assembly
Expand All @@ -1606,8 +1604,6 @@ def save_as_STP(
Iterable of shape objects to be saved
filename:
Full path filename of the STP assembly
unit_scale:
The scale in which to save the Shape objects
Raises
------
Expand All @@ -1631,13 +1627,6 @@ def save_as_STP(
raise FreeCADError("Shape is null.")

compound = make_compound(shapes)
scale = raw_uc(1, unit_scale, "mm")

if scale != 1:
# scale the compound. Since the scale function modifies directly the shape,
# a copy of the compound is made to avoid modification of the original shapes.
compound = scale_shape(compound.copy(), scale)

compound.exportStep(filename)


Expand All @@ -1662,7 +1651,6 @@ def save_cad(
filename: str,
cad_format: str | CADFileType = "stp",
labels: Iterable[str] | None = None,
unit_scale: str = "metre",
**kwargs,
):
"""
Expand All @@ -1678,8 +1666,6 @@ def save_cad(
file cad_format
labels:
shape labels
unit_scale:
unit to save the objects as.
kwargs:
passed to freecad preferences configuration
Expand Down Expand Up @@ -1711,10 +1697,6 @@ def save_cad(
with Document() as doc:
objs = list(doc.setup(shapes, labels))

# Part is always built in mm but some formats are unitless
if cad_format not in CADFileType.unitless_formats():
_scale_obj(objs, scale=raw_uc(1, unit_scale, "mm"))

# Some exporters need FreeCADGui to be setup before their import,
# this is achieved in _setup_document
try:
Expand Down
8 changes: 3 additions & 5 deletions bluemira/codes/_freecadconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import FreeCAD


class _Unit(enum.IntEnum):
class FCUnit(enum.IntEnum):
"""Available units in FreeCAD"""

MM = 0 # mmKS
Expand Down Expand Up @@ -50,9 +50,7 @@ def _freecad_save_config(
This must be run before Part is imported for legacy exporters
"""
unit_prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units")
# Seems to have little effect on anything but its an option to set
# does effect the GUI be apparently not the base unit of the built part...
unit_prefs.SetInt("UserSchema", _Unit[unit].value)
unit_prefs.SetInt("UserSchema", FCUnit[unit].value)
unit_prefs.SetInt("Decimals", no_dp) # 100th mm

part_step_prefs = FreeCAD.ParamGet(
Expand All @@ -62,7 +60,7 @@ def _freecad_save_config(
part_step_prefs.SetString("Author", author)
part_step_prefs.SetString("Company", "Bluemira")
# Seems to have little effect on anything but its an option to set
part_step_prefs.SetInt("Unit", _Unit[unit].value)
part_step_prefs.SetInt("Unit", FCUnit[unit].value)

part_step_2_prefs = FreeCAD.ParamGet(
"User parameter:BaseApp/Preferences/Mod/Import/hSTEP"
Expand Down
5 changes: 1 addition & 4 deletions bluemira/geometry/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,6 @@ def is_convex(points: npt.NDArray):
def save_as_STP(
shapes: BluemiraGeoT | Iterable[BluemiraGeoT],
filename: str,
unit_scale: str = "metre",
**kwargs,
):
"""
Expand All @@ -1479,15 +1478,13 @@ def save_as_STP(
List of shape objects to be saved
filename:
Full path filename of the STP assembly
unit_scale:
The scale in which to save the Shape objects
"""
filename = force_file_extension(filename, [".stp", ".step"])

if not isinstance(shapes, list):
shapes = list(shapes) if isinstance(shapes, Iterable) else [shapes]

cadapi.save_as_STP([s.shape for s in shapes], filename, unit_scale, **kwargs)
cadapi.save_as_STP([s.shape for s in shapes], filename, **kwargs)


def save_cad(
Expand Down
1 change: 0 additions & 1 deletion examples/geometry/geometry_tutorial.ex.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,5 +403,4 @@
filename=Path(
get_bluemira_path("", subfolder="generated_data"), my_file_path
).as_posix(),
unit_scale="metre",
)

0 comments on commit 3899524

Please sign in to comment.