float problem

i put one more line in a script and thre is an eror generated
code:
glob.hypo= sqrt(pow( glob.base, 2.0))
float

what can i do to correct this line of code?

Thanks

Do you really need to get square root from variable in degree 2? :slight_smile:

import math
from math import sqrt

a = sqrt(pow( 2.1, 2.0))
print a

2.1

No errors…

the real line is more like this
calutaton of hypotenus =sqroot of sum of squares

glob.hypo= sqrt(pow( glob.base, 2)+pow( glob.height, 2))

and this is inside a function - and in this script it seems that i have to use glob variables
instead of local variable not certain why?
plus this error about float which i don’t understand!
tht’ arond line 150 in the script

this calcualtion was inside another script and working fine
but i imported it inside Def function and nothing seems to be working anymore
very strange?

Thanks

I can’t even simulate this error…

it has about 300 lines
mind you i/m working only the first part which is the fouth def
for triangle rectangular
i’ll put inside the Def functin the rest of the calculation but in quotation
so it want execute

i had to redefine variable as global because of the Def function

http://uploader.polorix.net//files/1502/trianglemenu5.py
now to get the error you run the script then select the first menu and then rectangle
that should start the Def functin #4 and run the rectangular triangle Def function
and that;s where the error happens
that’s around line 150 in the script

Thanks

http://uploader.polorix.net//files/1502/trianglebaseheight1.blend

this draw a simple rec triangle with some text which is not working for now
and it should show values for the centroid - inscribe circle - circomscribe cirle
edges lengh - angles ect…
all the important parameters for a triangle
later i’ll probably put the script inot the Blender scripts repository if ican find how!

this the same script that i’m trying to put inside a Def function
the only thing not working so far is the Text3D i cannot put a string inside the text3D object
that would change the content of the text inside the text objects in blender

anyway
i had to change some of the variables to glob variable tio amke tem globaly available
and that;s ehre the problem begans

i appreciate a lot you help

Thanks

If glob.base or glob.height isn’t a float, pow() will fail. When you fix that, your error should be fixed too. Having said that, I think that you should unlearn a few bad habits, they will hurt you if your scripts get bigger:

  • Don’t use glob to name a global variable, since there is a built-in Python module called glob.
  • If you really need global variables, use them as little as possible. Instead of:

def make_spiral_Rectangle():
  hypo = glob.hypo
  ...
make_spiral_Rectangle()

use:


def make_spiral_Rectangle(hypo):
  ...
hypo = glob.hypo
make_spiral_Rectangle(hypo)

  • pow(hypo,2) can be replaced by hypo**2

Sjoerd

ok i used your suggestin for the power of 2
and made another little independant script to test it and it works fine

but it’s refusing to work inside the Def function

i put this code to make a test
aa=glob.base
bb=glob.height
print “aa=”,aa," bb=",bb

cc=bb**2.0
print " bb 2 = cc =",cc

and it crash at the line for cc=bb**2.0
the error is unsupported operand for the pow function

at the end of the DEf functin
i;m using this statement
B.Window.RedrawAll()
my be this one does like it that power function

something else is wrong here and not certain what it is

i made a ttest and it doesn not like any of the Mulitply power ect operand ?

Thanks

Create creates a blender Button object. To access it’s value do.

G.somebutton=Create(2.0)
print G.somebutton.val
G.somebutton.val=1.0
print G.somebutton.val