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.
Am I just an retard? or is feature script impossible..
john_mcclary
Member, Developers Posts: 3,936 PRO
So what I have been attempting to do, for the 10th time now... Is create a slot (as shown in the top left corner of the sketch) on each selected point.
This is still my first "from scratch" feature script. but I can never get past the first step... creating a sketch on a plane...
I've learned a dozen other languages without being hung up this early. WTF is wrong with me.. The debug message does not make any sense to me.
every video I watch makes it look so easy and natural. But I end up stuck every time I make something myself.
Can anyone point me to a REAL tutorial? or should I just stop trying right here and save me the anguish...
At this point I just want to SEE the plane i'm creating using opPlane... just as a double check during the creation phase of this script to make sure my input is correct.
What I have been failing to do since day 1 i s:
make a sketch normal to the plane the vertices are on,
Then I want to draw a line,
offset it (slot offset, if that is even available in FS),
then extrude.
It is literally 2 features (as seen on the tree) but I use slots so often I want it to behave just like the "Hole" feature.
I swear I'm going to need therapy before I finish even 1 feature script feature..
FeatureScript 718;
This is still my first "from scratch" feature script. but I can never get past the first step... creating a sketch on a plane...
I've learned a dozen other languages without being hung up this early. WTF is wrong with me.. The debug message does not make any sense to me.
every video I watch makes it look so easy and natural. But I end up stuck every time I make something myself.
Can anyone point me to a REAL tutorial? or should I just stop trying right here and save me the anguish...
At this point I just want to SEE the plane i'm creating using opPlane... just as a double check during the creation phase of this script to make sure my input is correct.
What I have been failing to do since day 1 i s:
make a sketch normal to the plane the vertices are on,
Then I want to draw a line,
offset it (slot offset, if that is even available in FS),
then extrude.
It is literally 2 features (as seen on the tree) but I use slots so often I want it to behave just like the "Hole" feature.
I swear I'm going to need therapy before I finish even 1 feature script feature..
FeatureScript 718;
import(path : "onshape/std/geometry.fs", version : "718.0");
annotation { "Feature Type Name" : "Bolt Slot" }
export const BoltSlot = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
annotation { "Name" : "Sketch Points to place slots", "Filter" : EntityType.VERTEX && SketchObject.YES && ConstructionObject.NO && ModifiableEntityOnly.YES }
definition.points is Query;
annotation { "Name" : "Merge scope",
"Filter" : (EntityType.BODY && BodyType.SOLID && ModifiableEntityOnly.YES) }
definition.scope is Query;
annotation { "Name" : "Direction", "Filter" : EntityType.EDGE, "MaxNumberOfPicks" : 1 }
definition.direction is Query;
annotation { "Name" : "Slot Length" }
isLength(definition.Length, LENGTH_BOUNDS);
}
{
const plane = opPlane(context, id + "plane1", {
"plane" : plane(definition.points[0], vector(0, 0, 1)),
"width" : 6 * inch,
"height" : 6 * inch
});
});
0
Comments
you actually trying to write FS as if you were drawing your slot by yourself. this not the best approach in FS.
// to get a plane of the sketch vertex you need
globalNormal = evOwnerSketchPlane().normal;
// direction of X axis defined by definition.direction
xAxis = evLine(context, {"edge": definition.direction}).direction;
// then start the main loop
var i=0;
for (point in evaluateQuery( definition.points))
{
i+=1;
//define a sketch plane object based on the local point, global normal, and direction of X
//you may need an option to flip direction
//here you construct a plane object
localPlane = plane(point, globalNormal, xAxis);
//start a sketch
sk = newSketchOnPlane(context, id+i+"sk", {"sketchPlane": localPlane});
//the slot profile should be defined by two lines and two arcs in the coordinate system of localPlane, use skLine and skArc for it
//then solve the sketch
skSolve(sk);
//and perform opExtrude, extruded entities may be queried by qSketchRegion(id+i+"sk")
//and finaly delete sketches by opDeleteBodies()
}
1. Have you gone through this: https://cad.onshape.com/FsDoc/tutorials/create-a-slot-feature.html ?
2. What we've found is that FeatureScript has a learning curve different than other languages. It's not the language itself that's the challenge, but that programming CAD is hard and so are the concepts involved. The good news is that after the initial hurdles (queries vs geometry, which you ran into, feature/sketch ids, debugging) it gets easier.
3. In your case, the problem is that definition.points is a query, not an array of vectors. Getting to coordinates (which plane needs) is a two step process -- you have to evaluate the query using evaluateQuery to "shatter" it into many queries, one for each point. And then given a query for a single point, you call evVertexPoint to get the coordinates (I believe Konstantin missed that part)
Hope that helps -- please continue asking questions.
@konstantin_shiriazdanov how come it's not as good to sketch the slot by drawing the center line as we would manually? Does slot offset not exist in FS?
@ilya_baran yea i did the tutorial, and followed
@NeilCooke 's webinar where he makes the Lip feature. But the problem is there is a lot of black magic that he needed to do to get it to work. I mean just to get a tangent edge he took the combination of a like 5 queries. I would have never considered such a 2 steps back 3 steps foreward approach. I think that's my biggest set back.
Like I said. I can copy.. but not create.
Niether offset nor trim, project, fillet and moreover sketch constraints are almost unusable. Sketching via FS is like guiding a submarine, all the lines should be precalculated and defined exactly in place, so one should think twise before making complex sketches with FS.