Lecture notes 10/10/22


So made a devblog (https://ionasphero.itch.io/programming-for-animation) that lecturers and other people on the course have access to. It’s a bit easier than managing the shared link settings of Trello, plus I’ll probably have to work with itch.io in the future if I ever plan to release a game/software.

As for coding, did a bit more Python in Mimo, got expressions down. In lecture, looks like we’ll be doing if statements. Gonna copy this useful bit from w3schools for posterity

Python supports the usual logical conditions from mathematics:

  • Equals: a == b
  • Not Equals: a != b
  • Less than: a < b
  • Less than or equal to: a <= b
  • Greater than: a > b
  • Greater than or equal to: a >= b

These conditions can be used in several ways, most commonly in "if statements" and loops.

An "if statement" is written by using the if keyword.

So far so good, seems easier but very similar than normal Java if statements. Of course, nothing in coding is simple so I’m sure I’ll eat these words later. I tried a simple script to randomly generate two numbers, then use an if statement to print who won. Didn’t work though, working that bit out now. I am already eating those words.

import random

 

a = random.randrange (1,100)

b = random.randrange (1,100)

 

 

print()

print()

print()

 

if b > a:

                print("A wins")

 

if a < b:

                print("B wins")

   

if a == b:

                print("It's a draw, holy shit")

 

Figured out the issue. Turns out python is super anal about whitespace, and a simple tab isn’t enough. Very well, three spaces it is. I got the code to work (I had put the > the wrong way round), but when I tried to add an expression to show the A and B values (to make sure it worked properly) I got this error:

Traceback (most recent call last):

  File "./prog.py", line 7, in <module>

TypeError: can only concatenate str (not "int") to str

 

It’s not massively important for now, so moving on. Else statements from java now appear to have been joined elif statements, which is honestly much nicer. I’m actually liking python so far for it’s simplicity. So you can now have a nice loop of if, elif, else statements.

And and Or are there too, and too pretty much what they say on the tin. There’s also single line shorthand versions of the if and else statements if they only have one variable, but I’ll probably stick to the longhand version till I’ve got this shit nailed down.

Did a few exercises, then moved onto Maya work, namely how to create a window. The code for it:

 

import maya.cmds as cmds

 

 

if cmds.window("UI_window", exists = True):

    cmds.deleteUI("UI_window")

 

window = cmds.window( "UI_window", title="Long Name", iconName='Short Name', widthHeight=(200, 55) )

cmds.columnLayout( adjustableColumn=True )

cmds.button( label='Do Nothing' )

cmds.button( label='Close', command=('cmds.deleteUI(\"' + "UI_window" + '\", window=True)') )

cmds.setParent( '..' )

cmds.showWindow( "UI_window" )

 

Remember to use command documentation more! Turns out if there is a maya.cmds command that exists, now only does the command doc tell you just what the hell it does but also all of the tags that can directly affect it. I’ve got a headache atm and it’s hard to work this out but remember to check this out: https://help.autodesk.com/view/MAYAUL/2023/ENU/index.html?contextId=COMMANDSPYTHON-SETPARENT

And actually figure out how the fuck parent works, or at least how to expand this window. Although I’m not sure just what the window is good for in Maya, or if it’s just good stuff to know.