Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat


RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#11
after making that, i also made this python script to rename everything if u want:

Code:
import os
import re
import shutil

def rename_files(dir_path):
    print(f"Looking for .dat files in {dir_path}...")
    for filename in os.listdir(dir_path):
        print(f"Found file: {filename}")
        if filename.endswith('.dat'):
            filepath = os.path.join(dir_path, filename)
            with open(filepath, 'r') as file:
                first_line = file.readline()
                file.close()  # Manually closing the file after reading the first line
                match = re.match(r"^0\s+(.*)", first_line)
                if match:
                    part_name = match.group(1).strip()
                    part_name = part_name.replace('/', '-')  # Replace forward slashes with hyphens
                    part_name = re.sub(r'[<>:"|?*]', '', part_name)  # Remove illegal characters
                    part_name = part_name.replace('(', '').replace(')', '')  # Remove parentheses
                    new_name = part_name.replace(' ', '_') + f'_id-{filename[:-4]}'
                    new_name = (new_name[:97] + '...') if len(new_name) > 100 else new_name  # Ensure filename is not too long
                    new_name += '.dat'
                    new_path = os.path.join(dir_path, new_name)
                    print(f"Old name: {filename}")
                    print(f"First line: {first_line.strip()}")
                    print(f"Extracted part name: {part_name}")
                    print(f"New name: {new_name}")
                    try:
                        shutil.copy2(filepath, new_path)  # Copy the file
                        os.remove(filepath)  # Remove the old file
                    except Exception as e:
                        print(f"Failed to rename {filepath} to {new_path}. Error: {str(e)}")

# Use the function on your directory
rename_files('F:\\ldview iter test\\parts')


This just reads the metadata in the.dat files before converting to stl and appends it to the file name
Reply
« Next Oldest | Next Newest »



Messages In This Thread
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat - by Kuemmerle - 2023-06-24, 1:02

Forum Jump:


Users browsing this thread: 1 Guest(s)