HOM

From DreamsteepWiki

Jump to: navigation, search

CURVE SOP SCRIPTING

import hou


def set_parm( node,parname,value):
  PARM = node.parm(parname)
  PARM.set(value)
  PARM.eval()

def set_curve_cvs ( hou_node,coords ):
   hou_parm = hou_node.parm("coords")
   hou_parm.set(coords)
   hou_parm.setAutoscope(False)
   hou_parm.lock(False)

geonod = hou.node('/obj').createNode('geo')
pathuse = geonod.path()
hou.cd( pathuse )
curvenod = geonod.createNode('curve')
set_curve_cvs(curvenod,'1,1,1 2,2,2 3,3,3 4,4,4 5,5,5 ')
hou.cd( '..' )


MY OWN PARTICLE DATA DUMPER BASED ON CODE BELOW FORM HOM COOKBOOK

import hou


#############################################
def kl_writeArray2File(file_name,array):
   f = file(file_name, "w")
   for line in array:
        f.write(line +'\n')
   f.close()
   

#############################################
def export_cvs_over_time (popnet):

   geo = popnet.geometry()
   ARRAY = []
   ALLPOINTS = geo.points()
   attribs = geo.pointAttribs()
      

   for point in ALLPOINTS:
      XYZDATA  =  point.attribValue( attribs[0] )
      VELOCITY =  point.attribValue( attribs[1] )
      LIFETIME =  point.attribValue( attribs[2] )
      ##
      ARRAY.append( str( XYZDATA  )  )

   return ARRAY

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


start =  0
end   =  20

for a in range(start,end):
  hou.setFrame(a)
  FRAM = hou.frame()
  print '# EXPORTING FRAME NUMBER  '+str( FRAM )
  #writeFireworks( ('C:/fire_'+str(a)+'.txt') )
  DATA = export_cvs_over_time( hou.node("/obj/aa/popnet1") )
  #print DATA
  kl_writeArray2File( ('C:/firewerks.txt') ,DATA )


NODES CAN CREATE NODES

import hou


geonod = hou.node('/obj').createNode('geo')
pathuse = geonod.path()
hou.cd( pathuse )
print ('DEBUG PATH USE ' + pathuse)

curvenod = geonod.createNode('curve')
hou.cd( '..' )

print hou.pwd()


SAMPLE PARTICLE POSTITIONS


import hou

def writeParticlesAsGeo(popnet, file_name):
   popnet.geometry().saveToFile(file_name)
   
def writeParticlesInCustomFormat(popnet, file_name):
   """Write the particle data in the geometry geometry to a custom file
   format.
   """
   geo = popnet.geometry()
   f = file(file_name, "w")
   # Write out the number of particle attributes, followed by the particle
   # attribute information.
   f.write("%d attributes:\n" % len(geo.pointAttribs()))

   for attrib in geo.pointAttribs():
      f.write("%s %s %d\n" % (attrib.name(), attrib.dataType(), attrib.size()))
   f.write("\n")
   
   # Write the number of particles, followed by the particle attribute values.
   f.write("%d points:\n" % len(geo.points()))
   for point in geo.points():
      for attrib in geo.pointAttribs():
         f.write("%s = %s\n" % (attrib.name(), point.attribValue(attrib)))
      f.write("\n")
   f.close()

def writeFireworks():
      writeParticlesInCustomFormat(hou.node("/obj/aa/popnet1"), "C:/fireworks.txt")
      
writeFireworks()

n = hou.node('/asdfasdf') >>> # The node path was invalid, so n will be the None object. 

>>> print n None >>> g = hou.node('/obj').createNode('geo') >>> g <hou.ObjNode of type geo at /obj/geo1> >>> # g is hou.Node object corresponding to the newly created /obj/geo1 node. >>> # Note that g is actually a hou.ObjNode instance, which is a subclass of >>> # hou.Node. >>> # The parm method on hou.Node objects returns a hou.Parm object (or None >>> # if the parameter name is invalid). >>> tx = g.parm('tx') >>> tx <hou.Parm tx in /obj/geo1> >>> # Evaluate the parameter and change its value. >>> tx.eval() 0.0 >>> tx.set(3.5) >>> tx.eval() 3.5 >>> hou.node('/obj/geo1').parm('tx').eval() 3.5 >>> # hou.parm is a shortcut to access a parm directly. >>> hou.parm('/obj/geo1/tx').eval() 3.5 >>> # hou.evalParm is a shortcut to evaluate a parameter. >>> hou.evalParm('/obj/geo1/tx') 3.5 >>> # hou.ch is exactly the same as hou.evalParm. >>> hou.ch('/obj/geo1/tx') 3.5 >>> # hou.Parm.name returns the name of the parameter, and hou.Node.parms >>> # Returns a tuple of all the Node's parameters. >>> [p.name() for p in g.parms()] ['stdswitcher1', 'stdswitcher2', 'stdswitcher3', 'stdswitcher4', 'keeppos', 'pre_xform', 'xOrd', 'rOrd', 'tx', 'ty', 'tz', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz', 'px', 'py', 'pz', 'scale', 'lookatpath', 'lookup', 'pathobjpath', 'roll', 'pos', 'uparmtype', 'pathorient', 'upx', 'upy', 'upz', 'bank', 'shop_materialpath', 'shop_materialopts', 'tdisplay', 'display', 'use_dcolor', 'dcolorr', 'dcolorg', 'dcolorb', 'picking', 'pickscript', 'caching', 'vport_shadeopen', 'vport_displayassubdiv', 'vm_phantom', 'vm_renderable', 'folder01', 'folder02', 'folder03', 'folder04', 'categories', 'reflectmask', 'lightmask', 'geo_velocityblur', 'vm_shadingquality', 'vm_rayshadingquality', 'vm_rmbackface', 'shop_geometrypath', 'vm_rendersubd', 'vm_renderpoints', 'vm_metavolume', 'vm_coving', 'vm_computeN'] >>> # hou.Parm tuples correspond to parameter groupings: >>> t = g.parmTuple('t') >>> t <hou.ParmTuple t in /obj/geo1> >>> tuple(t) (<hou.Parm tx in /obj/geo1>, <hou.Parm ty in /obj/geo1>, <hou.Parm tz in /obj/geo1>) >>> t.eval() (3.5, 0.0, 0.0) >>> t.set((1.0, 2.0, 3.0)) >>> t.eval() (1.0, 2.0, 3.0) >>> # Build a simple sop network. >>> hou.hipFile.clear() >>> geo = hou.node('/obj').createNode('geo') >>> box = geo.createNode('box') >>> subd = geo.createNode('subdivide') >>> subd.parm('iterations').set(3) >>> subd.setFirstInput(box) >>> subd.moveToGoodPosition() # Move the node tiles to avoid overlaps. >>> subd.setDisplayFlag(True) >>> subd.setRenderFlag(True) >>> subd.setCurrent(True, clear_all_selected=True)

Personal tools