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.
Select entity for extrusion via API
Kyle_Tennison
Member Posts: 6 ✭
I've been working on creating tool that interfaces through the OnShape API.
I followed this tutorial about how to make a Cylinder, and everything went well: https://onshape-public.github.io/docs/api-adv/featureaccess/#create-a-cylinder
In this tutorial, we're shown how to extrude a sketch. However, I would like to extrude a sketch region. I am able to do this in the following featurescript:
I followed this tutorial about how to make a Cylinder, and everything went well: https://onshape-public.github.io/docs/api-adv/featureaccess/#create-a-cylinder
In this tutorial, we're shown how to extrude a sketch. However, I would like to extrude a sketch region. I am able to do this in the following featurescript:
annotation { "Feature Type Name" : "My Feature" }
export const myFeature = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Target Feature ID" }
definition.targetFeatureId is string;
}
{
var target_sketch_id = makeId(definition.targetFeatureId);
var target_sketch_query = qSketchRegion(makeId(definition.targetFeatureId), false);
var origin = vector([0, 0, 0]) * inch;
var contains_origin_query = qContainsPoint(target_sketch_query, origin);
var contains_origin_entity = evaluateQuery(context, contains_origin_query)[0];
print("This entity is the target:");
println(contains_origin_entity);
opExtrude(context, id + "extrude1", {
"entities" : contains_origin_entity,
"direction" : evOwnerSketchPlane(context, {"entity" : contains_origin_entity}).normal,
"endBound" : BoundingType.BLIND,
"endDepth" : 1 * inch
});
});
My project requires me to interface with the default features (i.e., I can't define a custom feature).
I created this extrude manually, and then looked at the GET /partstudios/DWVME/features response; the way the entity gets defined here is:
How would I go about getting a query string like this? Is there an alternative way to specifying a query?
Thank you for your help!
I created this extrude manually, and then looked at the GET /partstudios/DWVME/features response; the way the entity gets defined here is:
{
"btType": "BTMParameterQueryList-148",
"queries": [
{
"btType": "BTMIndividualQuery-138",
"queryStatement": null,
"queryString": "query=qCompressed(1.0,\"&270$eJxlkEFz2yAQhf8MPSbDIkDSUZZwomltJQvpxKcMEjhhOrZUWWnH/77IjpM2PQH7dj/e2y8LQe5f/XhcCQ2MuHCwuzY8v9op9PvKTraAFftfMcfB64yY5q751txs4tXvpzAFfyhYwUq6krolzo/hl3fLsd/FitD23HSchxeWqPeH5kRVNyqOvITD1I/HN3yJqjB1s45CP/jx9HPtFozUrgANcC3J8n4QD7f1xq75M+Pyif4Oo28GnZOfc6oTyBH9VZny9kmtTW022pPDDz91L2cDtdOMks4nWQJbb3niOKStlcJ3YH3rc87AcaTzIhCQYXKJiLyIFTpnQ4ESU8wwxxY7dOhnaNJx5nguhU0tt5Jm1NEWgCVbmdKtgwtUC9JgpTCe/Ri3VlEUZaol+a7QqMczuOxi5it3nZKwG8awn7CLKeu1iXOqNNUVXFwhJO92Ib5EBdEf5G8GYXYIHTL6l+u5qFNSr+4wIqP2AWOfsyO4UwOyBMF/giDLTuTon5NlUap/tT9DProJ\",id);",
"nodeId": "FF2PwXilvxQj32j"
}
],
"nodeId": "9Zv3KmObfJdroJUX",
"parameterId": "entities"
},
How would I go about getting a query string like this? Is there an alternative way to specifying a query?
Thank you for your help!
0
Comments
The simplest, and the one I use most often is to just use the transient ID of the entities.
Each entity is referenced through a BTMIndividualQuery (See below).
So the BTMParameterQueryList queries parameter is an array of BTMIndividualQuery objects, one for each ID.
Here JFV is the id of the sketch region, replace with your entity ID.
The challenge is getting the ID of the region. This could be done in featurescript, or with the API through client messaging
For a featurescript. You can get the transient ID by evaluating the query, and for each element, referencing the transientId property.
Getting the id in a featurescript:
evaluateQuery(context, myQuery)[0].transientId;
BTMIndividual query:
Custom FeatureScript and Onshape Integrated Applications
The JSON format you provided appears to be a different schema than the v6 API. There must've been an update that prevents this from being backwards compatible.
However, I did arrive at a solution using queries. It looks like the key was using a BTMIndividualQuery-138 btType:
I guess that it's possible to squish the featurescript query into one line, then provide it outright for the API to evaluate. I'm still unsure how to provide transient ids to the API, though, that's an issue for another time.
Thank you!
My inputs are generally based on what the GET /features endpoint gives out as comparison.
You could do a transient id with your method:
"queryString": "query = { "queryType" : QueryType.TRANSIENT, "transientId" : mytransientid } as Query;"
Custom FeatureScript and Onshape Integrated Applications
In case anyone in the future is wondering, if you want to query using transient ids, you can still do it using deterministicIds field:
{
]
For anyone who has found this thread in the future (Like I just did),
You can use transient ids in the queryString, its just a small little change from what I was trying.
"queryString": "query = qTransient(\"JHD\");"
The other thing to note is that this only works on certain api versions, so doing /api/partstudios… might not work,
but /api/v6/partstudios does.
Custom FeatureScript and Onshape Integrated Applications