Do you guys know of an identifying way to identify non Genesis characters

Issue #1889 resolved
Joe Morris @ FAST Animation Studio Toolz created an issue

I'm I'm trying to write a conditional in my code so I could still detect If a file is a Genesis character but also allow characters like D A Z horse come through and D A Z dog…. See I'm doing this conditional to allow DAZ horse through but it would be great to easily get all nonstandard characters like animals and maybe that talking monkey and I think there's a talking bear on there and just you know the whole selection of non standard non Genesis characters or at least more than just D a Z Horse…. Without Unzipping and looking through every file . but still be able to use my conditional to warn the end user if they’re importing a character and not a proper environment so can I count on your greater D a Z wisdom to let me know the right approach to maybe differentiating...

def is_character_file(file_path):
    def unzip_and_read_file(file_path):
        temp_dir = tempfile.mkdtemp()
        output_path = os.path.join(temp_dir, os.path.basename(file_path))

        with gzip.open(file_path, "rb") as gzip_file:
            with open(output_path, "wb") as out_file:
                out_file.write(gzip_file.read())

        with open(output_path, "r") as f:
            content = f.read()

        os.remove(output_path)
        return content

    def read_directly(file_path):
        with open(file_path, "r") as f:
            return f.read()

    def get_content_type(file_content):
        if '"type" : "scene",' in file_content:
            return "scene"
        elif '"type" : "preset_pose",' in file_content:
            return "pose"
        else:
            return None

    # Determine if it's gzipped
    is_compressed = is_gzip_file(file_path)

    if is_compressed:
        content = unzip_and_read_file(file_path)
    else:
        content = read_directly(file_path)

    # Determine the type of content (scene or pose)
    content_type = get_content_type(content)

    # Check if it's a scene with "Genesis" or the specific DAZ Horse 2
    if content_type == "scene":
        if "Genesis" in content:
            print_color("AR", "\nThis is a Genesis character file.")
            return True  # This was True before, change it to False if you want to block Genesis characters
        elif '"/DAZ%20HORSE%202.duf"' in content:
            print_color("AG", "\nThis is the DAZ Horse file, allowing function to continue.")
            return True
        else:
            print_color("AR", "\nThis is an Environment or Prop or Other file.")
            return False
    else:
        return False

Comments (5)

  1. Alessandro Padovani

    Personally i just check for the bone names to identify a specific daz rig, I’m not sure if there’s better ways.

  2. Thomas Larsson repo owner

    Daz files are just gzipped json files. Hence we can use the json module to load the file and then parse the content in python. E.g., the following script lists the urls of all nodes with geometries (so not bones):

    import json
    import gzip
    
    def list_file_urls(filepath):
        try:
            with gzip.open(filepath, 'rb') as fp:
                bytes = fp.read()
        except IOError:
            bytes = None
        if bytes:
            string = bytes.decode("utf-8-sig")
        else:
            with open(filepath, 'r', encoding="utf-8-sig") as fp:
                string = fp.read()
        struct = json.loads(string)
        scene = struct.get("scene", {})
        for node in scene.get("nodes", {}):
            url = node.get("url")
            if url:
                if node.get("geometries"):
                    print("URL", url)
    
    list_file_urls("D:/home/myblends/characters/aiko1/aiko-basic-wear.duf")
    

    The output is as follows:

    URL /data/DAZ%203D/Genesis%208/Female/Genesis8Female.dsf#Genesis8Female
    URL /data/DAZ%203D/Genesis%208/Female%20Eyelashes/Genesis8FemaleEyelashes.dsf#Genesis8FemaleEyelashes
    URL /data/DAZ%203D/Genesis%208%20Female%20Starter%20Essentials/Toulouse%20Hair/ToulouseHR.dsf#Genesis%202_35228
    URL /data/Bobbie25/Basic%20Wear/B25BWShorts/Shorts_19407.dsf#Shorts_19407
    URL /data/Bobbie25/Basic%20Wear/B25BWSportsBra/SportsBra_7768.dsf#SportsBra_7768
    

  3. Joe Morris @ FAST Animation Studio Toolz reporter

    OK thank you very much so my first idea because I like to do this before I import so I could cancel the operation if they selected the wrong selection on the panel and it wouldn't import a Genesis…. Is to download 10 non human characters and then look at their urls….please let me know if that's wrong…but thanks a lot for the advice I appreciate your approach.

  4. Log in to comment