Replies: 2 comments 4 replies
-
Is this what you need: #1353 ? |
Beta Was this translation helpful? Give feedback.
-
@adam-urbanczyk I believe the ask is to split a face using a polygon. This is typical in simulations to select surfaces and apply a boundary condition on them. Given a cube and a triangle shape, one would like to see that rectangular face of the cube be split into two face, one a triangle and other the boolean of the rectangle and triangle. See image for illustration. Turns out I would also need this functionality for my carpet on a staircase like CAD im trying to generate #1698 . I tried to implement it using a script. I still have one issue that the final exported STEP file shows a surface body and a solidbody, What I would like is a single solid body with 7 surfaces instead of the original 6. Sharing script here: import cadquery as cq
from jupyter_cadquery import show
from OCP.BRepFeat import BRepFeat_SplitShape
from cadquery.occ_impl.shapes import Shape
# Step 1: Define the base model (the box)
base_model = cq.Workplane("XY").box(10, 10, 10, centered=True)
# show(base_model)
# Step 2: Define the wire on the top face as a triangle
# We create a triangular wire by connecting three points on the top face
top_wire = (
base_model.faces(">Z") # Select the top face
.workplane() # Go to the local workplane of the top face
.moveTo(-2.5, -2.5) # Start at one corner of the top face
.lineTo(2.5, -2.5) # Draw the first line to the second point
.lineTo(0, 2.5) # Draw the second line to the third point
.close() # Close the triangle by connecting back to the starting point
.wire() # Create a wire from the closed triangle
)
show(base_model, top_wire)
# Step 3: Extract the wire as a TopoDS_Shape
# The `wrapped` attribute converts the CadQuery object to a TopoDS_Shape
split_wire_shape = top_wire.val().wrapped
print(f'split_wire_shape is of type {type(split_wire_shape)}')
# Step 4: Initialize the BRepFeat_SplitShape with the top face shape
top_face_shape = base_model.faces(">Z").val().wrapped
split_shape = BRepFeat_SplitShape(top_face_shape)
print(f'split_shape is of type {type(split_shape)}')
# Step 5: Add the wire to split the shape
split_shape.Add(split_wire_shape, top_face_shape)
# Step 6: Build the split operation
split_shape.Build()
# Step 7: Check if the operation was successful and get the resulting shape
if split_shape.IsDone():
result_shape = split_shape.Shape()
print("Splitting operation completed successfully.")
else:
print("Splitting operation failed.")
# show(result_shape, base_model)
# Step 1: Convert `result_shape` to a CadQuery-compatible Shell or Solid
result_cq_shape = Shape.cast(result_shape)
# Step 2: Add result_cq_shape to base_model
combined_model = base_model.add(result_cq_shape)
# Display the combined model
show(combined_model) I'm unable to attach a STEP file so here is the screenshot. Any advice to point me in the right direction is appreciated! PS: script is generated with lot of chatgpt help |
Beta Was this translation helpful? Give feedback.
-
Hi,
To make the workflow with Ansys as seamless as possible, I need the cad file already prepared to, for example, have the sections of an object with different properties as a seperate face of a solid. This way each face can be selected easily and manipulated individually.
As an example case, consider i have a simple cylinder. Now I want to split its curved surfaces to have two seperate surfaces, while still only having one solid body.
I cannot manage to achieve this and would really appreaciate, if someone has an idea.
Thank you very much!
Beta Was this translation helpful? Give feedback.
All reactions