Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.
First time visiting? Here are some places to start:- Looking for a certain topic? Check out the categories filter or use Search (upper right).
- Need support? Ask a question to our Community Support category.
- Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
- Be respectful, on topic and if you see a problem, Flag it.
If you would like to contact our Community Manager personally, feel free to send a private message or an email.
Cut a line in the middle of a face
DavidX
Member Posts: 4 ✭
Hi,
I'm trying to write a script that cuts a line in the middle of a face, but doesn't really know how to draw the right rectangle that matches in all cases
That's the end result
I have the face
I have the 1 of the long edges I should be parallel with
What I have is
- I create the sketch along the face
- I draw a basic rectangle <- that's the missing part
- I extrude it
- And do the boolean operation to cut
My problem is to draw the tiny rectangle that is centered, parallel to the long edge
There is may be a better algorithm altogether
It's probably really simple, but I'm struggling with the different "dimensions" between the sketch and my part
Thanks!
I'm trying to write a script that cuts a line in the middle of a face, but doesn't really know how to draw the right rectangle that matches in all cases
That's the end result
I have the face
I have the 1 of the long edges I should be parallel with
What I have is
- I create the sketch along the face
- I draw a basic rectangle <- that's the missing part
- I extrude it
- And do the boolean operation to cut
My problem is to draw the tiny rectangle that is centered, parallel to the long edge
There is may be a better algorithm altogether
It's probably really simple, but I'm struggling with the different "dimensions" between the sketch and my part
Thanks!
0
Comments
Look into using fCuboid() instead of making a sketch and extruding it (assuming the cut shape is always a box, albeit a long skinny one). It just makes box shapes with two opposite corners as the input. To find the center of the face you could consider using evTangentPlane with the parameters of vector(0.5, 0.5). You might also consider evApproximateCentroid to find the face center, but I'd try the other way first. I'm glossing over some details for brevity, but let me know if you get stumped and I'll see if I can help more later.
Here is an example similar to Evan's idea:
https://cad.onshape.com/documents/7ad38b4e017cb72256e2f06c/w/262b7b49239019d1fd23a59d/e/001fec2a366b90b1574811df
Example code:
There are more efficient ways to write this code, this is simply a quick example.Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴
I started with fCuboid(), it was working great until I added more use cases and realized I could have some rotations...
I'm not sure I can make it work with fCuboid() and the rotations I have?
Meanwhile I came back to a sketch and reused parts of the example. By reading it I found what I was missing, "worldToPlane"! (What I explained pretty badly with different "dimensions", the right term is different "coordinates"! )
By adding more and more use cases, I realized it still doesn't work in some cases. If the side edge isn't flat, it behaves incorrectly. (the red case on my sample bellow) That should be good enough for my project, but would have liked to make it work for others.
Here is the feature I built, and why I asked. I have some beams to cut with complex angles that are joined by pipes. I want to print paper templates to make it simpler.
I found online that wrapping a sheet metal should permit me to flatten the beam. I tried manually, it worked but took me forever, so I decided to script it
https://cad.onshape.com/documents/53f96d606e7de3bf04196565/w/dd247d7d63610eceff56f71a/e/9eb9a66ea4933af4cc492f8d
And here is a real use case (here the seam is too wide, but should be ok)
Now that I have a demo project, let me know if you have ideas on how to make it more reliable (I have no doubt it can be more performant, but yeah, reliability is my main focus for now)