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.
How would you design an SVG export app/script/tool?
hovis
Member Posts: 7 ✭✭
Step 1: The user selects a number of parallel faces in the Onshape UI
Step 2: ???
Step 3: Profit! (Get an SVG you can take to your CNC workflow of choice)
The standard workflow recommendation for small CNCs is "Export DXF, import into Inkscape, merge the paths, re-export to SVG" but frankly that's a pain in my ass. There has to be a better way.
I've tried and failed to automate this via API and FeatureScript features. Onshape has provided some amazingly rich tools for us to work with, but it's difficult to understand how to use them because of their richness and complexity. I've come close a few times, but I can never find the right path through the forest to get the right curves in the right context to write an SVG file.
Can a FeatureScript/API expert please chime in with a suggested approach to this problem? I'm not asking you to do my work for me, but maybe you can point me in the right direction? Surely there's a "right way" to solve this problem, and a dozen wrong ways. How would the Onshape developer who designed these APIs expect me to approach the problem?
My failures so far:
- I wrote a NodeJS client to the Onshape API that does a great job. I used it to get the feature list, filtered for sketches, and then I was able to find all of the curve segments (BTMSketchCurveSegment) inside the sketch. I'm not sure how to determine which lines/curves are important to me - maybe I could math this out but it definitely feels like the wrong approach.
- I can query all of the faces of all the parts in the PartStudio, and I can filter for only planar faces with a normal of [0,0,1], but this corresponds to the top AND the bottom faces of some parts. I expected the opposing face to have a normal of [0,0,-1] but it seems that's not the case. I can try to select the faces with the highest Z value on the surface origin, but I definitely feel like I'm in the weeds here.
- I found out how to use a FeatureScript and qLoopEdges to get all the edges around a set of faces. This solves the problem from my first attempt, but FeatureScript doesn't support any kind of export.
Questions:
- It looks like there's a way to evaluate FeatureScript in an API call, I can't find any mention of using queries that way though. Can I invoke queries in an API call? If I could, I would simplify the problem and simply select all the boundary edges of all the faces that are parallel to one of the document axes and call it a day.
- I found a reference that you can get the user's selection via API, this would also help me select my edges so that I can generate my SVG. Can someone please show me where this is documented? I don't know the right query to search for it in the documentation.
Step 2: ???
Step 3: Profit! (Get an SVG you can take to your CNC workflow of choice)
The standard workflow recommendation for small CNCs is "Export DXF, import into Inkscape, merge the paths, re-export to SVG" but frankly that's a pain in my ass. There has to be a better way.
I've tried and failed to automate this via API and FeatureScript features. Onshape has provided some amazingly rich tools for us to work with, but it's difficult to understand how to use them because of their richness and complexity. I've come close a few times, but I can never find the right path through the forest to get the right curves in the right context to write an SVG file.
Can a FeatureScript/API expert please chime in with a suggested approach to this problem? I'm not asking you to do my work for me, but maybe you can point me in the right direction? Surely there's a "right way" to solve this problem, and a dozen wrong ways. How would the Onshape developer who designed these APIs expect me to approach the problem?
My failures so far:
- I wrote a NodeJS client to the Onshape API that does a great job. I used it to get the feature list, filtered for sketches, and then I was able to find all of the curve segments (BTMSketchCurveSegment) inside the sketch. I'm not sure how to determine which lines/curves are important to me - maybe I could math this out but it definitely feels like the wrong approach.
- I can query all of the faces of all the parts in the PartStudio, and I can filter for only planar faces with a normal of [0,0,1], but this corresponds to the top AND the bottom faces of some parts. I expected the opposing face to have a normal of [0,0,-1] but it seems that's not the case. I can try to select the faces with the highest Z value on the surface origin, but I definitely feel like I'm in the weeds here.
- I found out how to use a FeatureScript and qLoopEdges to get all the edges around a set of faces. This solves the problem from my first attempt, but FeatureScript doesn't support any kind of export.
Questions:
- It looks like there's a way to evaluate FeatureScript in an API call, I can't find any mention of using queries that way though. Can I invoke queries in an API call? If I could, I would simplify the problem and simply select all the boundary edges of all the faces that are parallel to one of the document axes and call it a day.
- I found a reference that you can get the user's selection via API, this would also help me select my edges so that I can generate my SVG. Can someone please show me where this is documented? I don't know the right query to search for it in the documentation.
Tagged:
0
Comments
Argh! This definitely won't work either. Here's a part with 4 faces normal to the Z axis, but I want to consider three of them. I ACTUALLY just want the edge loops highlighted in green.
https://ibb.co/3zt0QFX
If you wan't to find the edges of the top faces that lie on the same plane, you could do something like this:
This way does not require you to select a face. If you are ok with selecting a face, there are much easier ways to get the edges. Assuming you already have the face you want, you could use this:
Learn more about the Gospel of Christ ( Here )
CADSharp - We make custom features and integrated Onshape apps! Learn How to FeatureScript Here 🔴