What's new

Need SYNTAX help with script

oldfox

Alibre Super User
What is the proper syntax for:

OppositeSideLen = ((AC - AF)/2) * tan(rad)

Info: rad is a number in radians

Error returned:

IronPython.Runtime.UnboundNameException: name 'tan' is not defined
at IronPython.Runtime.Operations.PythonOps.GetVariable(CodeContext context, String name, Boolean isGlobal, Boolean lightThrow)
at IronPython.Compiler.LookupGlobalInstruction.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope)
at AlibreScript.UI.IronTextBoxControl.#ijb(Object #9A)

Thank you.
 

idslk

Alibre Super User
Hello @oldfox,

you have to "import" the function in your script before use.
You can do this for only tangens like:
from math import tan
or
from math import *
for all functions available in module math.
So insert one on the lines above (commonly the line with the *, if you like to use sin or cos ...)
Have fun.
Code:
from math import *
x_degree = 30
#"degree in radians version1"
x_rad = x_degree*pi/180
#"degree in radians version2"
x2_rad= radians(x_degree)
y=tan(x_rad)
z=sin(x2_rad)
print 'sin(30°)=',z,'\n','tan(30°)=',y
Regards
Stefan
 
Last edited:

oldfox

Alibre Super User
Thanks Stefan. Got it.
In your last line of code above, is the "superscript o" for degrees just that, or a special "degrees" symbol?
 
Thanks Stefan. Got it.
In your last line of code above, is the "superscript o" for degrees just that, or a special "degrees" symbol?
The degree symbol is, in most TrueType Fonts the character "<Alt>0176" (hold down the <Alt> key and type (on the nimbers keypad) "0176").
 
Top