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 plan in Feature Script
louis_rouquette622
Member Posts: 5 ✭
Hello,
I'm a beginner in the utilisation of feature script, and I was trying to create a plane.
But there is an error in my code but i don't understand where.
My code is mainly inspired by hexInfill, because my final objective is quite similar.
I can't visualize the HexPlane using the debug function.
Thanks a lot to everyone who is helping me
My code :
annotation { "Feature Type Name" : "Infill" }
export const hexinfill = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Body", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
definition.body is Query;
annotation { "Name" : "Side" }
isLength(definition.side, LENGTH_BOUNDS);
}
{
// On cherche les contours de l'objet
var Limits is Box3d = evBox3d(context, { "topology" : definition.body });
//var bbx1 = Limits.minCorner[0];
//var bby1 = Limits.minCorner[1];
var bbz1 = Limits.minCorner[2];
//var bbx2 = Limits.maxCorner[0];
//var bby2 = Limits.maxCorner[1];
//var bbz2 = Limits.maxCorner[2];
var Origin = vector([0, 0, bbz1])*meter;
var Normal = vector([0, 0, 1]);
var Xdir = vector([1, 0, 0]);
var HexPlane is Plane = plane(Origin, Normal, Xdir);
export const hexinfill = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Body", "Filter" : EntityType.BODY, "MaxNumberOfPicks" : 1 }
definition.body is Query;
annotation { "Name" : "Side" }
isLength(definition.side, LENGTH_BOUNDS);
}
{
// On cherche les contours de l'objet
var Limits is Box3d = evBox3d(context, { "topology" : definition.body });
//var bbx1 = Limits.minCorner[0];
//var bby1 = Limits.minCorner[1];
var bbz1 = Limits.minCorner[2];
//var bbx2 = Limits.maxCorner[0];
//var bby2 = Limits.maxCorner[1];
//var bbz2 = Limits.maxCorner[2];
var Origin = vector([0, 0, bbz1])*meter;
var Normal = vector([0, 0, 1]);
var Xdir = vector([1, 0, 0]);
var HexPlane is Plane = plane(Origin, Normal, Xdir);
debug(context, HexPlane);
var HexSketch = newSketch(context, id + "sketch1", {
"sketchPlane" : HexPlane
});
skRectangle(HexSketch, "rectangle1", {
"firstCorner" : vector(0, 0) * inch,
"secondCorner" : vector(definition.side, definition.side) * inch
});
skSolve(HexSketch);
});
0
Comments
var Origin = vector([0, 0, bbz1])*meter;
var Normal = vector([0, 0, 1]);
var Xdir = vector([1, 0, 0]);
There should be no square brackets - they indicate an array, not the values of a vector.
Change to:
In the top right corner of your screen there is a button that looks like "{✓}". If you click on that, the FeatureScript console will appear at the bottom of your screen. This will show you where the the code is failing. You can also use the "println" function in FeatureScript to print to this console, which makes debugging easier.
https://cad.onshape.com/FsDoc/library.html#println-
https://cad.onshape.com/documents/f1caabb4228cd8cb993f4d76/w/46e9322cd384d4d5d570985d/e/b5f747c7686bccbb2c96ec2d