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.
opBoolean.SUBTRACTION not working?
Federico_Casarini
Member Posts: 9 PRO
Hello! I am trying to create a quick feature script to engrave a text onto an existing object. This is the code I am using:
annotation { "Feature Type Name" : "Tag" }
export const Tag = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Location and Orientation", "Filter" : BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
definition.direction is Query;
annotation { "Name" : "Name", "Default" : "Name" }
definition.myString is string;
annotation { "Name" : "Size[mm]:" }
isReal(definition.textsize, TAG_BOUNDS);
}
{
var sketch_tag = newSketchOnPlane(context, id + "sketch11", {
"sketchPlane" : plane(WORLD_COORD_SYSTEM)
});
skText(sketch_tag, "text1", {
"text" : definition.myString,
"construction": true,
"fontName" : "OpenSans-Regular.ttf",
"firstCorner" : vector(1,0.1) * millimeter ,
"secondCorner" : vector(0.25,definition.textsize) * millimeter
});
skSolve(sketch_tag);
extrude(context, id + "extrude21", {
"entities" : qSketchRegion(id + "sketch11",true),
"endBound" : BoundingType.BLIND,
"depth" : -0.5 * millimeter
});
//delete the sketch
opDeleteBodies(context, id + "deleteBodies", { "entities" : qCreatedBy(id + "sketch11") });
opDeleteBodies(context, id + "deleteBodies", { "entities" : qCreatedBy(id + "sketch11") });
var dir = definition.direction;
var direction = evMateConnector(context, { "mateConnector" : dir });
var start = direction.origin; // xyz
const moveFrom = coordSystem(vector(0, 0, 0) * millimeter, vector(1, 0, 0), vector(0, 0, 1));
const moveTo = coordSystem( start, direction.xAxis, direction.zAxis ); // (origin * units, xAxis, zAxis)
opTransform(context, id + "transform1", {
"bodies" : qCreatedBy(id + "extrude21", EntityType.BODY),
"transform" : toWorld(moveTo) * fromWorld(moveFrom)
});
var target = qSubtraction(qBodyType(qEverything(EntityType.BODY), BodyType.SOLID), qCreatedBy(id + "extrude21", EntityType.BODY));
opBoolean(context, id + "boolean21", {
"tools" : qBodyType(qCreatedBy(id + "extrude21", EntityType.BODY), BodyType.SOLID),
"target" :target,
"operationType" : BooleanOperationType.SUBTRACTION,
"keepTools": false
});
debug(context, target);
debug(context, qBodyType(qCreatedBy(id + "extrude21", EntityType.BODY), BodyType.SOLID));
});
The idea is to create a sketch on the top plane, extrude it, move it onto the selected plane through the mate connector and subtract the text from the original solid. Unfortunately, when I run the code, I get a "cannot resolve entities" error. The tools and target are intersecting each other.
I also added a debug line to check if I was selecting the right solids and seems correct.

Can anyone help me with this?
Thanks!
Fed
The idea is to create a sketch on the top plane, extrude it, move it onto the selected plane through the mate connector and subtract the text from the original solid. Unfortunately, when I run the code, I get a "cannot resolve entities" error. The tools and target are intersecting each other.
I also added a debug line to check if I was selecting the right solids and seems correct.

Can anyone help me with this?
Thanks!
Fed
Tagged:
0
Best Answers
-
Hi @Federico_Casarini
When posting code, it will be easier to read if it is formatted. Please hit this button:
Which will create a code box that you can then paste your code into.
My suspicion is that your code is not working because opBoolean takes "targets" not "target".
Additionally, instead of sketching on the top plane and transforming, just call:var sketch_tag = newSketchOnPlane(context, id + "sketch11", { "sketchPlane" : plane(evMateConnector(context, { "mateConnector" : definition.direction })) });to position your sketch in the correct place from the beginning.Jake Rosenfeld - Modeling Team5 -
Hi @Federico_Casarini
Yup! The definition map is not checked by the language itself. The "Cannot resolve entities" failure you are seeing is actually because at runtime the internal engine looks for "targets" sees that it is `undefined` and reports back that it could not resolve any entities. It would be good if this error was a little more specific, I will look into it.Jake Rosenfeld - Modeling Team5
Answers
-
Hi @Federico_Casarini
When posting code, it will be easier to read if it is formatted. Please hit this button:
Which will create a code box that you can then paste your code into.
My suspicion is that your code is not working because opBoolean takes "targets" not "target".
Additionally, instead of sketching on the top plane and transforming, just call:var sketch_tag = newSketchOnPlane(context, id + "sketch11", { "sketchPlane" : plane(evMateConnector(context, { "mateConnector" : definition.direction })) });to position your sketch in the correct place from the beginning.Jake Rosenfeld - Modeling Team5 -
Hi Jake, thanks for the help! Sorry it's the first time I post on the forum, I will create a code box next time.
You are absolutely right, that worked! I guess that anything that is inside the "quotes" doesn't generate an error in the editor.
Thanks a lot!
Fed0 -
Hi @Federico_Casarini
Yup! The definition map is not checked by the language itself. The "Cannot resolve entities" failure you are seeing is actually because at runtime the internal engine looks for "targets" sees that it is `undefined` and reports back that it could not resolve any entities. It would be good if this error was a little more specific, I will look into it.Jake Rosenfeld - Modeling Team5 -
Yes! If the error at runtime could point at which line went wrong, it will certainly help the newbies like me!
thanks again! 0 -
@Federico_Casarini - it does. If you open the FeatureScript Notices panel (the checkmark in curly braces at the top), it will give you a stack trace as to where the error lies.
Senior Director, Technical Services, EMEA0 -
Hi Neil, thanks for this! I was referring to the actual line that generates the error. Something like "targets is undefined" could be helpful. I appreciate it's the kind of error that you do only once, because now I know what to look for. But it might save some time to new starters.
Thanks for all you help, super appreciated. You guys are doing a great job!
Fed0


