Create a shell cylinder with PyAnsys

Hello everyone,
I would like to generate a cylinder as a shell from a line that I create with the PyAnsys Modeler. In SpaceClaim and Discovery this is easy using the selection and pull function to then rotate the line with the RevolveEdge function in the IronPython API Script Editor. Is this also possible in PyAnsys? I think it is possible, but I haven't found the solution yet. Because when I use the function component.revolve(), I get an error.
standardUnit = unit.mm sketch = Sketch() start_point = Point2D([xMid_bottom, yMid_bottom], unit=standardUnit) end_point = Point2D([xMid_top, yMid_top], unit=standardUnit) sketch.segment(start_point, end_point, "Midline") component = design.add_component(name="what ever") component.revolve_sketch(name=shell.label, sketch=sketch, axis=UNITVECTOR3D_Y, angle=Angle(360, unit=unit.degrees), rotation_origin=Point3D([0, 0, 0]))
Answers
-
Hi @SchluppIng -- I think something like this is what you are looking for
import numpy as np from ansys.geometry.core import launch_modeler from ansys.geometry.core.math.constants import UNITVECTOR3D_Z from ansys.geometry.core.shapes.curves.circle import Circle from ansys.geometry.core.shapes.curves.line import Line from ansys.geometry.core.shapes.parameterization import Interval modeler = launch_modeler() # Create a design design = modeler.create_design(name="MyDesign") # Create your start and end point for your line line_point = [10, 0, 0] # Create the profile (cylinder's vertical line representing the outside of the cylinder) profile = [ Line(line_point, UNITVECTOR3D_Z).trim(Interval(0, 10)), ] # Create path for sweeping the profile (radius is defined randomly in this case, since # the profile is a line, it will be swept along the line) path = [Circle(origin=[0, 0, 0], radius=5).trim(Interval(0, 2 * np.pi))] # Create the sweep sweep = design.sweep_chain( name="MySweep", path=path, chain=profile, ) # Plot the sweep design.plot()
Currently, the
revolve_sketch
only accepts closed sketches. We will work to try and accept open sketches (and thus allowing you to define shelled bodies) in the future. Hope this serves0 -
Have a look at https://geometry.docs.pyansys.com/version/stable/examples/03_modeling/sweep_chain_profile.html# for more examples related to sweeping chains (open sketches) and sketches (closed sketches)
0 -
Hi @RobPasMue,
thanks for the quick answer. In general it works fine, but the line is just a straight line. How do a create an inclined line with a start and end point?
0 -
Hi @RobPasMue,
thanks for the quick answer. Short question regarding the Line.
0 -
Hi @SchluppIng -- sorry for the late response!
You could define a vector that represents your line's direction (not aligned along X, Y ,Z axis) and then trim from your starting point to your end point. Something like:
unit_vec= UnitVector3D([1, 1, 1]) x0 = Point3D([2, 3, 4]) profile = [ Line(x0, unit_vec).trim(Interval(0, 10)), ]
This line would have an origin/start point at x0 and you would trim it for 10 length units. And its direction is defined by unit_vec.
I hope this helps!
0