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.

Golden angle pattern (Sunflower)

digitalcarbondigitalcarbon Member Posts: 70 PRO

do we have a way to do the following?

need a start and stop diameter. so pattern is contained between an inner diameter and an outer.

need to tally count. so it will say "3224 holes" for example.

Comments

  • MichaelPascoeMichaelPascoe Member Posts: 2,184 PRO

    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • digitalcarbondigitalcarbon Member Posts: 70 PRO
    edited March 20

    i can import from another cad that can do sunflower.

    but 4247 entities is too much

  • MichaelPascoeMichaelPascoe Member Posts: 2,184 PRO
    edited March 20

    DXF/DWG imports have very small size allowances making only small imports possible. A limitation of Onshape as it is now.

    You don't want to model it in Onshape using patterns?


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • EvanReeseEvanReese Member, Mentor Posts: 2,301 ✭✭✭✭✭
    edited March 20

    My Speaker Pattern feature does fibonacci patterns like this. It doesn't do the starts/stops, but could be modified to do so. It's one of my earliest custom features so the code is kind of embarrassing, but could be a great start. To make it really efficient for that many holes I'd aim to convert it to being a face pattern, not a feature or body pattern.

    Evan Reese
    Independent Onshape Consultant | Industrial Designer
  • digitalcarbondigitalcarbon Member Posts: 70 PRO
    edited March 21

    @EvanReese Thanks. of course I know zip about programing. Except how to cut and paste.

    So i took your "embarrassing" code and dropped it into Grok 3.

    Below is what it sent back:

    FeatureScript 1188;
    import(path : "onshape/std/geometry.fs", version : "1188.0");

    // Icon import (kept for UI consistency)
    icon::import(path : "e8e9c163f08fa68c8a76741c", version : "79a131bdedd16200dcbcb8dd");

    // Default bounds for sunflower pattern
    export const SUNFLOWER_PATTERN_BOUNDS = {
    (meter) : [-500, 0.001, 500],
    (centimeter) : 0.2,
    (millimeter) : 2,
    (inch) : 0.1,
    (foot) : 0.1,
    (yard) : 0.025
    } as LengthBoundSpec;

    export const SUNFLOWER_COUNT_BOUNDS = {
    (unitless) : [1, 25, 1e5]
    } as IntegerBoundSpec;

    // UI Definition for Sunflower Pattern
    annotation { "Feature Type Name" : "Sunflower Pattern", "Icon" : icon::BLOB_DATA }
    export const SunflowerPattern = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
    annotation { "Name" : "Center Point", "Filter" : EntityType.VERTEX && SketchObject.YES || BodyType.MATE_CONNECTOR, "MaxNumberOfPicks" : 1 }
    definition.center is Query;

        annotation { "Name" : "Seed Diameter", "Default" : 2 * millimeter }
        isLength(definition.seedDia, SUNFLOWER_PATTERN_BOUNDS);
    
        annotation { "Name" : "Inside Diameter", "Default" : 5 * millimeter }
        isLength(definition.innerDia, SUNFLOWER_PATTERN_BOUNDS);
    
        annotation { "Name" : "Outside Diameter", "Default" : 50 * millimeter }
        isLength(definition.outerDia, SUNFLOWER_PATTERN_BOUNDS);
    
        annotation { "Name" : "Seed Count", "Default" : 25 }
        isInteger(definition.count, SUNFLOWER_COUNT_BOUNDS);
    
        annotation { "Name" : "Depth", "Default" : 1 * millimeter }
        isLength(definition.depth, SUNFLOWER_PATTERN_BOUNDS);
    
        annotation { "Name" : "Flip Direction", "UIHint" : "OPPOSITE_DIRECTION", "Default" : false }
        definition.flip is boolean;
    }
    {
        // Validate diameters
        if (definition.innerDia >= definition.outerDia)
            throw regenError("Inside Diameter must be less than Outside Diameter", ["innerDia", "outerDia"]);
    
        // Core variables
        const goldenAngle = (3 - sqrt(5)) * PI * radian;
        var normal;
    
        // Determine normal from center point
        try silent
        {
            normal = evOwnerSketchPlane(context, { "entity" : definition.center }).normal;
        }
        try silent
        {
            normal = evMateConnector(context, { "mateConnector" : definition.center }).zAxis;
        }
        if (normal == undefined)
            throw regenError("Invalid Center Point: Must be a sketch vertex or mate connector");
    
        // Create sketch plane
        var origin = evVertexPoint(context, { "vertex" : definition.center });
        var skplane = plane(origin, normal);
        opPlane(context, id + "plane1", { "plane" : skplane });
    
        // Create and solve sketch for seed circle
        var theSketch = newSketchOnPlane(context, id + "sketch1", { "sketchPlane" : skplane });
        skCircle(theSketch, "circle1", {
            "center" : vector(0, 0) * inch,
            "radius" : definition.seedDia / 2
        });
        skSolve(theSketch);
    
        // Extrude the seed circle
        var extrudeNormal = definition.flip ? -normal : normal;
        opExtrude(context, id + "extrude1", {
            "entities" : qSketchRegion(id + "sketch1"),
            "direction" : extrudeNormal,
            "endBound" : BoundingType.BLIND,
            "endDepth" : definition.depth
        });
    
        // Sunflower pattern transforms within inner and outer diameters
        var axis = line(origin, normal);
        var transforms = [];
        var instanceNames = [];
        var innerRadius = definition.innerDia / 2;
        var outerRadius = definition.outerDia / 2;
        var range = outerRadius - innerRadius;
        var step = definition.count > 1 ? range / (definition.count - 1) : 0; // Handle single instance case
    
        for (var i = 0; i < definition.count; i += 1)
        {
            var dist = definition.count > 1 ? innerRadius + (step * i) : innerRadius; // Single instance at inner radius
            var angle = goldenAngle * i;
            transforms = append(transforms, rotationAround(axis, angle) * transform(skplane.x * dist));
            instanceNames = append(instanceNames, "_" ~ toString(i));
        }
    
        // Apply pattern
        var seedBody = qCreatedBy(id + "extrude1", EntityType.BODY);
        opPattern(context, id + "pattern1", {
            "entities" : seedBody,
            "transforms" : transforms,
            "instanceNames" : instanceNames
        });
    
        // Cleanup
        opDeleteBodies(context, id + "deleteBodies", {
            "entities" : qUnion([qCreatedBy(id + "plane1"), qCreatedBy(id + "sketch1")])
        });
    });
    
  • digitalcarbondigitalcarbon Member Posts: 70 PRO

    I asked it to:

    I need you to read and understand the following program called FeatureScript 1188 do the following:Remove anything that is not related to the Fibonacci pattern. I only want to make a Sunflower pattern. Make the program lean, as there might be some sloppiness. Fix any other errors you see.

    Then

    I need to have the ability to set an inside diameter and an outside diameter as the limits of the sunflower pattern. Then I need to be able to set the count of how many of those patterns fall within those inside and outside limits. so can you add those features in?

    Then

    a few more requests and pow!

  • MDesignMDesign Member Posts: 647 ✭✭✭
  • MichaelPascoeMichaelPascoe Member Posts: 2,184 PRO
    edited March 21

    Dope! Wont be long before we have a "Siri" or "Cortana" assistant that can just help us out on the fly like that instead of having to go to a chat window.

    Eventually.. they will start strictly implementing the 3 laws. rip.
    Please remain in doors, this is for your own protection


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
  • EvanReeseEvanReese Member, Mentor Posts: 2,301 ✭✭✭✭✭

    let's goooo!

    Evan Reese
    Independent Onshape Consultant | Industrial Designer
  • digitalcarbondigitalcarbon Member Posts: 70 PRO

    @MichaelPascoe It gets even better…Wait till is connected to my brain and I start to dream..

  • Ste_WilsonSte_Wilson Member Posts: 425 EDU

    @digitalcarbon is that the final script?

    Could you share for posterity?

  • digitalcarbondigitalcarbon Member Posts: 70 PRO

    @Ste_Wilson How do I share?

    I suppose you all could just do the same with your version of Grok 3. (I have SuperGrok)

    Prompts:

    ************************

    I need you to read and understand the following program called FeatureScript 1188 do the following: Remove anything that is not related to the Fibonacci pattern. I only want to make a Sunflower pattern. Make the program lean, as there might be some sloppiness. Fix any other errors you see.

    ************************

    I need to have the ability to set an inside diameter and an outside diameter as the limits of the sunflower pattern. Then I need to be able to set the count of how many of those patterns fall within those inside and outside limits. So can you add those features in?

    ***********************

    Also, this program is for generating a sunflower pattern so can you take out any reference to "speakers" and just use an appropriate name?

    ***********************

    I got the following error "Nonconforming feature function 'SunflowerPattern': precondition analysis failed" "23:14 Speaker Pattern" can you fix it?

    ***********************

    Those are the prompts I used to get the final clean code. Start with @EvanReese Speaker Pattern doc, use his code but add in the prompts I listed above. See what you get.

  • digitalcarbondigitalcarbon Member Posts: 70 PRO

    SuperGrok 3 - Supercharging an average individual. 2025.03.24

Sign In or Register to comment.