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 to choose a vector and draw a simple circle in FS?
gary_parkin
Member Posts: 4 ✭
I am building a feature to create a tabbed slot. It's a hole cut through with a rectangle inside it. It mates with an extrusion with a tab on either side. You fit these parts together and give them 1/4 turn and they lock together.
btw, I'm not new to programming. I've been a developer for years now but this live query stuff has me baffled.
I've been playing with this for 3 days now.
Here is what I'm building:
See how the tab fits?
I'll be doing a lot of these so I thought I'd automate it.
Here is a pic of the test:
The problem I am getting is that the Precondition of skCircle failed, so I put the entire thing in a giant if statement.
Maybe this is not the way to do it but on the first time in, and you haven't selected the center point, then it errors out.
My code is as follows: (is there a format option for this forum?)
btw, I'm not new to programming. I've been a developer for years now but this live query stuff has me baffled.
I've been playing with this for 3 days now.
Here is what I'm building:
See how the tab fits?
I'll be doing a lot of these so I thought I'd automate it.
Here is a pic of the test:
The problem I am getting is that the Precondition of skCircle failed, so I put the entire thing in a giant if statement.
Maybe this is not the way to do it but on the first time in, and you haven't selected the center point, then it errors out.
My code is as follows: (is there a format option for this forum?)
<div>annotation { "Feature Type Name" : "Tab Socket" } </div><div>export const myFeature = defineFeature(function(context is Context, id is Id, definition is map) <span style="background-color: transparent; color: inherit; font-size: inherit; font-family: Flama, sans-serif;"> precondition </span><span style="background-color: transparent; color: inherit; font-size: inherit; font-family: Flama, sans-serif;"> {</span></div><div> annotation { "Name" : "Choose face", "Filter" : EntityType.FACE, "MaxNumberOfPicks" : 1 }</div><div> definition.partToCut is Query;</div><div><br></div><div> annotation { "Name" : "Choose center", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }</div><div> definition.centerXY is Query;</div><div><br></div><div> annotation { "Name" : "Hole Radius" }</div><div> isLength(definition.holeRadius, BLEND_BOUNDS);</div><div><br></div><div> // annotation { "Name" : "Tab Height" }</div><div> // isLength(definition.tabHeight, LENGTH_BOUNDS);</div><div><br></div><div> // annotation { "Name" : "Tab Width" }</div><div> // isLength(definition.tabWidth, LENGTH_BOUNDS);</div><div><br> }<br></div><div> {</div><div><br></div><div> // Step 1 - Get the face</div><div> // Step 2 - get the center point</div><div> // step 3 - set up the sketch</div><div> // step 4 draw the circle</div><div> // Circle errors out because of precondition fails #$%@</div><div><br><br></div><div> //debug(context, evaluateQuery(context, definition.centerXY));</div><div><br></div><div> // precondition fails so wait until all is filled in to run</div><div> if (evaluateQuery(context, definition.centerXY) != [])</div><div> {</div><div> println("Got here");</div><div><br></div><div> var centerPoint = evaluateQuery(context, definition.centerXY)[0];</div><div> debug(context, centerPoint);</div><div><br></div><div> //debug(context, "definition.centerXY == undefined");</div><div><br></div><div> var origin = evVertexPoint(context, {</div><div> "vertex" : centerPoint</div><div> });</div><div> debug(context, origin);</div><div><br></div><div> var testSketch = newSketch(context, id + "sketch1", {</div><div> "sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)</div><div> });</div><div><br></div><div> //create a circle</div><div> skCircle(testSketch, "circle1", {</div><div> "center" : centerPoint,</div><div> "radius" : definition.holeRadius</div><div> });</div>
=========================================================
Thanks for any and all help
Thanks for any and all help
0
Best Answer
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646@gary_parkin
I find that the code thing only works if you make the make the code box first, and then paste the code into it. Pasting the code, highlighting it, and then clicking on the code button makes the formatting bad.
Jake Rosenfeld - Modeling Team6
Answers
A couple of more suggestions:
1. You can pass definition.centerXY directly into evVertexPoint -- no need to evaluate the query beforehand
2. Yes, if you want a meaningful error msg if you don't have any selections, you do have to evaluate and check for equality to []
3. The best way to ask code questions on the forum is to make a version of your public document with an issue and post a link. That way we can see the exact code in its entirety, the errors, and can make a copy to experiment with solutions if necessary.
HWM-Water Ltd
I'm working through this and I got the circle to display.
ilya_baran, thanks. I didn't know I could pass that w/o changing it.
I was missing skSolve too.
I'm looking at the hex nut demo here
http://www.cadjunkie.com/featurescript-101/nut
Sketch
There are three steps to creating any sketch in FeatureScript:
Oh, and owen_sparks , using that code formatting seems to append it all in a line. I was going to split it up with carage returns but it's just not worth it. I think a better way was to share a project. At least I think so.I must have done something wrong.
Sorry. I'm really new to feature script.
I find that the code thing only works if you make the make the code box first, and then paste the code into it. Pasting the code, highlighting it, and then clicking on the code button makes the formatting bad.
I can make it work if I use a sketch, but not if I use a part. I've included the TabSocket and 2 test pieces that I wanted it to work on. It seems to work fine if I use a sketch but not using a part. I think it's because it can't find a plane, using the choose part then choose center point. I think this is because the center point on the actual part was created in in the sketch and then after it was extruded, now it's 1mm (extrusion height) below the actual face.
There must be a create plane using a face I'm sure but then I still have the how to select a vertex vector.
Has anyone done thins kind of thing that you might point me?
I've been a C# developer for over 30 years and this is bugging me.
Link
https://cad.onshape.com/documents/b0f08bded8713f461a7a2eab/w/34787ac915a63f3394407bc8/e/5ed5dd6f543e742796d5b613
Edit:
Your feature works fine for the part, your original sketch was just hidden:
Sketches are auto-hidden after they are used by a solid feature (like extrude), you can tell they are hidden because they are greyed out in the feature list. You can toggle their hide/show state with the eye toggle:
If I might make a suggestion though:
I think you may gain some advantage by using implicit mate connectors here, in addition to sketch vertices. Then, if your user does not want to sketch in advance they will not have to make a sketch as a pre-processing step and can just infer a mate connector while they have your feature dialog open. You could change your selection filter for `center` to:
and then evaluate the plane and point like so:
More detain on this: https://forum.onshape.com/discussion/11254/implicit-mate-connectors-in-custom-features