Duplicating Solaris Render Vars with python

   836   3   1
User Avatar
Member
86 posts
Joined: Jan. 2009
Offline
I'm wondering if there's a way to duplicate a Render Var prim with python. I've found I can create a new prim with the DefinePrim() function, but if I do that I'm going to need to loop through all of the Attributes on my existing Render Var and copy them one by one to the new prim. Ideally I'm looking for a DuplicatePrim() option. Does it exist?

Cheers,

Tony
User Avatar
Member
86 posts
Joined: Jan. 2009
Offline
if anyone is curious, this seems to be working for me at the moment in my python lop:

#current node
node = hou.pwd()
#current stage
stage = node.editableStage()
#path to source prim
source_path = "/Render/Products/Vars/N"
#name for target
target_name = "copy"
#get source prim
source=stage.GetPrimAtPath(source_path)
#define target path
target_path = source_path.rstrip(source_path.split("/")[-1])
#create target prim
target = stage.DefinePrim(target_path+target_name, source.GetTypeName())
#get a list of all the properties on the source prim
properties=source.GetProperties()
#loop through all the source properties
for property in properties:
    #get property name
    property_name = property.GetName()
    #get property value
    property_value = property.Get()
    #get property type
    property_type = property.GetTypeName()
    #if the new render var doesn't have the current property
    if not target.HasProperty(property_name):
        #create the property
        target.CreateAttribute(property_name, property_type)
    #set the property on the new render var
    target.GetAttribute(property_name).Set(property_value)
User Avatar
Staff
4438 posts
Joined: July 2005
Offline
Another approach would be to use DefinePrim to create the new prim, then adding a Reference on the new prim that points to the original. The difference with this approach is that any changes to the original prim will now show up on the new prim too (which may be good or bad depending on your use case).
User Avatar
Member
86 posts
Joined: Jan. 2009
Offline
That's interesting. Would I be able to override some values on my new prim or would they all have to match the old one?
  • Quick Links