ansys / pyansys-geometry

A Python wrapper for Ansys Geometry Services
https://geometry.docs.pyansys.com/
MIT License
38 stars 11 forks source link

Add examples with MasterBodies and templates #546

Open RobPasMue opened 1 year ago

RobPasMue commented 1 year ago

@jonahrb we should include your car example inside the documentation examples. Do you have your script somewhere? If so, just paste it inside the issue - I can handle the reformatting.

jonahrb commented 1 year ago

Here's a script that makes the 2 cars.

m = Modeler(port="50051")
design = m.create_design("design1")

# Create a car
car1 = design.add_component("Car1")
top_comp = car1.add_component("A").add_component("Top")
comp2 = car1.add_component("B")
wheel1 = comp2.add_component("Wheel1")

# Create car base frame
sketch = Sketch().box(Point2D([5, 10]), 10, 20)
comp2.add_component("Base").extrude_sketch("BaseBody", sketch, 5)

# Create first wheel
sketch = Sketch(Plane(direction_x=Vector3D([0, 1, 0]), direction_y=Vector3D([0, 0, 1])))
sketch.circle(Point2D([0, 0]), 5)
wheel_body = wheel1.extrude_sketch("WheelBody", sketch, -5)

# Create 3 other wheels and move them into position
rotation_origin = Point3D([0, 0, 0])
rotation_direction = UnitVector3D([0, 0, 1])

wheel2 = comp2.add_component("Wheel2", wheel1)
wheel2.modify_placement(Vector3D([0, 20, 0]))

wheel3 = comp2.add_component("Wheel3", wheel1)
wheel3.modify_placement(Vector3D([10, 0, 0]), rotation_origin, rotation_direction, np.pi)

wheel4 = comp2.add_component("Wheel4", wheel1)
wheel4.modify_placement(Vector3D([10, 20, 0]), rotation_origin, rotation_direction, np.pi)

# Create 2nd car
car2 = design.add_component("Car2", car1)
car2.modify_placement(Vector3D([30, 0, 0]))

# Create top of car - applies to BOTH cars
sketch = Sketch(Plane(Point3D([0, 5, 5]))).box(Point2D([5, 2.5]), 10, 5)
top_comp.extrude_sketch("TopBody", sketch, 5)
design.download("D:\\Work\\Projects\\PyGeometry\\car.scdocx", DesignFileFormat.SCDOCX)
design.plot()
RobPasMue commented 1 year ago

Assigning to @dastan-ansys ... just in case you have time =)

RobPasMue commented 6 months ago

@jonahrb @dastan-ansys - do you think you could be able to provide some examples for this? Based on the above script it should be fairly straightforward