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.

Help! Challenge: Fretboard Generation

michael_flynn102michael_flynn102 Member Posts: 2

Hey! I'm trying to generate a guitar fretboard based off of configuration parameters, and I'm having a hard time figuring out the best way to go about it.

The challenge is that I need to essentially perform a function on each instance of a linear pattern to determine the distance to the next instance, instead of setting just one distance between each instance.

So far I have successfully used FeatureScript to generate the distances I need, but I'm not sure the best way to implement these distances, as I would LIKE for the end result to work with any number of frets entered and then generate a fretboard with that many frets. This is complicated by the fact that the face of the fretboard is a drafted curve, so just copying an object in a straight line won't really work as the angles won't be perfect.

I have this feature script to generate the variables I can use to manually put in each fret in the proper location, but ideally I'd like to write FeatureScript to generate all of the frets.

annotation { "Feature Type Name" : "Generate Fret Spacing Variables" }
export const addMyFunctions = defineFeature(function(context is Context, id is Id, definition is map)
    precondition
    {
        annotation { "Name" : "String Length" }
        isLength(definition.stringLength, LENGTH_BOUNDS);
        
        annotation { "Name" : "Fret Count" }
        isInteger(definition.fretCount, POSITIVE_COUNT_BOUNDS);
    }
    {
        var c = definition.stringLength;
        
        for (var i = 1; i <= definition.fretCount; i += 1)
        {
            var p = c;
            c = c / 1.059463;
            setVariable(context, "BL" ~ i, c);
            setVariable(context, "OL" ~ i, p - c);
            setVariable(context, "NL" ~ i, definition.stringLength - c);
        }
        
        setVariable(context, "NeckLength", definition.stringLength - c);
    });

In the above code, the prefixes mean:

  • NL: Nut Length (Distance from top of string to fret)
  • BL: Bridge Length (Distance from bottom of string to fret)
  • OL: Offset Length (Distance from previous fret to this fret)

Here is my project, versioned V0.3 at time of writing: https://cad.onshape.com/documents/39121782acf88719d61983ae/w/4d7fdf89d456b54d1055a07d/e/5162cd4f7ed9efedfdb77ad6

The best idea I currently have is to try to split the neck at the set distances, and then insert a sketch circle at the top / front most position in each chunk and sweep it across the top edge, and then merge all the chunks back together. But I would love some other suggestions.

Thanks in advance!

Comments

  • NeilCookeNeilCooke Moderator, Onshape Employees Posts: 5,831

    I wouldn't use variables at all. Do it all in the feature. You can select (or create) the fretboard and either select a modelled fret or even better, create the fret in the feature then use opPattern to create the others.

    Senior Director, Technical Services, EMEA
  • jelte_steur814jelte_steur814 Member Posts: 385 PRO

    Do you really want to create a feature for this? it could be done with incrementing variables.

    @GregBrown explains well in this video how to.

    for #i, you could use my increment variable feature as well.

    in this case it doesn't make much of a difference, but it would

  • martin_kopplowmartin_kopplow Member Posts: 722 PRO

    I didn't know about this little trick with the iterations before. Great find! I did that manually for a bass build I have under way, but I believe a FS that incorporates the steps would still be a nice thing.

  • MichaelPascoeMichaelPascoe Member Posts: 2,201 PRO
    edited March 27

    Nice feature @jelte_steur814! I had tried to come up with ways to make variable feature patterns easier for users but never quite was able to. This simplifies it really well.


    Learn more about the Gospel of Christ  ( Here )

    CADSharp  -  We make custom features and integrated Onshape apps!   Learn How to FeatureScript Here 🔴
Sign In or Register to comment.