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.
feature script - extrude's entities queries
tonvis
Member Posts: 41 ✭✭
I am trying to create a script for springs. In partstudio it works ok with changing variables.
Now working in feature script , I am not able to find the right entity-query
I need three bodies for the later helix with a different pitch.
The extrude1,extrude2 and extrude3 should go on top of each other , but now they can only start from sketch1
I have been studying all examples given in the Forum for weeks but still not solving the problem.
Also "Showcode" is not helping with this major question.
Can someone please help me out ?
Tagged:
0
Best Answers
-
Jake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646Hi @tonvis
I'm not sure I quite understand what you want, but if you want to make the first extrude off of the sketch, then then second extrude stacked on the first extrude, then the third extrude off the second extrude, you could tryvar entity2_query = qCapEntity(id + "Extrude1", CapType.END, EntityType.FACE);;
This is a query for the end cap of the first extrude.
The other thing you could do is keep the profile query the same, but mess with the starting point ("second direction") of the extrude:extrude(context, id + "Extrude2", { "bodyType" : ToolBodyType.SOLID, "operationType" : NewBodyOperationType.NEW, "surfaceOperationType" : NewSurfaceOperationType.NEW, "entities" : entity2_query, "endBound" : BoundingType.BLIND, "oppositeDirection" : true, "depth" : L_veer, "hasSecondDirection" : true, "secondDirectionBound" : SecondDirectionBoundType.BLIND, "secondDirectionDepth" : L2, "secondDirectionOppositeDirection" : // <----- Not actually sure if this should be true or false });
Let us know if that works!Jake Rosenfeld - Modeling Team6 -
owen_sparks Member, Developers Posts: 2,660 PROLikewiseOwen SBusiness Systems and Configuration Controller
HWM-Water Ltd5
Answers
I'm not sure I quite understand what you want, but if you want to make the first extrude off of the sketch, then then second extrude stacked on the first extrude, then the third extrude off the second extrude, you could try
This is a query for the end cap of the first extrude.
The other thing you could do is keep the profile query the same, but mess with the starting point ("second direction") of the extrude:
Let us know if that works!
annotation { "Feature Name" : "Extrude 2" }
Unfortunately, even if they were not compressed, the queries that you get when you interact with the Onshape ui are nothing like the ones that you use when programming in FeatureScript. We use a number of different tricks to make downstream feature robust to upstream changes, and this ends up making ui queries pretty complicated. The `show code` panel is pretty good for seeing what the inputs to a feature look like in FeatureScript code, but for some good examples of human-readable code you could take a look through any of these public custom features:
https://www.onshape.com/features/custom-features
Or even take a look through all of the code for the built-in features in the toolbar:
https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/1609b2014b90745ff149a187
* see:https://cad.onshape.com/documents/aaf33b36515d458f14979723/w/38ba0931c4383130ad547336/e/92d15b1c456833375df278f5
* Supprisingly - using reverse engineering queries from Showcode are not giving errors , but also not solving the answer.
Questions ? sweptface1_query , plane_query, centersnap_query, pierce_query, edge_query?
Here are a couple extra resources to help you:
https://cad.onshape.com/FsDoc/library.html#qNothing - standard library documentation of all the types of queries you can use
https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/9fde5dffaf8d4e4c99aaa22c - source code of the file where all the queries are defined
For sweptface1_query, try using qNonCapEntity:
https://cad.onshape.com/FsDoc/library.html#qNonCapEntity-Id-EntityType
If you go and take a look at the precondition of helix, you can see which variables are required in the map and which aren't:
https://cad.onshape.com/documents/12312312345abcabcabcdeff/w/a855e4161c814f2e9ab3698a/e/a80a05e9b600481ba245f9b3
In this case, it looks like you want to be using TURNS rather than TURNS_PITCH as TURNS takes the "entities" parameter and TURNS_PITCH takes the "edges" parameter. It is worth noting that the "show code" panel will fill in every possible input to the feature, even if those inputs aren't necessarily required. By reading the source code or documentation of a FeatureScript function, you can see which inputs are required and which can be left out completely.
Feel free to continue along the current path you are going down, but if I might make a suggestion: you can skip the three initial extrudes if you use "opHelix" rather than "helix":
https://cad.onshape.com/FsDoc/library.html#opHelix-Context-Id-map
In general, we recommend that FeatureScript users use "op" functions when possible, as they generally take simple mathematical inputs rather than geometric ones. Onshape toolbar features (such as "helix") are somewhat more unwieldily to call because they are meant to take geometric selections from the user which are somewhat harder to manage from inside FeatureScript. In general, Onshape features (extrude(...), revolve(...), draft(...)) have corresponding, easier to use, documented internal operations (opExtrude(...), opRevolve(...), opDraft(...)).
By using opHelix directly you can skip the creation of any reference geometry, and define exactly the three helices you want to create.
As far as the rest of those queries go, I would avoid writing sketch code in the way that you have written it. When you are writing sketch code in FS, you do not need to use constrains or initial guesses. All the sketching calls will allow you to create your desired geometry directly:
https://cad.onshape.com/FsDoc/library.html#skPoint-Sketch-string-map
One additional suggestion, it seems like you're following the pattern:
qUnion is meant to combine an array of queries into a single query. Since `query` already is a single query, you could just provide it directly:
In a related vein, "qUnion([])" is functionally equivalent to "qNothing()", and in most cases where you provide qNothing, you can probably get away with not passing that parameter at all.
Sorry if this answer was less helpful than I intended. Feel free to respond with what you are still confused about, or with any further questions.
Another resource for you. Here is our FeatureScript tutorial:
https://cad.onshape.com/FsDoc/tutorials/create-a-slot-feature.html
read-only fillable UI parameters are something we've been thinking about internally, but don't really exist right now. I'm not sure if this is sufficient for you but you could do either of the following:
- Print out the relevant information using println(). This information will be displayed in the FS console, which is available by hitting the "{✓}" button in the top right corner of your document.
- Change the name of the part you create with setProperty(). You can change the name to anything you want, such as "14mm long 3mm wide spring" or something descriptive like that.
If you really want to, you can create editing logic that backfills parameters to whatever value you want, but its pretty complicated, and the user will be able to edit those fields. I can give an example of a feature that does this if you're interested in going down that path.See next post!
https://cad.onshape.com/documents/94dd7974241246afd953f6ee/w/14d3c2c7cd26df7a859166f7/e/8900f84e910871c575ede68a
Sorry for the confusion. I did a strikethrough of my first post because read-only fillable UI parameters are totally possible! I just didn't realize we had already pushed that functionality. My second post is an example of how to make one!
I made a copy of your doc and tried out your feature, it looks like it's working fine now! Are you still experiencing this issue?
{ // isCreating is required in the function definition for edit logic to work when editing an existing feature
if (oldDefinition.effectiv_windings != definition.effectiv_windings )
{
definition.l_Tot = definition.effectiv_windings * definition.pitch + (2 * definition.pre_windings * definition.wire_dia);
Glad to have you as part of the community.
HWM-Water Ltd