Python Query Functions: 
This code that I have made queries the user for the number of objects and then creates a ground plane and creates an equal distribution of at least 3 objects. The objects all have a random position, color and size. They also do not intersect with the ground plane. 


''' import random
obj = hou.node("/obj")
def newContainer(parent, name = "default", xpos = 0, ypos =0):
    container = parent.createNode("geo", name)
    
    container.parm("tx").set(xpos)
    container.parm("tz").set(ypos)
    
    return container
        
def newColor(parent, blue = 0.0, green = 0.0, red = 0.0):
    colorNode = parent.createNode("color", "newColor")
    
    if blue == 0.0: 
        blue = random.uniform(0.0, 1.0);
    if green == 0.0:
        green = random.uniform(0.0, 1.0);
    if red == 0.0: 
        red = random.uniform(0.0, 1.0);
        
    colorNode.parmTuple("color").set((blue, green, red)) 
    
    return colorNode
    
def newFloor(parent, name = "Floor", width = 300.0, depth = 300.0):
    myFloor = parent.createNode("grid", name)
    
    myFloor.parmTuple("size").set((width, depth))
    
    colorNode = newColor(parent)
    colorNode.setInput(0, myFloor) 
    colorNode.setDisplayFlag(True)
    
def newRoberto(parent, name = "Roberto"):
    myRoberto = parent.createNode("testgeometry_rubbertoy", name)
    
    randScale = random.uniform(.1, 5.0) 
    parent.parm("scale").set(randScale) 
    
    #bonuspoints
    myRoberto.parm("ty").set(.5, 2.0)
    
    colorNode = newColor(parent)
    colorNode.setInput(0, myRoberto) 
    colorNode.setDisplayFlag(True)
    
def newPiggy(parent, name = "Piggy"): 
    myPiggy = parent.createNode("testgeometry_pighead", name) 
    
    randScale = random.uniform(1.0, 3.0) 
    parent.parm("scale").set(randScale)
    
    #bonuspoints
    myPiggy.parm("ty").set(1.5, 5.0)
    
    colorNode = newColor(parent)
    colorNode.setInput(0, myPiggy) 
    colorNode.setDisplayFlag(True)
    
def newGolem(parent, name = "Golem"): 
    myGolem = parent.createNode("testgeometry_crag", name)
    
    randScale = random.uniform(2.0, 6.0) 
    parent.parm("scale").set(randScale)
    
    #bonuspoints
    myGolem.parm("ty").set(.5, 2.0)
    
    colorNode = newColor(parent)
    colorNode.setInput(0, myGolem) 
    colorNode.setDisplayFlag(True)
    
def newSquab(parent, name = "Woomy"):
    myWoomy = parent.createNode("testgeometry_squab", name) 
    
    randScale = random.uniform(0.5, 2.0) 
    parent.parm("scale").set(randScale)
    
    #bonuspoints
    myWoomy.parm("ty").set(2.0, 4.0)
    
    colorNode = newColor(parent)
    colorNode.setInput(0, myWoomy) 
    colorNode.setDisplayFlag(True)
    
def isUnique(xpos, ypos):
    global objectList
    
    for object in objectList: 
        if object[0] == xpos and object[1] == ypos: 
            return False
    return True
    
objectList = []
xmin = -70
xmax = 70
ymin = -70
ymax = 70
print("Let's build our fun world.")
input = input('Enter the number of objects so we can get this show on the road:') 
objectNumber = int(input) 
for geo in range(objectNumber):
    unique = False
    while unique == False: 
        xpos = random.randint(xmin, xmax) 
        ypos = random.randint(ymin, ymax) 
    
        if isUnique(xpos, ypos):
            unique = True 
        
    objectList.append((xpos, ypos))
    
    parent = newContainer(obj, "Minions", xpos, ypos) 
    
    if geo >= 3*objectNumber/4:
        child = newGolem(parent) 
    elif geo >= 2*objectNumber/4:
        child = newPiggy(parent) 
    elif geo >= objectNumber/4:
        child = newSquab(parent)
    else: 
        child = newRoberto(parent) 
    
parent = newContainer(obj, "Ground", 0, 0)
ground = newFloor(parent, "ground", (xmax-xmin)+5, (ymax-ymin)+5) '''
This code queries the user for the object they want to make, the number of objects, and the scale of objects. It then creates those objects, arranges them in a spiral pattern, and adds a random color for each one. 

''' import math # Needed for the trig functions
# Collect all of your input value
print("We are going to taste the rainbow!") 
print("Make your choices wisely.") 
input = input('enter object type(oink, woomy, roberto, tubey) number of objects and object scale:')
objectType, objectNumber, objectScale = input.split()
objectNumber = int(objectNumber)
objectScale = float(objectScale)
# Create a top Node
obj = hou.node("/obj")
# Creat constants for radius and rotational increments
rotationIncrement = (2.0 * math.pi)/objectNumber
pivotIncrement = 360.0 / objectNumber
pivot = 180
radius = 10
# Create all of your objects and position them in a circle
for object in range(objectNumber): 
    geoName = objectType+str(object)
    geoNode = obj.createNode("geo", geoName)
    geoNode.parm("scale").set(objectScale)   # Set the scale for good measure
    
    #If the user types in something incorrect, this will catch the error
    if objectType == "oink":
        geotype = "testgeometry_pighead"
    elif objectType == "woomy":
        geotype = "testgeometry_squab"
    elif objectType == "roberto":
        geotype = "testgeometry_rubbertoy"
    elif objectType == "tubey":
        geotype == "tube"
    else: 
        geotype = "testgeometry_pighead" 
        print("You done messed up, so you get a scary pig head by default!")
        break
        
    #Create the child primitive node    
    child = geoNode.createNode(geotype,"child")
    
    # a color sop after it to get fancy
    colorNode = geoNode.createNode("color", "color")
    colorNode.setInput(0, child)
    
    ## Extra
    myColor = hou.Color((0.0, 0.0, 0.0))
    hVal = float(object)/objectNumber * 360.0
    myColor.setHSV((hVal, 1.0, 1.0))
    colorNode.parmTuple('color').set(myColor.rgb())
    colorNode.setDisplayFlag(True)    
    
    ### Position the objects along a circle of radius 1
    xpos = radius * math.cos(object*rotationIncrement)
    zpos = radius * math.sin(object*rotationIncrement)
    ypos = radius * math.sin(object*rotationIncrement/4) 
    geoNode.parmTuple("t").set((xpos, ypos, zpos))
    
    ### Rotate the container such that the object always points to the outside
    geoNode.parm("ry").set(pivot)
    pivot -= pivotIncrement*2 '''
Back to Top