Due to a miscommunication between Elsevier Press and the Python Software Foundation, the first printing of this title used an unauthorized modification of the trademarked Python logo. We apologize to the PSF for this, and they have been understanding of our in-press status; in the 2nd and subsequent printing of this title, we shall use a cover design that has been approved as non-dilutive by the Python Software Foundation.

Help make the world a better place and make a secure donation to the Python Software Foundation today!

 

Chapter 2

Basics of Python Data

Author

Ryan Trowbridge & Adam Mechtley

Project

Using variables on conjunction with Maya commands

Example Files

None

Synopsis

This chapter provides a brief overview of variables and Python’s data model. We compare variable typing in Python to MEL and provide information on Python’s memory management system. We then examine some details of working with Python’s core object types.

Resources

Python String Methods
Unicode Table
Regular Expressions

Other Notes

None

Errata for the First Edition

None


7 Responses to “Chapter 2”

  1. Hey Guys,

    Good Book so far! I’m learning a lot, and it’s nice to learn python in terms of Maya versus generic computer programming. In any case I’m up to page 42 of your book where you give the example controlling a sphere’s translation with a cube’s rotation. I got to the multiply and divide note part…typed in the script and got this error message: # Error: RuntimeError: The destination attribute ‘multiplyDivide2.input1x’ cannot be found.

    Here’s the code i typed into the script editor:
    sphere = maya.cmds.polySphere()[0];
    cube = maya.cmds.polyCube()[0];

    mult = maya.cmds.createNode(‘multiplyDivide’)
    maya.cmds.connectAttr(cube+’.ry’,mult+’.input1x’);
    maya.cmds.setAttr(mult+’.input2x’,1.0/90.0);
    maya.cmds.connectAttr(mult+’.output1x’,sphere+’,ty’);
    maya.cmds.select(cube);

    Can you guys tell me what’s wrong?

    Also since I’m here I wanted to ask, when you use the createNode command does that first string determine what type of node you’re creating…and then if you want to name just n?

    I’m a huge newb to scripting and programming–so I apologize if this is a silly question.

    Thanks,

    Teresa

  2. Hi Teresa! Glad you’re enjoying the book so far. The problem in your code sample is that the capitalization of the attributes is wrong. It needs to be input1X, not input1x. As for your second question, you are correct. You may find this page helpful.

    • Hello Adam,

      I’m learning maya scripting now and I find your book very helpful.

      Can you please explain the input1X, input2X, outputX thing? I tried to find them in documents but I didn’t find anything.

      Thanks a lot,
      Sty

      • Hey Sty,

        You can find information on attributes of built-in nodes in the node reference in the help (Technical Documentation section at the very bottom of the help browser). For example, here is the documentation for the multiplyDivide node.

  3. Hello,

    I’m having trouble with something mentioned on page 32. The book mentions that python provides a built in function, type(), which allows you to determine the type of a variable at any point.

    Whenever I try to execute that function with a variable inside the parenthesis, I get an error in maya. An example would be:

    contents = ‘toys’
    type(contents)
    # Error: TypeError: file line 2: ‘module’ object is not callable #

    Any idea why I am getting this error?

    • Im actually further along in the book on page 65 where Im trying to following along but running into the following:

      def process_all_textures():
      print(‘process all textures’)

      type(process_all_textures)
      # Error: TypeError: file line 4: ‘module’ object is not callable #

      • by the way, I have the correct indenting, Im copying and pasting what is printed in the script editor after I run the code.

Leave a Reply

Your email address will not be published. Required fields are marked *