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.
Creating acircular pattern in featureScript
wayne_jayes
Member Posts: 13 ✭✭
Would someone be kind enough to look at the script in this document
https://cad.onshape.com/documents/623b04759dbfa9159178fe48/w/3f75f7adc024168001e48971/e/ebff95d2dd43547b3b99a055
and point me in the right direction to fix the circularPattern. I am trying to make a flange for joining sections of pipe
https://cad.onshape.com/documents/623b04759dbfa9159178fe48/w/3f75f7adc024168001e48971/e/ebff95d2dd43547b3b99a055
and point me in the right direction to fix the circularPattern. I am trying to make a flange for joining sections of pipe
Tagged:
0
Best Answers
-
The problem (as of 2:28 EST) was the ids -- you added the loop counter into the id on one of the features, but not the other ones in the loop. And the (currently harder to diagnose) other problem is that you added the counter after the string rather than before, which would cause breakage because if the id sequence is id+"cylinder3"+1, id+"transform1"+1,... id+"cylinder3"+2,... we have to "reopen" id+"cylinder3" after it's been closed. So the code for the loop body that works (also the queries need the loop counter in the id) is:
fCylinder(context, id + i + "cylinder3", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.HoleDia }); opTransform(context, id + i + "transform1", { "bodies" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "transform" : transform(vector(cos(i*180*degree/definition.NumHoles), sin(i*180*degree/definition.NumHoles), 0) * definition.PCD/2) }); booleanBodies( context, id + i + "boolean2", { "tools" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION });Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5 -
There is just a mistake in the transform vector (180 instead of 360 degrees)

annotation { "Feature Type Name" : "Flange" } export const myFlange = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type annotation { "Name" : "Outside Diameter" } isLength(definition.OD, LENGTH_BOUNDS); annotation { "Name" : "PCD" } isLength(definition.PCD, LENGTH_BOUNDS); annotation { "Name" : "Internal Diameter" } isLength(definition.ID, LENGTH_BOUNDS); annotation { "Name" : "Hole Diameter" } isLength(definition.HoleDia, LENGTH_BOUNDS); annotation { "Name" : "Flange Thickness" } isLength(definition.THK, LENGTH_BOUNDS); annotation { "Name" : "No of Holes" } isInteger(definition.NumHoles, POSITIVE_COUNT_BOUNDS); } { fCylinder(context, id + "cylinder1", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.OD }); fCylinder(context, id + "cylinder2", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.ID }); booleanBodies(context, id + "boolean1", { "tools" : qCreatedBy(id + "cylinder2", EntityType.BODY), "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION }); for (var i = 0; i < definition.NumHoles; i += 1) { fCylinder(context, id + i + "cylinder3", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.HoleDia }); opTransform(context, id + i + "transform1", { "bodies" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "transform" : transform(vector(cos(i * 360 * degree / definition.NumHoles), sin(i * 360 * degree / definition.NumHoles), 0) * definition.PCD / 2) }); booleanBodies(context, id + i + "boolean2", { "tools" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION }); } });And it works
1
Answers
-
Looks like you capitalized a couple of the parameters: "Angle" should be "angle" and "InstanceCount" should be "instanceCount". The query for "axis" also needs a cylindrical face, rather than the cylinder body. There may be other issues I can't see, but that's my first glance.
For what you are trying to do, a circular pattern is one possibility, but it might be easier to just put your cylinder, transform, and boolean into a for loop.Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc0 -
Hi Ilya, thanks for the pointers, unfortunately I still need some further help, I implemented your suggestions regarding "angle", "instanceCount", and the cylindrical face, but the problem was not solved. I tried the for loop, but again my knowledge of the onshape coding is not up to the task. I'm battling to find the right help in the language reference for FeatureScript. I am a compentant php coder, perhaps there are some example FeatureScript code fragments I could use as an example to learn from. Thanks
0 -
The problem (as of 2:28 EST) was the ids -- you added the loop counter into the id on one of the features, but not the other ones in the loop. And the (currently harder to diagnose) other problem is that you added the counter after the string rather than before, which would cause breakage because if the id sequence is id+"cylinder3"+1, id+"transform1"+1,... id+"cylinder3"+2,... we have to "reopen" id+"cylinder3" after it's been closed. So the code for the loop body that works (also the queries need the loop counter in the id) is:
fCylinder(context, id + i + "cylinder3", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.HoleDia }); opTransform(context, id + i + "transform1", { "bodies" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "transform" : transform(vector(cos(i*180*degree/definition.NumHoles), sin(i*180*degree/definition.NumHoles), 0) * definition.PCD/2) }); booleanBodies( context, id + i + "boolean2", { "tools" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION });Ilya Baran \ VP, Architecture and FeatureScript \ Onshape Inc5 -
There is just a mistake in the transform vector (180 instead of 360 degrees)

annotation { "Feature Type Name" : "Flange" } export const myFlange = defineFeature(function(context is Context, id is Id, definition is map) precondition { // Define the parameters of the feature type annotation { "Name" : "Outside Diameter" } isLength(definition.OD, LENGTH_BOUNDS); annotation { "Name" : "PCD" } isLength(definition.PCD, LENGTH_BOUNDS); annotation { "Name" : "Internal Diameter" } isLength(definition.ID, LENGTH_BOUNDS); annotation { "Name" : "Hole Diameter" } isLength(definition.HoleDia, LENGTH_BOUNDS); annotation { "Name" : "Flange Thickness" } isLength(definition.THK, LENGTH_BOUNDS); annotation { "Name" : "No of Holes" } isInteger(definition.NumHoles, POSITIVE_COUNT_BOUNDS); } { fCylinder(context, id + "cylinder1", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.OD }); fCylinder(context, id + "cylinder2", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.ID }); booleanBodies(context, id + "boolean1", { "tools" : qCreatedBy(id + "cylinder2", EntityType.BODY), "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION }); for (var i = 0; i < definition.NumHoles; i += 1) { fCylinder(context, id + i + "cylinder3", { "bottomCenter" : vector(0, 0, 0) * millimeter, "topCenter" : vector(0, 0, 1) * definition.THK, "radius" : 0.5 * definition.HoleDia }); opTransform(context, id + i + "transform1", { "bodies" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "transform" : transform(vector(cos(i * 360 * degree / definition.NumHoles), sin(i * 360 * degree / definition.NumHoles), 0) * definition.PCD / 2) }); booleanBodies(context, id + i + "boolean2", { "tools" : qCreatedBy(id + i + "cylinder3", EntityType.BODY), "targets" : qCreatedBy(id + "cylinder1", EntityType.BODY), "operationType" : BooleanOperationType.SUBTRACTION }); } });And it works
1 -
Thank you for your help. just what I needed to get me going.
0


