# Equation sketcher script# Demonstrates selecting sketches, inserting a sketch# For use with Alibre Designfrom __future__ import divisionfrom math import sqrtWin = Windows()ScriptName = 'Equation Sketcher'Options = []Options.append([None, WindowsInputTypes.Image, 'EquationSketcher.png', 170])Options.append(['Start point X', WindowsInputTypes.Integer, 0])Options.append(['Start point Y', WindowsInputTypes.Integer, 0])Options.append(['Equation y = ', WindowsInputTypes.String, '0.1*x**2'])Options.append(['Plane', WindowsInputTypes.Plane, None])Options.append(['X Range Start', WindowsInputTypes.Real, 0])Options.append(['X Range End', WindowsInputTypes.Real, 10])Options.append(['Number of points', WindowsInputTypes.Integer, 10])Options.append(['Swap X and Y', WindowsInputTypes.Boolean, False])Values = Win.OptionsDialog(ScriptName, Options, 170)if Values == None: sys.exit()# get the inputsNodeX = Values[1]NodeY = Values[2]Equation = Values[3]Pl = Values[4]StartX = Values[5]EndX = Values[6]NumPoints = Values[7]SwapXY = Values[8]# validateif not Equation: Win.ErrorDialog('No equation entered', ScriptName) sys.exit()if Pl == None: Win.ErrorDialog('No plane selected', ScriptName) sys.exit()if StartX > EndX: Win.ErrorDialog('Start X value is greater than end X value', ScriptName) sys.exit()if NumPoints < 2: Win.ErrorDialog('Invalid number of points', ScriptName) sys.exit()# get the part that defines the sketchPrt = Pl.GetPart()# create a sketch on the planeSk = Prt.AddSketch("Equation Sketch", Pl)print "Loading library..."# we only import this now because it can cause a bit of a delayfrom sympy import *print "Calculating..."# parse equationx = Symbol('x')Eq = sympify(Equation)# work out how much we increase x between pointsStepX = (EndX - StartX) / NumPoints# calculate the pointsPoints = []ValX = StartXfor p in xrange(NumPoints): ValY = Eq.subs(x, ValX) if SwapXY == True: PY = ValX PX = ValY else: PX = ValX PY = ValY Points.extend([float(PX + NodeX), float(PY + NodeY)]) ValX = ValX + StepXprint "Generating sketch..."# generate the bsplineSk.AddBspline(Points, False)