Author Topic: Assigning variables to export textures output template [JS]  (Read 1961 times)

Greetings and well met,
I'm trying to add a variable similar to `$mesh` and `$textureSet`. I can't find in the documentation a way to add to the output template.

Anyone have any success in this?

I'm grabbing the current selected layer and i'd like to append that to the output maps available variables. I'm not sure the repo etiquette but I do have a repo grabbing the selected layer.

Cheers
Last Edit: October 20, 2020, 05:36:18 am

Hi,

If i understand correctly you want to specify a new keyword for our export template from the scripting API. If so, this is not possible.

Can you give me details on your use case to see if i can propose an alternative ?

Can you also tell me which scripting API you are using ? JS or Python ?

Thx !
Senior Software Engineer
Substance Painter Team
@achassany

Hey Alexandre!

Thank you for the response. Yes, i'd like to pass the `$selectedLayer` into the export options so when I export I can append that to the exported file names. I'll create a imgur picture to show you what I'm intending to do. I've got a repo with the ability to have the selected layer which I can put here. I'm using JS but it seems like this notion can be achieved in python though I cannot corroborate this. https://imgur.com/a/C1Cl2MG <- imgur link of what i'd like to do in the exports.

I used the javascript plugin skeleton: https://github.com/mattattaq/substance_painter_layer_append_on_export/blob/main/main.qml#L78-L128
Last Edit: October 26, 2020, 03:21:04 am

Thanks for the details,

Just to make sure i understand properly. Do you want to export only the content of the selected layer ? Or the whole textureSet ?

Because the hook you use onExportAboutToStart() is called with the textures that are going to be exported from the export dialog. And from this dialog we can't export a single layer, we only export maps that come from the composited layer stack (and textureSet mesh maps).

Thx
Senior Software Engineer
Substance Painter Team
@achassany

I'd like to grab the string that is the selectedLayer's name so when I export I can append that string to the file name so as to make my exports a bit more specific in my naming convention so I don't have to update the names after exporting effectively adding a few seconds to my flow each export.

I've traversed the layers and i'm able to grab the string shown in this github link:
https://github.com/mattattaq/substance_painter_layer_append_on_export/blob/66baef5ed3a4245a4a980b14e4191902736f2732/main.qml#L78-L112

Thank you for your reply,
Cheers
Matthew

Hey Alexandre Chassany,

I just wanted to follow up again to see if you had any more clarity on this issue.

Cheers,
Matt

Sorry for the delay it was a busy week :/.
So if i understood correctly, what i would try to do is use the other signal "onExportFinished()" and rename the exported files adding the name of the selected layer.
In onExportFinished(), for each stack exported, get the name of the selected layer (like you do in onExportAboutToStart()), transform the file paths of the exported maps to add the name of the layer, then use the  alg. subprocess module to call the external tool of your platform to move files (MOVE on windows and mv on unix).

Cheers
Alex
Senior Software Engineer
Substance Painter Team
@achassany

No problem Alexandre,
I appreciate the response! The thing i'm unclear on is how to transform the file paths. Is there is a link in the documentation you should share that would illuminate that? Either that or if you know of a better way to relay that info i'm game.

Thanks again for the response,
Cheers
Matthew
Last Edit: November 16, 2020, 06:58:19 pm

Sorry for the delay it was a busy week :/.
So if i understood correctly, what i would try to do is use the other signal "onExportFinished()" and rename the exported files adding the name of the selected layer.
In onExportFinished(), for each stack exported, get the name of the selected layer (like you do in onExportAboutToStart()), transform the file paths of the exported maps to add the name of the layer, then use the  alg. subprocess module to call the external tool of your platform to move files (MOVE on windows and mv on unix).

Cheers
Alex

hope your holidays were pleasant Alexandre, I was hoping to reach out again on the documentation on the subprocess module to call the external tool of my platform to move files.

Cheers,
mattatttaq

The problem I'm solving right now is very close to mattatttaq problem.

I need to have different variations of textures for the same object. Variations organized in a specific folder as layers so toggling one represents a selection of a specific variant. Basically, the process is to enable a single subfolder in the variant folder then export textures then manually rename it to have a specific texture set for a specific variant. Unfortunately, it is impossible to iterate thru the whole folder via script. So I need to manually export each variation. I'm using a specific variable in the export preset such as $variant as a placeholder for the actual variant name. Then calling subprocess to rename files after export.

Found some problem with alg.subprocess.start
Code: [Select]
let commandPrefix = "cmd.exe /k"
let command = "move /y"
let source = convertFilenameToWindows(file)
let target = convertFilenameToWindows(file.replace(variant, variantValue))
let execution = `${commandPrefix} ${command} \"${source}\" \"${target}\"`
alg.log.info(execution)
alg.subprocess.start(execution, exportCallback)

When executing cmd.exe with parameters it is not returning any status of execution and not triggering a callback so it continues the execution loop.
As a result when saving after export (which is successful with moving and etc.) Substance Painter process halting.

There is a second approach. Basically, get document structure in JS API  -> get UV tile data from python API -> pass it thru WebSocket to python plugin -> custom export with config dictionary in python. But it is a bit painful rather than just inconvenient. Also, there is no tool to work with export presets which is binary data. Finally, it is impossible to reproduce a fully functional texture exporter which mentioned many times across the forum threads regarding scripting and APIs.

So it would be great you guys share some roadmap regarding API improvement and maybe some estimations because such lame solutions to a problem are not very viable.

Cheers,
Alex
Last Edit: March 24, 2021, 11:27:07 pm