Mr. Brian Ekins -
I entered this script, and it creates the 2 lines, but it gives an error on the line that creates the midpoint constraint.
Can you test the script I pasted below and see if you get the same error, and if you can tell what the problem is? I tried it on both Mac and Windows and get the same error in both places.

Here is the exact code I am running (made some tweaks to turn it into a full ready-to-run script):
#Author- sample from Fusion API forum by Brian Ekins
#Description-midpoint constraint https://forums.autodesk.com/t5/fusion-360-api-and-scripts/sketchline-midsketchpoint-property/td-p/8453832
import adsk.core, adsk.fusion, adsk.cam, traceback
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
#des = adsk.fusion.Design.cast(app.activeProduct)
#root = des.rootComponent
drawLinesWithMidpointContraint()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def createNewComponent():
# Get the active design.
app = adsk.core.Application.get()
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 drawLinesWithMidpointContraint():
try:
newComp = createNewComponent()
# Create a new sketch.
sketches = newComp.sketches
xyPlane = newComp.xYConstructionPlane
sketch = sketches.add(xyPlane)
pnt1 = adsk.core.Point3D.create(0,0,0)
pnt2 = adsk.core.Point3D.create(8,9,0)
line1 = sketch.sketchCurves.sketchLines.addByTwoPoints(pnt1, pnt2)
pnt3 = adsk.core.Point3D.create(0,5,0)
pnt4 = adsk.core.Point3D.create(4,4,0)
line2 = sketch.sketchCurves.sketchLines.addByTwoPoints(pnt3, pnt4)
sketch.geometryConstraints.addMidPoint(line2.endSketchPoint, line1)
except:
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))