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.
How to import a sketch into a feature script and then in a loop make copies of it along a path.
brad_phelan
Member Posts: 89 ✭✭
Hi there,
I have a sketch in my document. It has 3 variables set
MidThickness
Width
Height
the variables parameterize a cross section profile along a boat hull.
I would like to create a feature script feature that imports the sketch and then in a loop makes copies of it.
I have imported the profile into a feature like so and have tried to change the MidThickness variable
during build. It was just a guess it might work like this but it doesn't. Can anybody how to suggest how
to change the variables in the imported script before build?
I have a sketch in my document. It has 3 variables set
MidThickness
Width
Height
the variables parameterize a cross section profile along a boat hull.
I would like to create a feature script feature that imports the sketch and then in a loop makes copies of it.
I have imported the profile into a feature like so and have tried to change the MidThickness variable
during build. It was just a guess it might work like this but it doesn't. Can anybody how to suggest how
to change the variables in the imported script before build?
FeatureScript 638;
import(path : "onshape/std/geometry.fs", version : "638.0");
Profiles::import(path : "4b6e33509f1da3e4af0ad49f", version : "04aa852bfe127e381c7cf7bd");
annotation { "Feature Type Name" : "Surfboard" }
export const surfboard = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
}
{
// Build a thing in a separate context ( and try to set the "MidThickness" variable ( doesn't work )
var profile is Context = Profiles::build({"#MidThickness":"4in"});
// Delete its construction planes and origin
opDeleteBodies(profile, id + "deleteDefaultGeometry", {
"entities" : qUnion([
qConstructionFilter(qBodyType(qEverything(EntityType.BODY), BodyType.SHEET), ConstructionObject.YES),
qCreatedBy(makeId("Origin"))
])
});
for (var i = 0; i < 3; i += 1)
{
var idI = id + "addProfile" + i;
transform(profile, idI, {
"entities" : qEverything() ,
"transformType" : TransformType.TRANSLATION_3D,
"dx" : 0 * inch,
"dy" : i * inch,
"dz" : 0 * inch,
"makeCopy" : true
});
}
//Add thing's context to the current Part Studio
opMergeContexts(context,id + "merge", {
"contextFrom" : profile
});
});
Tagged:
0
Comments
To to do this you would have to programmatically recreate the sketch (skLine, skArc etc.) using values inputted into the feature (or variables if you really want to, but this seems unnecessary), then put that in a loop to create multiple sketches.
and this outputs
0.050800000000000005 meter
0.15 meter
Result: Regeneration complete
where the first value is the value set in the sketch and the second value is the value set in the importing script. ie: the variable is updated and then is regenerated but the output geometry does not reflect the variable change. The middle diension is still 0.05 meters in the copied profiles.
The original profile looks like
I assumed that variables would be available like a configuration feature for the part. A bit like iLogic in Inventor. However it seems that you can't really create parametric parts yet in onshape. That's a real pity.
I'll come back another time and see if it's possible.
For such a simple profile could you not use my suggestion?
https://cad.onshape.com/documents/d8aab1e0e7ae10038a6830e0/w/9dfdd631d025960813b8f2df/e/621b5be97d38074a1f1546e5
The trick is to fix a point in a sketch (external references other than fix get destroyed by feature patterns) and have the index variable increment itself as part of the pattern.