Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Guitar Creation Add-in [WIP] - Help desired!

5 REPLIES 5
Reply
Message 1 of 6
BradAndersonJr
575 Views, 5 Replies

Guitar Creation Add-in [WIP] - Help desired!

Hey everyone!

 

I'm just as new to Fusion 360 as I am "writing" python code.  My 3D background is in film/game oriented creation so CAD is a much different approach and I'm doing my best do adjust! 

 

Ideally I'd love to create an add-in which would be very similar in nature to the Bolt and Spur Gear add-ins already provided as samples.  Its purpose would be to construct the 'core' of the guitar based on user inputted parameters in a GUI.  I have an incredible amount of questions, but am trying my best to figure as much out on my own as I can.  I'm not terribly sure where to start in defining my goals, and I fear I'd just become a rambling fool...  Here's what I have so far!

 

import adsk.core, adsk.fusion, traceback, math
from math import sqrt

#xN = Width at nut
#xB = Width at end #yN = Radius
#yB = Radius at end #L = Length of fretboard xN = 1.75 yN = 10 xB = 2 yB = 16 L = 18.75*2.54 aN = yN-sqrt((yN**2-(xN/2)**2)) aB = yB-sqrt((yB**2-(xB/2)**2)) firstPtN = adsk.core.Point3D.create((xN/-2)*2.54, 0, -L) secondPtN = adsk.core.Point3D.create((xN/2)*2.54, 0, -L) centerPtN = adsk.core.Point3D.create(0, aN*2.54, -L) firstPtB = adsk.core.Point3D.create((xB/-2)*2.54, 0, 0) secondPtB = adsk.core.Point3D.create((xB/2)*2.54, 0, 0) centerPtB = adsk.core.Point3D.create(0, aB*2.54, 0) def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface design = app.activeProduct # Get the root component of the active design. rootComp = design.rootComponent # Create a new sketch on the xy plane. sketches = rootComp.sketches xyPlane = rootComp.xYConstructionPlane sketch = sketches.add(xyPlane) # Create fretboard arcs sketchArcs = sketch.sketchCurves.sketchArcs arc1 = sketchArcs.addByThreePoints(firstPtN, centerPtN, secondPtN) arc2 = sketchArcs.addByThreePoints(firstPtB, centerPtB, secondPtB) except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Most of this has been butchered and chopped from the other samples.  It works, but it sure isn't pretty or orthodox.  Basically my first objective is to be able to create a fretboard based on user input.  So far I was able to figure out how to create 3-point arcs for proper fretboard radii and establish the length.  The next step would be to loft the two curves together, and I've found I can only do that in Patch mode, and haven't a clue how to write that in python.

 

Again I'm pretty poor at writing code/script so please bare with me and my amateur attempts, but I have to start somewhere! 

 

I guess my initial questions are:

 

- How do I clean up the code to make it more orthodox?

- Am I able to set the units to inches without having to manually convert them?

- How do I loft the two curves together?

 

My next struggles will be to add a 4-point, symmetric spline to each arc to define the curve of the neck underneath.  These will likely be just to establish the surface and be manually adjusted after creation. 

 

Once I'm able to tackle basic neck construction I hope to incorporate the ability define the scale length of the guitar and then the number of frets. 

 

I hope this made sense, if not I'll do my best to further explain my intentions!

 

Thank you!

- Brad

 

 

 

 

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
Tags (2)
5 REPLIES 5
Message 2 of 6

Hey everyone!

 

So I had a chance to tweak it a tad more and solve one of my problems.  I incorporated a 3-point curve to the bottom of the arcs to give me a full 'cross section' of the neck now.  Now having two closed curves I found I'm able to loft them together in 'Model' so kindly disregard my 'Patch' comment. =]  This being stated, I'm now lost at how to identify arc1 and curve1 as a single profile to loft through python.  I found the Loft Sample and have been trying to wrap my head around what's going on.  Here's the updated script.

 

import adsk.core, adsk.fusion, traceback, math
from math import sqrt

#x = Width at nut
#y = Radius
#L = Length of fretboard

xN = 1.75
yN = 10
xB = 2
yB = 16
L = 18.75*2.54

#Equation for defining the proper radii
aN = yN-sqrt((yN**2-(xN/2)**2))
aB = yB-sqrt((yB**2-(xB/2)**2))

firstPtN = adsk.core.Point3D.create((xN/-2)*2.54, 0, -L)
secondPtN = adsk.core.Point3D.create((xN/2)*2.54, 0, -L)
centerPtN = adsk.core.Point3D.create(0, aN*2.54, -L)
firstPtB = adsk.core.Point3D.create((xB/-2)*2.54, 0, 0)
secondPtB = adsk.core.Point3D.create((xB/2)*2.54, 0, 0)
centerPtB = adsk.core.Point3D.create(0, aB*2.54, 0)

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        design = app.activeProduct

        # Get the root component of the active design.
        rootComp = design.rootComponent

        # Create a new sketch on the xy plane.
        sketches = rootComp.sketches
        xyPlane = rootComp.xYConstructionPlane
        sketch = sketches.add(xyPlane)

        # Create sketch
        sketchArcs = sketch.sketchCurves.sketchArcs
        arc1 = sketchArcs.addByThreePoints(firstPtN, centerPtN, secondPtN)
        arc2 = sketchArcs.addByThreePoints(firstPtB, centerPtB, secondPtB)
        
         # Create an object collection for the points.
        points1 = adsk.core.ObjectCollection.create()
        points2 = adsk.core.ObjectCollection.create()

        # Define the points the spline with fit through.
        points1.add(firstPtB)
        points1.add(adsk.core.Point3D.create(0, -1.25, 0))
        points1.add(secondPtB)
        points2.add(firstPtN)
        points2.add(adsk.core.Point3D.create(0, -1.25, -L))
        points2.add(secondPtN)

        # Create the spline.
        curve1 = sketch.sketchCurves.sketchFittedSplines.add(points1)
        curve2 = sketch.sketchCurves.sketchFittedSplines.add(points2)

#        profile1 = curve1.profiles.item(0)
#        profile2 = curve2.profiles.item(0)

#        # Create loft feature input
#        loftFeats = rootComp.features.loftFeatures
#        loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
#        loftSectionsObj = loftInput.loftSections
#        loftSectionsObj.add(profile1)
#        loftSectionsObj.add(profile2)
#        loftInput.isSolid = False
#
#        # Create loft feature
#        loftFeats.add(loftInput)

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Also, once I've lofted the two profiles I'd like to extrude the top planar face along the Y axis but can't seem to get it to function properly.

Well onward and upward!  Thanks again for any help!

 

- Brad

 

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
Message 3 of 6

Hey everyone!

 

Well another day at plugging away at it!  I solved the loft issue and now properly create the base of the neck to the appropriate dimensions.  I realized since the top of the fretboard is a compound curved surface the extrusion feature wouldn't work.  I just found a different way (and apparently more simple!) approach to that problem.  My intention isn't to script a complete guitar neck, but the major components that can later be adjusted and manually customized, such as the neck profile, and blend into the body.  Regardless, it's getting to where I want it, yay!

 

I added the equation for the spacing of the frets and the desired values appear in the Spyder console, which is a good thing!  My next challenge is transferring those results into lines down the surface of the fretboard.  This is where I'm really lost!  Ideally I'd also like to find a way so that the frets don't extend past the boundaries of neck.  This isn't probably terribly important though, as long as their in the right spot I'm sure the CAM operation would still work.

 

It's still very much a work-in-progress and I'm trying to clean it up as I go.

 

import adsk.core, adsk.fusion, traceback, math
from math import sqrt

#x = Width at nut
#y = Radius
#d = Depth of neck
#L = Length of fretboard
#f = Number of frets

xN = 1.7
yN = 10
xB = 2.2
yB = 16
dN = 0.86
dB = 0.94
L = 18.75
f = 24
scaleLength = 25.5

#Equation for defining the proper radii
aN = yN-sqrt((yN**2-(xN/2)**2))
aB = yB-sqrt((yB**2-(xB/2)**2))

firstPtN = adsk.core.Point3D.create((xN/-2)*2.54, 0, 0)
secondPtN = adsk.core.Point3D.create((xN/2)*2.54, 0, 0)
centerPtN = adsk.core.Point3D.create(0, aN*2.54, 0)
firstPtB = adsk.core.Point3D.create((xB/-2)*2.54, 0, 0)
secondPtB = adsk.core.Point3D.create((xB/2)*2.54, 0, 0)
centerPtB = adsk.core.Point3D.create(0, aB*2.54, 0)

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        # Create a document
        doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
        
        product = app.activeProduct
        design = adsk.fusion.Design.cast(product)
        rootComp = design.rootComponent

        #create neck profile 1
        sketchesObj = rootComp.sketches
        sketch1 = sketchesObj.add(rootComp.xYConstructionPlane)
        sketchArcsObj1 = sketch1.sketchCurves.sketchArcs
        sketchArcsObj1.addByThreePoints(firstPtN, centerPtN, secondPtN)
        points1 = adsk.core.ObjectCollection.create()
        points1.add(firstPtN)
        points1.add(adsk.core.Point3D.create(0, ((-dN*2.54)+(aN*2.54)), 0))
        points1.add(secondPtN)
        sketch1.sketchCurves.sketchFittedSplines.add(points1)
        profile1 = sketch1.profiles.item(0) 

        #create neck profile 2
        ctorPlanes = rootComp.constructionPlanes
        ctorPlaneInput1 = ctorPlanes.createInput()
        offset = adsk.core.ValueInput.createByString("18.75 in")
        ctorPlaneInput1.setByOffset(rootComp.xYConstructionPlane, offset)
        ctorPlane1 = ctorPlanes.add(ctorPlaneInput1)
        sketch2 = sketchesObj.add(ctorPlane1)
        sketchArcsObj2 = sketch2.sketchCurves.sketchArcs
        sketchArcsObj2.addByThreePoints(firstPtB, centerPtB, secondPtB)
        points2 = adsk.core.ObjectCollection.create()
        points2.add(firstPtB)
        points2.add(adsk.core.Point3D.create(0, ((-dB*2.54)+(aB*2.54)), 0))
        points2.add(secondPtB)
        sketch2.sketchCurves.sketchFittedSplines.add(points2)
        profile2 = sketch2.profiles.item(0) 
        
        # Create loft feature input
        loftFeats = rootComp.features.loftFeatures
        loftInput = loftFeats.createInput(adsk.fusion.FeatureOperations.NewBodyFeatureOperation)
        loftSectionsObj = loftInput.loftSections
        loftSectionsObj.add(profile1)
        loftSectionsObj.add(profile2)
        loftInput.isSolid = False

        # Create loft feature
        loftFeats.add(loftInput)
        
        # Calculate Frets
        for fretNumber in range(1,f+1):
            fretDistance = scaleLength-(scaleLength/(2**(fretNumber/12.0)))
            print('%2d %5.3f'%(fretNumber, fretDistance))
            print('\n')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Thanks again!

- Brad

 

 

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
Message 4 of 6
ekinsb
in reply to: BradAndersonJr

Here's my advice.  Go through the process manually.  It much easier to do a lot of trial and error in the user-interface to find out what works and what doesn't to build the geometry you want.  Once you have the workflow figured out then you can start writing code to automate it.  By the way, great job so far.  Having a project your passionate about is the best way to learn something new.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 6

Thanks Brian!

 

I've definitely been toying with manual operations to get a feel for how to properly 'chain' it all together.  Again with a mixture of looking at other scripts, trial and error and a whole lot of luck I've been able to achieve most of my goal so far.  I may be at the end of the line for the neck operation via the API, I haven't been able to find anything on Project to Surface for the frets.  This is fine if that becomes a manual operation, I wasn't planning on being able to script a complete automation for guitar creation.  But, if there is a way to do it I'd love to know!

 

The next step will be adding the ability to define the overall dimensions of the guitar, body, headstock, pick up placement, nut and bridge placement which I don't expect to be too challenging.  Mostly this will just be adding construction lines to establish boundaries to work within for.  After that will be the daunting task of cleaning up the script, and then make it a GUI, I plan to study the Spur Gear script heavily to figure all that out.

 

Here's where I'm at!  Everything aside from the texture application, fillets along the length of the neck (just for fun!) and the actual projected frets to the surface has been automated with the python script!

 

guitarNeck003.jpg

 

 Thanks!

- Brad

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group
Tags (2)
Message 6 of 6

Oops,

 

Also the profile of the neck back curvature is a manual operation too, the script provides spline placement but requires the point handles to be toyed with to achieve the desired shape.  If thank makes sense...

 

Thanks!

Brad Anderson Jr
Fusion 360 Hobbyist
Fusion 360 Luthiers Facebook Group

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report