Python Primer Example error


I am in the course of learning script example from Rhino 5 Python Primer regarding recursion.

I have a function written as below:

def AddArcDir(ptStart, ptEnd, vecDir):
    vecBase = rs.PointSubtract(ptEnd, ptStart)
    if rs.VectorLength(vecBase)==0.0: return
    if rs.IsVectorParallelTo(vecBase, vecDir): return
    vecBase = rs.VectorUnitize(vecBase)
    vecDir = rs.VectorUnitize(vecDir)
    vecBisector = rs.VectorAdd(vecDir, vecBase)
    vecBisector = rs.VectorUnitize(vecBisector)
    dotProd = rs.VectorDotProduct(vecBisector, vecDir)
    midLength = (0.5*rs.Distance(ptStart, ptEnd)/dotProd
    vecBisector = rs.VectorScale(vecBisector,midLength)
    return rs.AddArc3Pt(ptStart, rs.PointAdd(ptStart, vecBisector), ptEnd)

In the line :

  vecBisector = rs.VectorScale(vecBisector,midLength)

I get an error message "SyntaxError: unexpected token ‘vecBisector’ ". Why do I get this message?

Hi, the error happens one line above because the parenthesis is opened but not closed at the end of the line:

midLength = (0.5*rs.Distance(ptStart, ptEnd)/dotProd)


“Unexpected token” errors are almost always about something missing in the line before, often parentheses, sometimes a colon if it’s a conditional or loop…


Thank you all for replies. Everything works now.

When I tried this part of the primer my trees did not really look like they do in the example. The problem was in the last line of that code. If you look at the help file on AddArc3Pt you will find out why :wink:

I did not mind at first that tree looks bit differently, because I thought it was the matter of given parameters. Now, thanks to your advice it works fine. Thanks