Author Topic: Script for multiple colorways help  (Read 9333 times)

0 Members and 1 Guest are viewing this topic.

Offline maf1909

  • Newbie
  • *
  • Posts: 37
Script for multiple colorways help
« on: May 18, 2016, 01:30:01 pm »
I'm trying to create a set of images for our web team, and am a bit lost on how to make the following happen:

1. Turn on only a specific group of parts (in this case I have "frame" and "body" as the two groups of parts)
2.  Apply a material to that group of parts (I've got 114 different materials to apply...57 paints in 2 finishes)
3. Put that image in a filepath depending on the finish (gloss or matte) and the part with the file name being the material name (candy_apple, diamond, etc.).  For example, a Candy Apple gloss frame would go in ...\parts\gloss\frame under the name "candy-apple"
4. Repeat for all the parts/colors/finishes

I read through most of the threads on this board and got some ideas, especially from this thread: https://www.keyshot.com/forum/index.php?topic=11656.0, especially "ryanfenik's" post with the cube example, and I can kind of get it to work.  My problem arises in not knowing how to make it call a material from a certain folder if I have the same named material in multiple folders ("candy_apple" in gloss folder and in matte folder, different material though).

I'm a relative novice to coding, but do have enough background in it between simple websites and some stuff in college to understand the gist of it.


Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #1 on: May 22, 2016, 01:31:27 am »
My first advice would be to make sure you have unique names for all materials. This is a good practice in general.
So maybe you can name the shiny and matte finishes 'candy_apple_shiny' and 'candy_apple_matte' respectively.
And maybe it's even better to have a unique identifier at the beginning, so that the result is like 'Wookiee_candy_apple_shiny'. 'Wookiee' could be the prduct name... :)

It would be easier if we could work from there.

Dries

Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #2 on: May 22, 2016, 08:45:30 am »
Here is my attempt at doing this...
See attached for a sample scene, material package and script.
If you wish to test this sample, then please import the material package in KeyShot first.

So here is how I thought this could work...

The idea is to embed the name of the colorway into the material names. So for a colorway 'Wookiee', the materials are named 'Wookiee_blue_shiny', 'Wookiee_orange_shiny' etc.
You can enter the name of the colorway in the script. The script will find all materials with a name that contains the colorway name.
You can enter the name of the groups/parts that the colorways should be applied to.
So in this case, all the 'Wookiee' materials in the library will be applied to all parts in the scene with name 'Jedi'. (Sorry, I am in a Star Wars mood today... ;D).
You can also specify a suffix.
The image filenames will look something like this: 'Colorways-test_2016-05-22_Wookiee_blue_shiny.png'

I provided a few additional options:
- Select a Lighting Preset from a combobox.
- Set resolution.
- Set quality as amount of maximum samples.
- Add to Queue.
- Process Queue after the script is finished.
- Reload the scene.

Let me know how this works for you.
It is not exactly what you asked for, but this should get you started. :)

Dries
« Last Edit: May 22, 2016, 08:59:38 am by DriesV »

Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #3 on: May 22, 2016, 09:23:55 am »
Okay, I changed the script a little...

Now when rendering, only the specified parts will be shown.
You can now render all combinations by running the script twice, for 'frame' and 'body'.

Dries

Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #4 on: May 22, 2016, 09:31:59 am »
OK, last change for today...
I added a checkbox to enable/disable hiding of other parts.

Dries

Offline LayC42

  • Sr. Member
  • ****
  • Posts: 358
  • mostly harmless
Re: Script for multiple colorways help
« Reply #5 on: May 22, 2016, 12:38:08 pm »
Many thanks Dries!!!

Offline Will Gibbons

  • Hero Member
  • *****
  • Posts: 2846
  • willgibbons.com
    • My Website
Re: Script for multiple colorways help
« Reply #6 on: May 23, 2016, 06:52:54 am »
This is awesome! I just started learning about scripting and have a long way to go, but the power of it is always impressive.

Offline maf1909

  • Newbie
  • *
  • Posts: 37
Re: Script for multiple colorways help
« Reply #7 on: May 24, 2016, 11:47:06 am »
Thanks a ton Dries!  That worked like a charm.  Only thing I don't like is how the files are named, would prefer just the color to be the name since they need to go in their own folders anyway.  But I found a quick little tool to rename all the files at once, so that fixed that!

I did run into one little issue.  Even though you can type in what resolution you want to render the images at, it still appears to be dependent on the viewport resolution in keyshot.  The first time I ran it the images came out at the right resolution according to the details of the file, but the visible portions of the image were definitely not that resolution.  Just a weird little thing to watch out for
« Last Edit: May 24, 2016, 11:49:05 am by maf1909 »

guest84672

  • Guest
Re: Script for multiple colorways help
« Reply #8 on: May 24, 2016, 10:28:39 pm »
The render resolution will be dependent on the aspect ratio set in the image tab.

Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #9 on: May 25, 2016, 12:05:16 am »
...
Only thing I don't like is how the files are named, would prefer just the color to be the name since they need to go in their own folders anyway.
...
Well, you can always change the script so that it only sets the material name as the file name.  :)
And then you could also add some conditional statements to put the images in different folders depending on the material name.  ;)

