I wrote this code to the following question:

code:

import maya.cmds as mc

mc.window()
mc.columnLayout()
mc.button ('make chain', command="chainspheres(),chainpc(),chainpp()")
mc.button ('make joints', command="jts1(),jts2()")
mc.showWindow()

def chainspheres(): # Chain Spheres

#Make sphere 1

   mc.sphere(n='sphere1')         # Create sphere with name sphere1
   mc.move (0,0,0)                # Move sphere1 in positions
   mc.makeIdentity( apply=True )  # Freeze position

#Make Sphere 2

   mc.sphere(n='sphere2')         # Create sphere with name sphere2
   mc.move (5.213,0,0)
   mc.makeIdentity( apply=True )  # Freeze position

#Make Sphere 3

   mc.sphere(n='sphere3')         # Create sphere with name sphere3
   mc.move (10.134,0,0)           # Move sphere1 in positions
   mc.makeIdentity( apply=True )  # Freeze position

############################################################################

def chainpc():                   # Chain polyCube 1

   mc.polyCube(n='cube1')         # Create pCube 1
   mc.move (12.714,0,0)           # Move sphere1 in positions
   mc.makeIdentity( apply=True )  # Freeze position

   mc.polyCube(n='cube2')         # Create pCube 2
   mc.move (14.885,0,0)           # Move cube3 in positions
   mc.makeIdentity( apply=True )  # Freeze position

   mc.polyCube(n='cube3')         # Create pCube 3
   mc.move (16.933,0,0)           # Move cube3 in positions
   mc.makeIdentity( apply=True )  # Freeze position

   mc.parent( 'cube3','cube2', relative=True )
   mc.parent( 'cube2','cube1', relative=True )



def chainpp():                      # Chain polyPlane

   mc.polyPlane(n='plane1')         # Create pplane 1
   mc.move (12.714,0,2.055)         # Move sphere1 in positions
   mc.makeIdentity( apply=True )    # Freeze position

   mc.polyPlane(n='plane2')         # Create pplane 2
   mc.move (14.885,0,2.055)         # Move plane3 in positions
   mc.makeIdentity( apply=True )    # Freeze position

   mc.polyPlane(n='plane3')         # Create pplane 3
   mc.move (16.933,0,2.055)         # Move plane3 in positions
   mc.makeIdentity( apply=True )    # Freeze position

   mc.parent( 'plane3','plane2', relative=True )
   mc.parent( 'plane2','plane1', relative=True )

########################################################################

def jts1():

# Make joints in geometries polyCubes

   cmds.group( em=True, name='pcube_grp' )
   cmds.joint (n='jtcube1')
   cmds.delete(    cmds.parentConstraint("cube1","jtcube1"))

   cmds.joint (n='jtcube2')
   cmds.delete(    cmds.parentConstraint("cube2","jtcube2"))

   cmds.joint (n='jtcube3')
   cmds.delete(    cmds.parentConstraint("cube3","jtcube3"))

# Delete Geo
   cmds.delete ('cube1')

def jts2():

# Make joints in geometries polyPlanes

   cmds.group( em=True, name='pplane_grp' )
   cmds.joint (n='jtplane1')
   cmds.delete(    cmds.parentConstraint("plane1","jtplane1"))

   cmds.joint (n='jtplane2')
   cmds.delete(    cmds.parentConstraint("plane2","jtplane2"))

   cmds.joint (n='jtplane3')
   cmds.delete(    cmds.parentConstraint("plane3","jtplane3"))

# Delete Geo
   cmds.delete ('plane1')

# END


The question is:

When .... I create the geometries on the Make Chain, the geometries
appearance in the viewport ok? suppose I want to delete the string
(plane1). Apart from that, squeeze the button Make Joints.

An error occurs:

# Error: Object is invalid plane1

How do I recognize the script that plane1 was deleted manually without
the error occurs?
-- 
http://groups.google.com/group/python_inside_maya

Reply via email to