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


Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#1
I'm trying to build a library of game-ready parts for use in video games, and would like a library of low-poly bricks to fall back on for bricks I have not yet converted by hand. I've dug around and tried a few methods so far, but all have failed to work.

LdrDat2Obj: Processes 1,466 dats out of the 14,038 in ldraw's parts directory, and then exits silently with no error or log. the last brick it appears to process is 22385p050.dat It processes the parts in an order I can't decipher, so skipping this last brick and moving on isn't possible.

LdrDat2Obj2: no apparent batch process

Toby Nelson/TobyLobster's blender importer: seems to work well, but only allows one .dat to import at a time - that's not workable with 14,000 parts.

Matthew Morrison's blender importer: Crashes every time I try to import a .dat file. I posted more details about the crash in his thread: https://forums.ldraw.org/thread-24153.html

LDView: no apparent batch process

Stud.IO: no way I can see to create a file that contains each brick once.

If I could get the ldraw parts into any conventional 3D model format I would be able to batch convert the results into something game engines can use, including obj, fbx, stl, dae, and -probably- usd.
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#2
What about using LDView on the command line and build a batch processing aroudn it?
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#3
(2021-08-22, 12:45)KristyB Wrote: LDView: no apparent batch process

LDView itself does not support globbing (*.dat, for example), but it can be called from a batch file that does. It supports command line exports to POV, STL (monochrome output), and 3DS. Please search for ExportFiles, SaveExportType, and ExportSuffix in LDView's help file for instructions on using it.
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#4
(2021-08-22, 21:39)Travis Cobbs Wrote: LDView itself does not support globbing (*.dat, for example), but it can be called from a batch file that does. It supports command line exports to POV, STL (monochrome output), and 3DS. Please search for ExportFiles, SaveExportType, and ExportSuffix in LDView's help file for instructions on using it.
Thank you both for the suggestion!

Iterating through a list that both skips numbers and has arbitrary letters sprinkled in with the numbers seems a bit daunting, and my experience with bats file is less than rudimentary. I'm also not sure what globbing is in this context. It might take me a good while, so if anyone has other suggestions while I tinker with it I'd be glad to hear them too.
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#5
It occurs to me I can also use Python in in blender to script the import/export process, maybe? I'm already pretty familiar with Python, and Toby Nelson's .dat import options would allow me to automate the high-poly making process for a lot of the Bricks. I am going to try this route first before looking at LDView.
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#6
(2021-08-23, 11:22)KristyB Wrote: Thank you both for the suggestion!

Iterating through a list that both skips numbers and has arbitrary letters sprinkled in with the numbers seems a bit daunting, and my experience with bats file is less than rudimentary. I'm also not sure what globbing is in this context. It might take me a good while, so if anyone has other suggestions while I tinker with it I'd be glad to hear them too.

A simple batch file like
 
Code:
for %%f in (*.dat) do call ldview....

Should do. 

Please note, I did not try this and you would need to specify the filename (especially the ecport name) also in the ldview command string.

Add an 'echo'to see the progress
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#7
(2021-08-22, 12:45)KristyB Wrote: I'm trying to build a library of game-ready parts for use in video games, and would like a library of low-poly bricks to fall back on for bricks I have not yet converted by hand. I've dug around and tried a few methods so far, but all have failed to work.

LdrDat2Obj: Processes 1,466 dats out of the 14,038 in ldraw's parts directory, and then exits silently with no error or log. the last brick it appears to process is 22385p050.dat It processes the parts in an order I can't decipher, so skipping this last brick and moving on isn't possible.

LdrDat2Obj2: no apparent batch process

Toby Nelson/TobyLobster's blender importer: seems to work well, but only allows one .dat to import at a time - that's not workable with 14,000 parts.

Matthew Morrison's blender importer: Crashes every time I try to import a .dat file. I posted more details about the crash in his thread: https://forums.ldraw.org/thread-24153.html

LDView: no apparent batch process

Stud.IO: no way I can see to create a file that contains each brick once.

If I could get the ldraw parts into any conventional 3D model format I would be able to batch convert the results into something game engines can use, including obj, fbx, stl, dae, and -probably- usd.

Are you still getting the crash? I've pushed a few updates since you posted the error report.
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#8
i got it to work with this:

@echo off
set sourcedir=F:\ldview iter test\parts
set exportdir=F:\ldview iter test\stlexp

for %%f in ("%sourcedir%\*.dat") do (
    "E:\LEGO\LDraw suite\LDView\LDView64.exe" -ExportFile="%exportdir%\%%~nf.stl" "%%f"
)


but for some reason its exporting parts super small
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#9
(2023-06-23, 5:34)Kuemmerle Wrote: i got it to work with this:

@echo off
set sourcedir=F:\ldview iter test\parts
set exportdir=F:\ldview iter test\stlexp

for %%f in ("%sourcedir%\*.dat") do (
    "E:\LEGO\LDraw suite\LDView\LDView64.exe" -ExportFile="%exportdir%\%%~nf.stl" "%%f"
)


but for some reason its exporting parts super small

Try doing an STL export from the LDView UI, then go to the export options and check the units. Choose and appropriate unit and export to verify. The command line should use the most recently selected units from LDView UI.
Reply
RE: Help converting -all- .dat parts to fbx/obj/stl/usd/anyConventionalFileFormat
#10
(2023-06-23, 17:13)Travis Cobbs Wrote: Try doing an STL export from the LDView UI, then go to the export options and check the units. Choose and appropriate unit and export to verify. The command line should use the most recently selected units from LDView UI.

That worked, thanks so much.
Reply
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 »



Forum Jump:


Users browsing this thread: 3 Guest(s)