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.
Loft sketches using FeatureScript
fluvio_lobo_fenoglietto
Member Posts: 36 PRO
Hello,
I am trying to build a FeatureScript that will take external data, generate offset sketches and loft them. Each sketch is essentially a profile. However, I am having difficulties creating an array of sketches or profiles to then pass to the opLoft function #N00B.
Could anyone take a look at my code?
I am trying to build a FeatureScript that will take external data, generate offset sketches and loft them. Each sketch is essentially a profile. However, I am having difficulties creating an array of sketches or profiles to then pass to the opLoft function #N00B.
Could anyone take a look at my code?
FeatureScript 701;Thank you!
import(path : "onshape/std/geometry.fs", version : "701.0");
// Imports data as top-level constants, which can be accessed through e.g. PROFILE_1::BLOB_DATA.csvData
import(path : "8349bfa1ec555b8e48de1120", version : "1b5f3508f0dadd9ac02337e1");
annotation { "Feature Type Name" : "import_data" }
export const import_data = defineFeature(function(context is Context, id is Id, definition is map)
precondition
{
// nothing here for this script...
}
{ // Processing input data
var unit = millimeter; // units
var input_array = BLOB_DATA.csvData; // storing csv data into array variable
var input_array_length = size(input_array); // determining length of input data
//println(input_array_length);
var index_array = []; // initialize index array - index of vertex or data point
var x_array = []; // initialize x coordinate array
var y_array = []; // initialize y coordinate array
var z_array = []; // initialize z coordinate array
var vertex = []; // initialize vertex nx3 array
for (var i = 0; i < input_array_length; i += 1) // populating data arrays
{
index_array = append(index_array, input_array[i][0]);
x_array = append(x_array,input_array[i][1]);
y_array = append(y_array,input_array[i][2]);
z_array = append(z_array,input_array[i][3]);
vertex = append(vertex, vector([x_array[i], y_array[i]])*unit); // need to understand their vector structure
} // end of for-loop
var number_of_planes = 5;
var plane_separation = 10;
var k = 0;
var sketches = [];
for (var i = 0; i < number_of_planes; i += 1) // plane/sketch loop - only needs to ad counter to the id of the sketch element
{
sketches = append(sketches, id + i);
var sketch = newSketchOnPlane(context, sketches[i], { // create sketch on a custom plane
"sketchPlane" : plane(vector(0, 0, k) * unit, vector(0, 0, 1))
});
/*
var sketch1 = newSketch(context, id + "sketch1", { // sketch creation
"sketchPlane" : qCreatedBy(makeId("Top"), EntityType.FACE)
});*/
skFitSpline(sketch, "spline1", {
"points" : vertex
});
skSolve(sketch);
k = k + plane_separation;
println(sketches[i]);
}
opLoft(context, id + "loft1", {
"profileSubqueries" : qCreatedBy(sketches, EntityType.BODY),
"derivativeInfo" : [ { "profileIndex" : 0, "vector" : vector(1, 0, 0), "magnitude" : 2., "tangentToPlane" : true}, { "profileIndex" : 1, "matchCurvature" : true, "adjacentFaces" : qFaces ]}
})
});
Tagged:
0
Comments
So, for instance, in your loop you could do:
And in opLoft pass in:
Thank you for your response. This definitely worked. However, I am running into another issue with the lofting feature...
When adding the feature;
I get an error "no viable alternative at input"
Is this error referred to a specific attribute or syntax?
Thank you!
I figured out that the syntax given by the default code sample for the loft feature is off. The "derivativeInfo" attribute ends on "]}" the order should be backwards "}]".
This has not resolved my issue however. I am not sure if my sketches are been evaluated correctly. The only information I get from the notices is;
i @opLoft: LOFT_PROFILE_POINT
Note that I removed the "derivativeInfo" attribute altogether;
One trick when you see a thrown error value like LOFT_PROFILE_POINT is to hover on your custom feature in the feature list to show its tooltip. There you'll find a translated (english) explanation of the error that was thrown. In this case, that's "Point profiles can only exist as first or last profiles".
The issue is that the queries in sketches include point bodies, which the loft feature doesn't deal with. This was my mistake above: I think the fix will be to change qCreatedBy(id + i) to qCreatedBy(id + i, EntityType.FACE) so that you're only lofting between the sketch regions created.
This worked!
Thank you for the tip and the fix.