Intro to Python Scripting: 02 Varibles and Input/Output
OK, in this video we finally get to do a little Rhino, albeit a very little. We are building up in small steps, partly because it keeps the videos short and I think bite sized chunks are helpful in these intro videos. This video covers a couple of varible types and a little bit about naming conventions. We also look at getting info from the user via Rhino's command line. Simple stuff but it leads to good scripts later. We also cover a bit of string formatting in python. This can be slightly confusing to people so I try to explain it in the simplest terms. Here is good link that talks about all things strings! Take a look specifically at string formatters and escape characters.
#Variables and Simple User input/output import rhinoscriptsyntax as rs #String Examples strGreeting = "Hello World" print strGreeting strInput = rs.GetString("Type String to Print") print strInput #Number Examples dblRadius01 = 2.0 print dblRadius01 dblRadius02 = rs.GetReal("Enter a Number for Radius02", 3.0) print dblRadius02 #String Formatters print "Radius01 : %d \nRadius02 : %d" % (dblRadius01, dblRadius02) strMessage = "Radius01 : %d \nRadius02 : %d" % (dblRadius01, dblRadius02) rs.MessageBox(strMessage)
Format Symbol %c character %s string conversion via str() prior to formatting %i signed decimal integer %d signed decimal integer %u unsigned decimal integer %o octal integer %x hexadecimal integer (lowercase letters) %X hexadecimal integer (UPPERcase letters) %e exponential notation (with lowercase 'e') %E exponential notation (with UPPERcase 'E') %f floating point real number %g the shorter of %f and %e %G the shorter of %f and %E
Backslash Notation and Descriptions \a Bell or alert \b Backspace \cx Control-x \e Escape \f Formfeed \n Newline \r Carriage return \s Space \t Tab \v Vertical tab \x Character x
Want to Contribute?
Want to be an author? Drop us a line here we'd love to have you.
Already have a video you'd like to post? Send us a link and we'll get you going.
:)
Comments
miledrizk replied on Permalink