cuddlyogre / ExportLDraw

LDraw Import and Exporter for Blender 2.82+
GNU General Public License v2.0
49 stars 12 forks source link

Automate import via python script #47

Open tnindd opened 9 months ago

tnindd commented 9 months ago

I want to automate the process of importing the ldr file and exporting it to another file. I tried the following line for importing:

bpy.ops.ldraw_exporter.import_operator(ldraw_path="d:\\test.ldr", studio_ldraw_path="C:\\Program Files\\Studio 2.0\\ldraw")

But I receive two errors:

missing LDCfgalt.ldr
missing 

======Import Complete======

Part count: 0
elapsed: 0.03504189999875962
===========================

{'FINISHED'}

I can switch off the colors by adding the additional parameter:

use_alt_colors=False

Which removes the first "missing" error but the second remains. And switching off the color-option seems not a professional way of solving this error.

How to correctly solve these errors?

cuddlyogre commented 9 months ago

Stud.io doesn't have a LDCfgalt.ldr file. Try setting use_alt_colors to false and see if that works.

tnindd commented 9 months ago

That only removes the first "missing" line, but not the second.

cuddlyogre commented 9 months ago

It looks like you're using the model's path as the ldraw_path.

Try this format. bpy.ops.ldraw_exporter.import_operator(filepath="d:\\ldraw\\models\\car.ldr", ldraw_path="d:\\ldraw", studio_ldraw_path="C:\\Program Files\\Studio 2.0\\ldraw")

If you don't have the official LDraw library: bpy.ops.ldraw_exporter.import_operator(filepath="d:\\ldraw\\models\\car.ldr", studio_ldraw_path="C:\\Program Files\\Studio 2.0\\ldraw")

tnindd commented 9 months ago

Yes, that worked, thank you!

If anyone else has the same problem, here is the python script for automatically converting ldraw to collada:

import bpy
bpy.ops.ldraw_exporter.import_operator(filepath="d:\\Car.ldr", ldraw_path="c:\\Users\\Public\\Documents\\LDraw", studio_ldraw_path="C:\\Program Files\\Studio 2.0\\ldraw")
bpy.ops.wm.collada_export(filepath='d:\\Car.dae')

Call it on the command line with:

"c:\Program Files\Blender Foundation\Blender 4.0\blender.exe" --background --python "d:\Car.py"