...
Even though you can type in what resolution you want to render the images at, it still appears to be dependent on the viewport resolution in keyshot.  The first time I ran it the images came out at the right resolution according to the details of the file, but the visible portions of the image were definitely not that resolution.
That is weird, as resolutions explicitly set through scripting should always be respected for rendering.
Can you show some examples of what you are seeing?

The render resolution will be dependent on the aspect ratio set in the image tab.
This is true for regular offline rendering, but not for rendering through scripting when you explicitly set the height and width of the image.
Like this:
Code: [Select]
width = 1920
height = 1080
lux.renderImage(width = width, height = height)

Dries

Offline maf1909

  • Newbie
  • *
  • Posts: 37
Re: Script for multiple colorways help
« Reply #10 on: May 25, 2016, 06:40:03 am »

Well, you can always change the script so that it only sets the material name as the file name.  :)
And then you could also add some conditional statements to put the images in different folders depending on the material name.  ;)


I tried setting the script to make only the material the file name, and it would go through the process of rendering the image and then not actually put the image anywhere.  I assume I did it wrong, but this method works too.  Either way, since I had to make the materials a different name (xx_gloss and xx_matte), I have to go through and remove that anyway.

Quote
That is weird, as resolutions explicitly set through scripting should always be respected for rendering.
Can you show some examples of what you are seeing?

The render resolution will be dependent on the aspect ratio set in the image tab.
This is true for regular offline rendering, but not for rendering through scripting when you explicitly set the height and width of the image.
Like this:
Code: [Select]
width = 1920
height = 1080
lux.renderImage(width = width, height = height)

Dries

The "2560x1536.png" file was rendered offline, with the ratio in the image tab set to 1280x768 (half the final output).  The "1000x800 to 2560x1536.png" was rendered through the script, with the image tab set to 1000x800, and the resolution in the script set to 2560x1536.  Both come out the same resolution according to the details of the file, but if you try to layer them so the first image sits on top of the second image, they're clearly not the same, as you can see in the "layered.png"

guest84672

  • Guest
Re: Script for multiple colorways help
« Reply #11 on: May 25, 2016, 04:20:23 pm »

The render resolution will be dependent on the aspect ratio set in the image tab.
This is true for regular offline rendering, but not for rendering through scripting when you explicitly set the height and width of the image.
Like this:
Code: [Select]
width = 1920
height = 1080
lux.renderImage(width = width, height = height)

Dries
[/quote]

But you don't want to do this, because the camera may not match. This is why we disabled this in the render tab, so you can only enter a value that is a multiple of the aspect ratio.

And this shows in @maf1909's example. Your aspect ratio in the realtime window is 1.25, while your output resolution has an aspect ratio of 1.6667. Your camera has shifted.

Try that in the realtime window and you will see what happens with the camera.

KeyShot is not like other rendering applications where you can set up a render window of your scene. Maybe that's where the confusion comes in.

Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #12 on: May 26, 2016, 05:30:05 am »
As long as the camera hasn't changed and no transformations have been done in the script, the images should always overlap when rendered at the same resolution.

@ maf1909:
Are these parts (black & red) from 2 different scenes?
Are they positioned to be aligned perfectly?
Are the camera settings identical for both scenes?

If those conditions are met, then the renderings should align perfectly, when rendered at the same resolution through the script, regardless of the aspect ratio in realtime.
You can test this with attached simple scenes. The scenes are identical (geometry and camera), except for the aspect ratio. When rendered at the same resolution through the script, they align perfectly.

Of course, as soon as the camera is adjusted in one of the scenes, the images won't match.

Dries

Offline maf1909

  • Newbie
  • *
  • Posts: 37
Re: Script for multiple colorways help
« Reply #13 on: May 26, 2016, 06:27:16 am »
As long as the camera hasn't changed and no transformations have been done in the script, the images should always overlap when rendered at the same resolution.

@ maf1909:
Are these parts (black & red) from 2 different scenes?
Are they positioned to be aligned perfectly?
Are the camera settings identical for both scenes?

If those conditions are met, then the renderings should align perfectly, when rendered at the same resolution through the script, regardless of the aspect ratio in realtime.
You can test this with attached simple scenes. The scenes are identical (geometry and camera), except for the aspect ratio. When rendered at the same resolution through the script, they align perfectly.

Of course, as soon as the camera is adjusted in one of the scenes, the images won't match.

Dries

The parts are from the same scene, the black is designed to be a foreground layer since it's the fabric and rubber for that particular product. 

The camera is locked, the only change I made was the resolution under the "image" tab.

Offline DriesV

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2412
  • Product Specialist at Luxion
Re: Script for multiple colorways help
« Reply #14 on: May 26, 2016, 07:15:42 am »
Can you share the scene?
You can use keyshot.wetransfer.com. Send to dries@luxion.com.

Dries
« Last Edit: May 26, 2016, 07:20:43 am by DriesV »