Issue calling translate_sketch_plane_by_distance when default units is not meters #1807
Closed
2 tasks done
Labels
bug
Something isn't working
🔍 Before submitting the issue
🐞 Description of the bug
This issue is seen when I set the default units to millimeters:
DEFAULT_UNITS.LENGTH = UNITS.mm
In my code I'm translating a sketch plane by 10mm in the z direction:
sketch.translate_sketch_plane_by_distance(UnitVector3D([0, 0, 1]), Distance(10, UNITS.mm))
However the sketch plane is translated 10m in the z direction
📝 Steps to reproduce
Run the following code. At the end, a plot of the extruded outline is made, in PyVista you can observe the extruded outline is extremely far away from the sketch plane in the plot (see image at end of code). This is because the sketch plane for this extruded body was translated 10m in the z direction instead of 10mm.
Import libraries
import os
import sys
from pathlib import Path
from pyvista.plotting import system_supports_plotting
from ansys.geometry.core import *
from ansys.geometry.core.connection import *
from ansys.geometry.core.designer import *
from ansys.geometry.core.materials import *
from ansys.geometry.core.math import *
from ansys.geometry.core.misc import *
from ansys.geometry.core.misc.units import *
from ansys.geometry.core.parameters import *
from ansys.geometry.core.plotting import *
from ansys.geometry.core.shapes import *
from ansys.geometry.core.sketch import *
from ansys.geometry.core.tools import *
import math
Connect to Core Service backend
modeler = Modeler(host="127.0.0.1", port=50051, timeout=10)
Create initial design and set default units to millimeters
design = modeler.create_design("bracket")
DEFAULT_UNITS.LENGTH = UNITS.mm
Extrude bracket body
sketch = Sketch()
segment = sketch.segment(Point2D([0, 0]), Point2D([191.5319, 20]))
segment = segment.segment_to_point(Point2D([196, 10]))
segment = segment.segment_to_point(Point2D([8, -74]))
segment = segment.segment_to_point(Point2D([-16, -74]))
segment = segment.segment_to_point(Point2D([0, 0]))
body = design.extrude_sketch("bracket_extrude", sketch, 10)
Cut three holes in the body
sketch = Sketch()
sketch.circle(Point2D([12.3649, -13.79040]), 5)
sketch.circle(Point2D([2.5899, -59]), 5)
sketch.circle(Point2D([179.5442, 11.3572]), 5)
faces = body.project_curves(direction=UNITVECTOR3D_Z, sketch=sketch, closest_face=True, only_one_curve=True)
new_edges, new_faces = body.imprint_curves(faces, sketch)
for face in new_faces:
hole = design.extrude_face("hole", face, 10)
body.subtract(hole)
Sketch first cutout
sketch = Sketch()
segment = sketch.segment(Point2D([32.6723, -3.3362]), Point2D([25.422, -58.9219]))
segment = segment.segment_to_point(Point2D([47.4057, -46.7735]))
segment = segment.segment_to_point(Point2D([50.6723, -38.7762]))
segment = segment.segment_to_point(Point2D([78.8, -26.4]))
segment = segment.segment_to_point(Point2D([32.6723, -3.3362]))
Sketch second cutout
segment = sketch.segment(Point2D([46.4086, -1.2043]), Point2D([86.4086, -21.2043]))
segment = segment.segment_to_point(Point2D([96.9864, 4.6925]))
segment = segment.segment_to_point(Point2D([46.4086, -1.2043]))
Sketch third cutout
segment = sketch.segment(Point2D([107.5841, 5.928]), Point2D([97.7928, -18.0432]))
segment = segment.segment_to_point(Point2D([107.8933, -13.5989]))
segment = segment.segment_to_point(Point2D([118.6723, -15.4162]))
segment = segment.segment_to_point(Point2D([150.6723, -1.3362]))
segment = segment.segment_to_point(Point2D([107.5841, 5.928]))
Sketch fourth cutout
segment = sketch.segment(Point2D([129.2148, 8.4499]), Point2D([160.8082, 3.1236]))
segment = segment.segment_to_point(Point2D([164.6723, 12.5838]))
segment = segment.segment_to_point(Point2D([129.2148, 8.4499]))
faces = body.project_curves(direction=UNITVECTOR3D_Z, sketch=sketch, closest_face=True, only_one_curve=True)
new_edges, new_faces = body.imprint_curves(faces, sketch)
for face in new_faces:
cutout = design.extrude_face("cutout", face, 10)
body.subtract(cutout)
Define outline sketch
def outline_sketch(sketch):
segment = sketch.segment(Point2D([28, -1.059]), Point2D([28, -14]))
segment = segment.segment_to_point(Point2D([20, -58]))
segment = segment.segment_to_point(Point2D([20, -65.5623]))
segment = segment.segment_to_point(Point2D([55.1617, -48.8931]))
segment = segment.segment_to_point(Point2D([57.4117, -42.8931]))
segment = segment.segment_to_point(Point2D([102.3421, -23.7647]))
segment = segment.segment_to_point(Point2D([108.3421, -26.0147]))
segment = segment.segment_to_point(Point2D([164.5502, -1.8342]))
segment = segment.segment_to_point(Point2D([170.77906, 14.8067]))
segment = segment.segment_to_point(Point2D([28, -1.059]))
Sketch outline on the front of the bracket
sketch = Sketch()
outline_sketch(sketch)
Extrude and subtract front outline
outline = design.extrude_sketch("outline", sketch, 2)
body.subtract(outline)
Sketch outline on the back of the bracket
sketch = Sketch()
sketch.translate_sketch_plane_by_distance(UnitVector3D([0, 0, 1]), Distance(10, UNITS.mm))
outline_sketch(sketch)
Extrude and subtract back outline
outline = design.extrude_sketch("outline", sketch, -2)
outline.plot()
body.subtract(outline)
💻 Which operating system are you using?
Windows
📀 Which ANSYS version are you using?
25.2
🐍 Which Python version are you using?
3.12
📦 Installed packages
The text was updated successfully, but these errors were encountered: