- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all,
I'm working on a script that will help me design the fretboard of a guitar. The script is supposed to create a sketch which will contain construction lines indicating the positions of the frets, as well as construction lines showing where the strings will be to help properly visualize everything during the design process. This sketch is to be positioned on a construction plane 2" above the root component's XZ plane. This is my first time using the API, so it's been a bit of a struggle, but I'm finally getting on. I'm able to create the needed construction plane, place a sketch on it, and create sketch elements within it. However, I am having a really strange issue where the coordinate system in the sketch is not aligned with the root component's coordinate system, and I cannot figure out why. Here is my code thus far:
import adsk.core, adsk.fusion, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
#doc = app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType)
#Initializing stuff
design = app.activeProduct
userParams = design.userParameters
units = design.unitsManager
point3d = adsk.core.Point3D
point2d = adsk.core.Point2D
design.unitsManager.defaultLengthUnits = 'in'
rootComp = design.rootComponent
rootSketches = rootComp.sketches
planes = rootComp.constructionPlanes
xyPlane = rootComp.xYConstructionPlane
xzPlane = rootComp.xZConstructionPlane
yzPlane = rootComp.yZConstructionPlane
#Creating a sketch giving an overview of the fretboard
#Create sketch plane 2 inches above the xz plane
planeInput = planes.createInput()
planeInput.setByOffset(xzPlane,adsk.core.ValueInput.createByReal(units.convert(2,'in','cm')))
fretboardOverviewPlane = planes.add(planeInput)
fretboardOverviewPlane.name = 'fretboardOverviewPlane'
#Create sketch on the plane
fretboardOverviewSketch = rootSketches.add(fretboardOverviewPlane)
fretboardOverviewSketch.name = 'fretboardOverviewSketch'
#Getting relevant values from user parameters
scaleLength = userParams.itemByName('scaleLength').value
numberOfFrets = userParams.itemByName('numberOfFrets').value
fretboardWidthAtNut = userParams.itemByName('fretboardWidthAtNut').value
fretboardWidthAtLastFret = userParams.itemByName('fretboardWidthAtLastFret').value
stringSpacingAtNut = userParams.itemByName('stringSpacingAtNut').value
stringSpacingAtBridge = userParams.itemByName('stringSpacingAtBridge').value
fretMarkerLineWidth = userParams.itemByName('fretboardWidthAtLastFret').value*1.5 #make the fret marker lines a bit wider than the fretboard
lines = fretboardOverviewSketch.sketchCurves.sketchLines
lines.addByTwoPoints(point3d.create(-fretMarkerLineWidth/2,0,0),point3d.create(fretMarkerLineWidth/2,0,0))
lines.addByTwoPoints(point3d.create(-fretMarkerLineWidth/2,0,scaleLength),point3d.create(fretMarkerLineWidth/2,0,scaleLength))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
The issue lies in line 48:
lines.addByTwoPoints(point3d.create(-fretMarkerLineWidth/2,0,scaleLength),point3d.create(fretMarkerLineWidth/2,0,scaleLength))
I would expect this to generate a line parallel to the x-axis and offset by scaleLength units in the positive z direction, as pictured below:
However this is not the case. Instead, the code above generates this:
With the line being offset in the positive y direction instead of positive z. Swapping the y and z components of the point3d.create command so it reads
lines.addByTwoPoints(point3d.create(-fretMarkerLineWidth/2,scaleLength,0),point3d.create(fretMarkerLineWidth/2,scaleLength,0))
then offsets the line in the negative z direction, as below:
The only way to achieve what I want is to swap the components and negate them. So the code that produces what I am looking for is
lines.addByTwoPoints(point3d.create(-fretMarkerLineWidth/2,0,-scaleLength),point3d.create(fretMarkerLineWidth/2,0,-scaleLength))
So what gives? How do I make the coordinate systems align?
Solved! Go to Solution.