kgoossens Posted February 7, 2012 Share Posted February 7, 2012 Hi All, I'd like to access or emulate the "Create All Local Material Parameters" Resulting in I'm still beginning to use Python, but I'm a bit lost on how I should approach this. I think I've got the beginning, but then... shop = hou.node('/shop/material1').parmTemplateGroup() hou.node('/obj/geo2').setParmTemplateGroup(shop) It creates all the parameters under a "Spare" folder and puts the existing parameters under a "Standard" folder. Something that is totally different. Looking through the ParmTemplateGroup functions I'm unable to find/understand yet how I should approach this. Putting me on the right track would be greatly appreciated by this derailed person. Quote Link to comment Share on other sites More sharing options...
asnowcappedromance Posted February 7, 2012 Share Posted February 7, 2012 here's how you do it shop = hou.node('/shop/clay') shopptg = shop.parmTemplateGroup() node = hou.node('/obj/box_object1') ptg = node.parmTemplateGroup() for i in shopptg.parmTemplates(): ptg.appendToFolder(ptg.findFolder("Material"), i) node.setParmTemplateGroup(ptg) cheers, Manuel Quote Link to comment Share on other sites More sharing options...
kgoossens Posted February 7, 2012 Author Share Posted February 7, 2012 (edited) here's how you do it shop = hou.node('/shop/clay') shopptg = shop.parmTemplateGroup() node = hou.node('/obj/box_object1') ptg = node.parmTemplateGroup() for i in shopptg.parmTemplates(): ptg.appendToFolder(ptg.findFolder("Material"), i) node.setParmTemplateGroup(ptg) cheers, Manuel Thanks a lot Manuel It works in the sense that it adds the parameters on the right spot, but there seems more things going on with the delayed load. Because if I use the "Create All Local Material Parameters" then the instancing works. If I add the parameters with the script it doesn't work. Has anybody have some ideas on this? Using script I've also attached the scene file. DelayedLoadInstance.rar Edited February 7, 2012 by kgoossens Quote Link to comment Share on other sites More sharing options...
graham Posted February 10, 2012 Share Posted February 10, 2012 (edited) The problem is that material override parameters need to have a special parm tag to flag them as being material overrides: "material_spare" = "1". This needs to be set on every parameter that is being applied. The following function is what I use to handle this type of thing. Given the object node to apply the operation to, it will find the material node, ensure it's actually a material, then take care of modifying all the parameters and sticking them in the right place. def applyLocalOverrides(objnode): """ Promote all material parameters from the Material SHOP to the node. """ # Get the path to the material. material_path = objnode.evalParm("shop_materialpath") # Try to find the node. material_node = objnode.node(material_path) # The node type for the SHOP material node. material_type = hou.nodeType(hou.shopNodeTypeCategory(), "material") # If the material node doesn't exist we need to throw an error. if not material_node: msg = "{0} is not a valid node.".format(material_path) raise hou.OperationFailed(msg) # If the material node is not actually a material we need to throw # an error. if material_node.type() != material_type: msg = "{0} is not a material.".format(material_path) raise hou.OperationFailed(msg) # Grab the parm template groups for the material and object. material_template_group = material_node.parmTemplateGroup() template_group = objnode.parmTemplateGroup() # We need to loop over every entry in the material group and apply the # 'material_spare' tag with a value of '1'. for template in material_template_group.entriesWithoutFolders(): # Grab any existing tags. tags = template.tags() # Apply the tag to signify it is a material spare property. tags["material_spare"] = "1" # Set the tags back to the template. template.setTags(tags) # Replace the original template with the modified one. material_template_group.replace(template.name(), template) # Find the folder to place the parameters into. material_folder = template_group.findFolder("Material") # For each entry in the template group, append it to the material # folder. for template in material_template_group.entries(): template_group.appendToFolder(material_folder, template) # Set the parm template group with the new parms to the object. objnode.setParmTemplateGroup(template_group) Edited February 10, 2012 by graham 1 Quote Link to comment Share on other sites More sharing options...
kgoossens Posted February 10, 2012 Author Share Posted February 10, 2012 Great!! Thanks a lot Graham! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.