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.

Creating plan in Feature Script

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);
        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);    
    });


Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,680
    I believe your error is here:

            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.
    Senior Director, Technical Services, EMEAI
  • louis_rouquette622louis_rouquette622 Member Posts: 5
    Hi,
    Thank you very much for your reactivity.
    I have modify it, but nothing have changed, I still can't see the plan using the debug function.
    Moreover this part of the script was copied from the hexinfill featurescript, and it seems to work quite well.
    If someone have an other idea.
  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,680
    "Limits" already has units of meter, so Origin turns it into meter^2

    Change to:
    var Origin = vector(0 * meter, 0 * meter, bbz1);

    Senior Director, Technical Services, EMEAI
  • Jake_RosenfeldJake_Rosenfeld Moderator, Onshape Employees, Developers Posts: 1,646
    @louis_rouquette622

    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
    Jake Rosenfeld - Modeling Team
  • louis_rouquette622louis_rouquette622 Member Posts: 5
    NeilCooke said:
    "Limits" already has units of meter, so Origin turns it into meter^2

    Change to:
    var Origin = vector(0 * meter, 0 * meter, bbz1);

    Thanks a lot, it was that.


Sign In or Register to comment.