Hi Hilary,
You already got further than me so interesting to follow this for me. I saw a KeyShot presentation today and maybe you can contact the guy from the presentation (email at the end). They are also working on scripting 100s of materials for their Speedo sunglasses.
Interesting presentation and at 21:57 (should start at this time) you’ll see what they are currently working on: KeyShot World LA 2023 - Speedo X KeyShot - Alex Moy - YouTube
[edit]
Had some trouble viewing the image with the link in your post, not sure why. Hope this helps (for others as well)
About the script, I’m sure someone can help you with some actual code but the part which I think needs some changes is the part from here, line 185:
for file in os.listdir(importFolder):
I’ll try to explain what happens in my best English.
Currently it loops x-times (number of files in directory) through the loop and within that loop it loads each file and changes the variable for the materialTemplate 10 times (for each file, line 213-222) and since ‘BV’ is the last value of the template that will also be the one template that actually gets rendered (together with all models on top of eachother).
What you actually want is that it uses the queue and maybe the templates that should be used are based on part of the filename.
To have it use the queue I think you need something like this:
**setAddToQueue** (...)
Instead of rendering immediately then it will be added to the internal KeyShot queue, waiting for processing. Note that a copy of the scene will be saved to disk each time. Call *lux.[processQueue](https://media.keyshot.com/scripting/doc/10.2/lux.html#-processQueue)()* to process the queue and render what has been added to it.
add = Whether to add to queue or not. *
Together with this you need to build in some logic like a conditional statement that looks at a part of the filename and sets the right material template. If it’s not based on the filename you could for example put all those template names in an array and use a counter to go through them and it’s also handy I think to have the template-name in the filename as well.
Within the loop you also need a ‘clean’ part. where you delete the other table top or entire scene. I don’t know which code would be handy for it but a logical place to put it is after the file gets transferred to the queue. That way it can load the next table top at the top of the loop again and start with a clean slate.
And than after it looped through all your files it will exit the loop en go to line 237 and line 240 to process the queue.
Like said earlier, I’ve no experience with Python but I think it might help a bit if you see what is happening and why it behaves like it does. I’m sure some can explain better or offer some code as well.
Once you get the logic of the code a bit it’s also easier to think what’s the most smart way to all the different models you want to render. Especially if for example product codes already have certain logic like model X starts with AB in the code, you can use such things hat again in your scripts which can save you even more work.
When I did some PHP/javascript code I liked to draw kind of schedules on a piece of paper so I got a bit of a clear view on how it should run through a bunch of files. If you have for example 10 different tops with 10 materials you could basically render 100 products with a few lines of code. And if only the material changes you just need the 10 different table tops and have the materials inside KeyShot.
I’m more a picture guy than a coder but with some loops and arrays to store values you get far. That modelList for example which in this script holds all filenames.
Hope this was not too confusing, I tried to make things a bit clear. With your post my hands do itch a bit to try to fix some myself as well to get some renders done, just to see how it works.