Welcome to the Onshape forum! Ask questions and join in the discussions about everything Onshape.

First time visiting? Here are some places to start:

  1. Looking for a certain topic? Check out the categories filter or use Search (upper right).
  2. Need support? Ask a question to our Community Support category.
  3. Please submit support tickets for bugs but you can request improvements in the Product Feedback category.
  4. 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

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?

FeatureScript 701;
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 ]}
        })  
       
    });
Thank you!


Comments

  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 423
    profileSubqueries should be an array of queries (one for each profile), not a single query for everything.

    So, for instance, in your loop you could do:
    sketches = append(sketches, qCreatedBy(id + i));

    And in opLoft pass in:
                    "profileSubqueries" : sketches,
  • fluvio_lobo_fenogliettofluvio_lobo_fenoglietto Member Posts: 15 EDU
    @kevin_o_toole_1

    Thank you for your response. This definitely worked. However, I am running into another issue with the lofting feature...

    When adding the feature;

    opLoft(context, id + "loft1", {
                    "profileSubqueries" : sketches,
                    "derivativeInfo" : [ { "profileIndex" : 0, "vector" : vector(1, 0, 0), "magnitude" : 2., "tangentToPlane" : true}, { "profileIndex" : 1, "matchCurvature" : true, "adjacentFaces" : qFaces ]}
            });
     
    I get an error "no viable alternative at input"
    Is this error referred to a specific attribute or syntax?

    Thank you!
  • fluvio_lobo_fenogliettofluvio_lobo_fenoglietto Member Posts: 15 EDU
    @kevin_o_toole_1

    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 "}]".
    opLoft(context, id + "loft1", {
                    "profileSubqueries" : profileSubqueries,
                    "derivativeInfo" : [ { "profileIndex" : 0, "vector" : vector(1, 0, 0), "magnitude" : 2., "tangentToPlane" : true}, { "profileIndex" : 1, "matchCurvature" : true, "adjacentFaces" : qFaces }]
            });
    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;
    opLoft(context, id + "loft1", {
                    "profileSubqueries" : sketches,
            });


  • kevin_o_toole_1kevin_o_toole_1 Onshape Employees, Developers, HDM Posts: 423
    edited October 2017
    @fluvio_lobo_fenoglietto
    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.
  • fluvio_lobo_fenogliettofluvio_lobo_fenoglietto Member Posts: 15 EDU
    @kevin_o_toole_1

    This worked!
    Thank you for the tip and the fix.
Sign In or Register to comment.