Oh! No! I´m strikes again! :D

Home Page Forums General Chat Oh! No! I´m strikes again! :D

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1964880
    Abad
    Participant
    Rank: Rank 5

    Is there a script to optimize a .duf? I mean nodes with values (0,0), or (0,1) , which are not significant for "NOTHING"...
    If the duf format is a json, that information can be removed without affecting a pose, animation, etc., and less space in the file.
    While it can be done with "DSON editor", it's pretty boring.
    If not, I'll have to look for an "inquisitor" script for JSON, with the data to delete...
    A 3000Kb duf is not the same as a 100Kb duf... (Yes: It´s the same, but...)

    #1964882
    eelgoo
    Moderator
    Rank: Rank 7

    It might not be directly what you are looking for, but the free notepad++ is an useful tool.

    https://notepad-plus-plus.org/

    🙂

    #1964892
    Abad
    Participant
    Rank: Rank 5

    @eelgoo , yes. I´m a user of Notepad++, Visual Studio Code, or Wings for Python...

    Now, i´m try this:

    var json = { ... };
    var key = "0,0";
    delete json[key]; // Removes json.0,0 from the dictionary.

    I don't know if it will work well... Now I'm in the kitchen, preparing a "puchero", a meal "tipical spanish.."... https://www.youtube.com/watch?v=EDPkCu4xPro LOL
    I'll check it later...

    #1964923
    Richard Y.
    Participant
    Rank: Rank Overload

    I'm not aware of such a script but as for downsizing a duf file, just use 'Batch Convert' in Ds to compress it... not really needed to delete those code

    #1964967
    Abad
    Participant
    Rank: Rank 5

    Richard, or @windreaver0118 .Bad aswer. The DSON format is a JSON format. Then, in Notepad++, and a plugin called "JSson", you can "minifi" ( or exctact the "human reading" in a lines of code.) My "minifier" is only a python code, in a exe orPython 3 code..

    Daz Content Minifier (Repost?)*


    Now, i´m searching for "delete garbage" in DSON/JSON code...
    To compress, better isntall a "gzip.exe" for windows, but you need known all the commands..(Is a command line..., but it add a extension ".gz"...Then, rename, blah, blah, blah... -is used in Linux enviromments...-, never in Windows.., but Daz use "gzip".
    ¿really dont need delete this "trash" in the code???!!!

    #1964987
    Richard Y.
    Participant
    Rank: Rank Overload

    Not necessary to fight me back~ I just pointed a way. If I was mistaken, pls just ignore it, and take your time...

    #1965114
    Abad
    Participant
    Rank: Rank 5

    @windreaver0118 , dont worry. I hold my own pretty well with Python3. The problem is to convert code to "DazScript", which is too lazy, for me, to learn "their code" and it is very poorly documented (Barely...). On top of that, it uses QT, which has always seemed rubbish to me..., and install its framework... Puarfgghh! 😀
    I already studied how to decrypt the .dse to .dsa, not to bother, but to see "how" the code is. All "developers" need food.
    The hunger for knowledge overcomes us...

    #1965116
    Richard Y.
    Participant
    Rank: Rank Overload

    @abad
    Got it~ and I really learnt this word 'Puarfgghh'~ ~ 😆

    #1965151
    Vanimoch3dx
    Participant
    Rank: Rank-1

    Using Python you should be able to use the JSON library to do this job, likely you did this already. I opened a few .duf files but I have no clue where one could save space, except of removing all unnecessary white-space and formatting as these files don't need to be formatted in a human-readable way. I assume your Minifier does this already.
    'mCasual/Jacques' has many Daz scripts on his site which might be interesting but coding in the Daz IDE is not really fun.

    #1965171
    Abad
    Participant
    Rank: Rank 5

    @vanimoch3dx, Indeed. Is a simple script in Python3...
    ----------------
    #!/usr/bin/env python

    import sys
    import os
    import os.path
    import json
    ################
    # os.startfile("reduf.exe")

    ################################################################################
    def parse_args(argv):
    options = {}
    if len(sys.argv) > 1:
    options['input'] = sys.argv[1]

    if len(sys.argv) > 2:
    options['output'] = sys.argv[2]

    return options

    ################################################################################
    def validate_options(options):
    if not 'input' in options:
    raise RuntimeError("No [input] argument was provided")

    if not (os.path.isfile(options['input']) or os.path.isdir(options['input'])):
    raise TypeError("[input] '" + options['input'] + "' is not a file or directory")

    if 'output' in options and os.path.isdir(options['input']) and not os.path.isdir(options['output']):
    raise TypeError("[output] '" + options['output'] + "' must be a directory because [input] is a directory")

    ################################################################################
    def print_help_and_exit():
    sys.stdout.write("usage: " + os.path.basename(__file__) + " [input] [output]\n")
    sys.stdout.write("Where [input] => path to dsf or duf file or directory\n")
    sys.stdout.write(" [output] => path to output file or directory\n\n")
    sys.exit(2)

    ################################################################################
    def print_error_and_exit(message):
    sys.stderr.write(message + "\n")
    sys.exit(1)

    ################################################################################
    def create_path(path):
    abs_path = os.path.abspath(os.path.dirname(path))
    if not os.path.exists(abs_path):
    os.makedirs(abs_path)

    ################################################################################
    def minify_file(input_filepath, output_path):
    try:
    filepath = os.path.abspath(input_filepath)
    json_txt = open(filepath, 'r').read()
    json_mini = json.dumps(json.loads(json_txt), separators=(',', ':'))

    if len(output_path) > 0:
    out_file = os.path.abspath(output_path)
    create_path(out_file)
    open(out_file, 'w').write(json_mini)

    else:
    sys.stdout.write(json_mini)

    except Exception as e:
    sys.stderr.write(str(e) + "\n")

    ################################################################################
    def find_json_files(input_dir):
    search_results = []
    search_root = input_dir
    for root, directories, files in os.walk(search_root):
    for filename in files:
    if os.path.splitext(filename)[1] == '.dsf':
    relative_path = os.path.relpath(root, search_root)
    search_results.append(os.path.join(relative_path, filename))
    if os.path.splitext(filename)[1] == '.duf':
    relative_path = os.path.relpath(root, search_root)
    search_results.append(os.path.join(relative_path, filename))
    return search_results

    ################################################################################
    def minify_dir(dir_in, dir_out):
    abs_dir_in = os.path.abspath(dir_in)
    files = find_json_files(abs_dir_in)
    for relative_filepath in files:
    file_in = os.path.join(abs_dir_in, relative_filepath)
    file_out = ""
    if len(dir_out) > 0:
    file_out = os.path.join(dir_out, relative_filepath)

    minify_file(file_in, file_out)

    ################################################################################
    options = parse_args(sys.argv)

    try:
    validate_options(options)

    except Exception as e:
    sys.stderr.write(str(e) + "\n")
    print_help_and_exit()

    try:
    output = options['output'] if 'output' in options else ""

    if os.path.isfile(options['input']):
    minify_file(options['input'], output)

    elif os.path.isdir(options['input']):
    minify_dir(options['input'], output)

    except Exception as e:
    print_error_and_exit(str(e) + "\n")
    ---------------------
    No more... (Of course, you need install the module "json".. I dont remeber the version..! 😀 https://pypi.org/search/?q=json
    I think is this: https://pypi.org/project/json5/

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

 

Post You Might Like