예제 #1
0
def create_hda(asset_name, department, already_tabbed_in_node=None):

    # Check if this body is an asset. If not, return error.
    body = Project().get_body(asset_name)
    if not body.is_asset():
        error_message("Must be an asset of type PROP or CHARACTER.")
        return None

    # Check if it is a set.
    if body.get_type() == AssetType.SET:
        error_message("Asset must be a PROP or CHARACTER.")
        return None

    # Check if the user is trying to create a Hair or Cloth asset for a Prop on accident.
    if body.get_type() == AssetType.PROP and (department == Department.HAIR or department == Department.CLOTH):
        error_message("Hair and cloth should only be made for characters.")
        return None

    # Create element if does not exist.
    element = body.get_element(department, name=Element.DEFAULT_NAME, force_create=True)

    # TODO: Get rid of this ugly hotfix
    # !!! HOTFIX !!!
    # Material was previously used as an AssetElement, but now is being treated like an HDAElement.
    # This will convert it's file extension to .hdanc. (Before, it's extension was "").
    element._datadict[Element.APP_EXT] = element.create_new_dict(Element.DEFAULT_NAME, department, asset_name)[Element.APP_EXT]
    element._update_pipeline_file()
    # !!! END HOTFIX !!!

    # Check out the department.
    username = Project().get_current_username()
    checkout_file = element.checkout(username)

    # Tab in the parent asset that will hold this checked out HDA
    node = already_tabbed_in_node if already_tabbed_in_node else tab_in(hou.node("/obj"), asset_name, excluded_departments=[department])

    # If it's a character and it's not a hair or cloth asset, we need to reach one level deeper.
    if body.get_type() == AssetType.CHARACTER and department not in this.byu_character_departments:
        inside = node.node("inside/geo/inside")
    else:
        inside = node.node("inside")

    # CREATE NEW HDA DEFINITION
    operator_name = element.get_parent() + "_" + element.get_department()
    operator_label = (asset_name.replace("_", " ") + " " + element.get_department()).title()
    this.hda_definitions[department].copyToHDAFile(checkout_file, operator_name, operator_label)
    hda_type = hou.objNodeTypeCategory() if department in this.byu_character_departments else hou.sopNodeTypeCategory()
    hou.hda.installFile(checkout_file)
    hda_definition = hou.hdaDefinition(hda_type, operator_name, checkout_file)
    hda_definition.setPreferred(True)

    # Tab an instance of this new HDA into the asset you are working on
    try:
        hda_instance = inside.createNode(asset_name + "_" + department)
        print('noce')
    except Exception as e:
        error_message("HDA Creation Error. " + asset_name + "_" + department + " must not exist.")
    hda_instance.setName(department)
    tab_into_correct_place(inside, hda_instance, department)
    hda_instance.allowEditingOfContents()
    hda_instance.setSelected(True, clear_all_selected=True)

    return hda_instance
예제 #2
0
def import_shot(shot_name):

    # Bring in the body so we can get info
    body = Project().get_body(shot_name)
    if not body or not body.is_shot():
        message_gui.error("Error with body.")
        return

    # Bring in element so we can get cache directory
    element = body.get_element(Department.ANIM)
    if not element:
        message_gui.error(
            "Anim department does not exist for {0} ".format(shot_name))
        return

    cache_dir = element.get_cache_dir()

    sets_json = []
    characters_json = []
    animated_props_json = []

    try:
        with open(os.path.join(cache_dir, "sets.json")) as f:
            sets_json = json.load(f)
    except Exception as error:
        print "{0}/sets.json not found.".format(cache_dir)

    try:
        with open(os.path.join(cache_dir, "characters.json")) as f:
            characters_json = json.load(f)
    except Exception as error:
        print "{0}/characters.json not found.".format(cache_dir)

    try:
        with open(os.path.join(cache_dir, "animated_props.json")) as f:
            animated_props_json = json.load(f)
    except Exception as error:
        print "{0}/animated_props.json not found.".format(cache_dir)

    set_nodes = []
    character_nodes = []
    animated_prop_nodes = []

    for set in sets_json:
        try:
            set_node = assemble_v2.tab_in(hou.node("/obj"), set["asset_name"])
        except:
            print "Error with {0}".format(set)
            continue
        set_nodes.append(set_node)
        for prop in set_node.children():
            data_parm = prop.parm("data")
            if data_parm is None:
                continue
            data = data_parm.evalAsJSONMap()
            for animated_prop in animated_props_json:
                if data["asset_name"] == animated_prop["asset_name"] and data[
                        "version_number"] == animated_prop["version_number"]:
                    prop.parm("space").set("anim")
                    prop.parm("shot").set(shot_name)
                    animated_prop_nodes.append(prop)

    print "we started from the bottom now we here"
    print "\tCharacters: {0}".format(characters_json)
    for character in characters_json:
        #TODO: Hardcoded name of show
        if character["asset_name"] == "dand_camera":
            camera_node = tab_in_camera(shot_name)
            character_nodes.append(camera_node)
            continue
        try:
            character_node = assemble_v2.byu_character(hou.node("/obj"),
                                                       character["asset_name"],
                                                       shot=shot_name)
            character_nodes.append(character_node)
        except:
            print "Error with {0}".format(character)
            continue
        #shot_parm = character_node.parm("shot")
        #shot_parm.set(shot_name)

        data_parm = character_node.parm("data")
        data = data_parm.evalAsJSONMap()
        print character
        print character["version_number"]
        data["version_number"] = str(character["version_number"])
        data_parm.set(data)

        version_number_parm = character_node.parm("version_number")
        version_number_parm.set(character["version_number"])

    box = hou.node("/obj").createNetworkBox()
    box.setComment(shot_name)
    for set_node in set_nodes:
        box.addItem(set_node)
    for character_node in character_nodes:
        box.addItem(character_node)
    for animated_prop_node in animated_prop_nodes:
        box.addItem(animated_prop_node)
    for set_node in set_nodes:
        set_node.moveToGoodPosition()
    for character_node in character_nodes:
        character_node.moveToGoodPosition()
    for animated_prop_node in animated_prop_nodes:
        character_node.moveToGoodPosition()