there is the code :
import adsk.core, adsk.fusion, traceback
import math
defaultBoltName = 'FretBoard 1'
defaultHeadDiameter = 7
defaultBodyDiameter = 10.4
defaultHeadHeight = 24.5
defaultBodyLength = 24.5
defaultCutAngle = 30.0 * (math.pi / 180)
defaultChamferDistance = 4
defaultFilletRadius = 22
# global set of event handlers to keep them referenced for the duration of the command
handlers = []
app = adsk.core.Application.get()
if app:
ui = app.userInterface
newComp = None
def createNewComponent():
# Get the active design.
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
rootComp = design.rootComponent
allOccs = rootComp.occurrences
newOcc = allOccs.addNewComponent(adsk.core.Matrix3D.create())
return newOcc.component
def run(context):
try:
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
if not design:
ui.messageBox('It is not supported in current workspace, please change to MODEL workspace and try again.')
return
# 1) Create a new sketch.
global newComp
newComp = createNewComponent()
sketches = newComp.sketches
xyPlane = newComp.xYConstructionPlane
xzPlane = newComp.xZConstructionPlane
sketch = sketches.add(xyPlane)
sketch.name='MainFrame'
constraints = sketch.geometricConstraints
p1 = sketch.sketchPoints.add(adsk.core.Point3D.create(-50, 50, 0))
p2 = sketch.sketchPoints.add(adsk.core.Point3D.create(-50, -50, 0))
p3 = sketch.sketchPoints.add(adsk.core.Point3D.create(50, 50, 0))
p4 = sketch.sketchPoints.add(adsk.core.Point3D.create(50, -50, 0))
line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p2)
line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(p3, p4)
line3 = sketch.sketchCurves.sketchLines.addByTwoPoints(p1, p3)
line4 = sketch.sketchCurves.sketchLines.addByTwoPoints(p2, p4)
# prevent this module from being terminate when the script returns, because we are waiting for event handlers to fire
#2) add second sketche
sketch2 = sketches.add(xyPlane)
sketch2.name='Fretboard_Contour'
projections = sketch2.project(line1)
projections = sketch2.project(line2)
projections = sketch2.project(line3)
projectionsP3 = sketch2.project(p3)
projections = sketch2.project(p4)
# projections = sketch2.project(line4)
# project1=projections.item(0)
# project1.isConstruction=True
# lineBottom = sketch2.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(-5, -100, 0), adsk.core.Point3D.create(5,-100, 0))
lastFret= sketch2.sketchCurves.sketchLines.addByTwoPoints(adsk.core.Point3D.create(-5, -100, 0), adsk.core.Point3D.create(5,-100, 0))
coincidentConstraint = constraints.addCoincident(projectionsP3.item(0),lastFret )
# fb_B = sketch2.sketchDimensions.addDistanceDimension(projections.item(0).endSketchPoint, lineBottom.endSketchPoint, adsk.fusion.DimensionOrientations.VerticalDimensionOrientation, adsk.core.Point3D.create(0, 1, 0))
adsk.autoTerminate(False)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
error is produced by the 76th line :
coincidentConstraint = constraints.addCoincident(projectionsP3.item(0),lastFret )