Need help with python script to make complex line

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
idblum
Posts: 3
Joined: Fri Jan 06, 2017 3:36 pm

Need help with python script to make complex line

Post by idblum »

Hoping someone can help me with this as I am very new to python (started this morning). I want to make a complex polygon however I am getting the dreaded "invalid syntax" error. I know indentation is important but for the life of me I just can't get this code to work. I've tried both elif and else: but I always get the same syntax error on line 36.

Please have mercy on me and help me troubleshoot this stupid code.

Code: Select all

  File "<input>", line 6
    else:	#elif I <= Y <= xmax:
       ^
SyntaxError: invalid syntax

Code: Select all

import FreeCAD, FreeCADGui, Part
import math
from math import cos,tan
doc=App.activeDocument()  

#======== DRAW A FUNCTION =========
# Use it to draw a function described
# by a "equation" [z=F(x)] (Z-X plane)
# The example done here generate a parabol
#
# Change the part inside two comment
# to do your function.
#==================================

#Describe your variables here:
h=3.5
theta=11
pi=3.14159265359
#Describing initial conditions
X=0
Y=0
Z=0
I=h*pi/(4*tan(theta))
xmax=h/(2*tan(theta))+I
#---------------------------
#Choose the number of steps:
Nb=10
Step=1000/Nb

Y=0
for P in range(0,Nb,Step):
    X=0
    Y=Y+Step	#Describe the function (express with Y and YY)(ex: z=Y^2/(4*F))
    if 0 <= Y <= I:
        Z=h*((1-cos((pi*Y)/(2*I))/2)
    else:	#elif I <= Y <= xmax:
        Z=tan(theta)*(Y-I)+h/2

   #---------------------------------------------------------------
name=doc.addObject("Part::Polygon","Polygon")
name.Nodes=P     
doc.recompute()
idblum
Posts: 3
Joined: Fri Jan 06, 2017 3:36 pm

Re: Need help with python script to make complex line

Post by idblum »

Ok so the problem with the original code was not the "elif" at all but rather an extraneous parenthesis in the line above. Sorry to waste everyone's time.

so frustrating that the error was drawing my eye away from the real issue the whole time
Post Reply