I have read alot about validating the user input at different websites, but I still wasn’t able to find a method in python for generating the condition at “the end of the while statement”… Like in Visual Basic for example:
Do
[ statements ]
[ Continue Do ]
[ statements ]
[ Exit Do ]
[ statements ]
Loop { While | Until } condition
So here is my code at the momen. I’m not sure, if everything is perfect. I am just a beginner … Maybe somebody has more knowledge and can provide me with a simple way to get to the solution…
import Rhino as rhinoRef
import Rhino.Geometry
import rhinoscriptsyntax as rs
import math
import scriptcontext
def abcde():
# Parameters
# standard values for parameters
bx = 0.0 # base point coordinates
by = 0.0
bz = 0.0
lCube = 10.0 # side length of cube
rCyl = 1.0 # radius of cylinder
hCyl = 20.0 # height of cylinder
rSph = 6.0 # radius of sphere
thSl = 0.3 # thickness of slot
hSl = 1.3 # height of slot
# ask the user to pick a base point
BasePoint = rs.GetPoint("Pick base point")
# ask the user to enter the side length for the cube
lCube = rs.GetReal("please, enter the side length for the cube C1",10.0,1,)
# ask the user to enter radius of the cylinder
rCyl = rs.GetReal("please, enter the radius of the cylinder Cl1",1.0,1,)
# ask the user to enter height of the cylinder
hCyl = rs.GetReal("please, enter the height of the cylinder Cl1",20.0,1,)
# ask the user to enter radius of the spehere
rSph = rs.GetReal("please, enter the radius of the spehere S1",6.0,1,)
# ask the user to enter thickness of the slot
thSl = rs.GetReal("please, enter the thickness of the slot Sl1",0.3,0.1,)
# ask the user to enter height of the slot
hSl = rs.GetReal("please, enter the height of the slot Sl1",1.3,0.5,)
# store base point coordiantes
bx = BasePoint.X
by = BasePoint.Y
bz = BasePoint.Z
# Validation of input
while (thSl < lCube and hSl < lCube and rSph >= lCube/2) == False:
print ("The thickness of the slot" + " = " + str(thSl) + "should not be smaller than the length of the cube" + " = " + str(lCube))
print ("and the height of the slot" + " = " + str(thSl) + "should not be smaller than the length of the cube" + " = " + str(lCube))
print ("and the radius of the sphere" + " = " + str(rSph) + "should not be smaller than the half side length of the cube" + " = " + str(lCube/2))
print ("please, repeat and make sure, that your input matches these criteria")
return
#create a cylinder
rs.AddCylinder(BasePoint,hCyl,rCyl,cap=True)
#create a sphere
rs.AddSphere(BasePoint,rSph)
One problem is that I am not really sure, what “return” exactly does here. The second problem is that neither sphere nor cylinder are created in Rhino!!
Thanks alot!!