How to using FS to create a quick sphere

tsung_ren_hung
tsung_ren_hung Member Posts: 9 EDU
edited July 2016 in FeatureScript
I tried using FS to quickly create a sphere
but it still not work.
where is the problem?

thanks

https://cad.onshape.com/documents/578f89d3e4b0cdd13940cfe7/w/92807c44d555c353a9b7b4b3/e/d9b77e1c239e6135100324f8


Best Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    edited July 2016 Answer ✓
    Sorry, the documentation is wrong - center should be a query not a length vector. 
    annotation { "Feature Type Name" : "Quick Sphere" }
    export const quickSphere = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Select sphere center", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }
            definition.center is Query;
            
            annotation { "Name" : "Sphere size" }
            isLength(definition.sphereSize, LENGTH_BOUNDS);
        }
        {
         
            sphere(context, id + "sphere1", {
                    "center" : definition.center,
                    "radius" : definition.sphereSize / 2
            });
        });
    If you need to specify a vector, please use fEllipsoid:
        fEllipsoid(context, id + "sphere", {
                "center" : vector(0, 0, 0) * inch,
                "radius" : vector(definition.sphereSize / 2, definition.sphereSize / 2, definition.sphereSize / 2)
        });

    Senior Director, Technical Services, EMEA

Answers

  • NeilCooke
    NeilCooke Moderator, Onshape Employees Posts: 6,116 image
    edited July 2016 Answer ✓
    Sorry, the documentation is wrong - center should be a query not a length vector. 
    annotation { "Feature Type Name" : "Quick Sphere" }
    export const quickSphere = defineFeature(function(context is Context, id is Id, definition is map)
        precondition
        {
            annotation { "Name" : "Select sphere center", "Filter" : EntityType.VERTEX, "MaxNumberOfPicks" : 1 }
            definition.center is Query;
            
            annotation { "Name" : "Sphere size" }
            isLength(definition.sphereSize, LENGTH_BOUNDS);
        }
        {
         
            sphere(context, id + "sphere1", {
                    "center" : definition.center,
                    "radius" : definition.sphereSize / 2
            });
        });
    If you need to specify a vector, please use fEllipsoid:
        fEllipsoid(context, id + "sphere", {
                "center" : vector(0, 0, 0) * inch,
                "radius" : vector(definition.sphereSize / 2, definition.sphereSize / 2, definition.sphereSize / 2)
        });

    Senior Director, Technical Services, EMEA