I've being trying to create a textile comprising of a sizable number of warps and wefts and I want to specify a specific colour of each yarn. How is this achieved in python?
thanks
Setting yarn colour in python
Moderators: Martin, Developers
I just added a function to set the yarn color, of course you'll need to compile the latest SVN version for it to work. Once install you can set the yarn colors from the GUI interactive python console like this:
This sets the yarn with index 0 to magenta.
Code: Select all
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(1, 0, 1))
Just trying out this new feature in 3.2.1
You are not limited to the default colours of TexGen (i.e. 0,0,0 = Black, 0,1,0 = Green, 1,1,1 = White etc).
You can actually input RGB values to get the colour you require:
so instead of using:
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(1, 0, 1))
use:
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(180, 215, 218))
A nice RGB calculator can be found here;
http://www.calculatorcat.com/free_calcu ... ider.phtml
Hope it helps.
You are not limited to the default colours of TexGen (i.e. 0,0,0 = Black, 0,1,0 = Green, 1,1,1 = White etc).
You can actually input RGB values to get the colour you require:
so instead of using:
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(1, 0, 1))
use:
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(180, 215, 218))
A nice RGB calculator can be found here;
http://www.calculatorcat.com/free_calcu ... ider.phtml
Hope it helps.
Yes that's right you're not limited to black, green, white... but the red, green, blue parameters to the COLOR structure should be given in the range from 0 to 1 and not 0 to 255. So the following works:
but the following would be recognised as white:
(Note: Just divide the value by 255 to get it in the range 0 to 1)
Code: Select all
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(0.7, 0.85, 0.85))Code: Select all
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(180, 215, 218))Hi Martin,
I'm trying to write a python script for a specific fabric and want to include the "yarn colour function" directly into the code.
The colour function works great when I use it in the python console of Texgen (for example).
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(0.7, 0.85, 0.85))
However, if I include the above code into my python script, I get the error message:
rw.SetYarnColor(1, COLOR(0.7, 0.85, 0.85))
AttributeError: 'NoneType' object has no attribute 'SetYarnColor'
I'd be grateful for any pointers and advice.
Cheers
I'm trying to write a python script for a specific fabric and want to include the "yarn colour function" directly into the code.
The colour function works great when I use it in the python console of Texgen (for example).
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(0.7, 0.85, 0.85))
However, if I include the above code into my python script, I get the error message:
rw.SetYarnColor(1, COLOR(0.7, 0.85, 0.85))
AttributeError: 'NoneType' object has no attribute 'SetYarnColor'
I'd be grateful for any pointers and advice.
Cheers
Did you include both lines?
Perhaps you could post the entire script so I can see what the problem might be.
In any case the error you are seeing indicates that the call to "GetRenderWindow()" is returning "None". This is probably because the render window doesn't exist yet at the time you called that function. You should make sure this part of the code comes after the AddTextile() call.
Code: Select all
rw = GetRenderWindow()
rw.SetYarnColor(0, COLOR(0.7, 0.85, 0.85))In any case the error you are seeing indicates that the call to "GetRenderWindow()" is returning "None". This is probably because the render window doesn't exist yet at the time you called that function. You should make sure this part of the code comes after the AddTextile() call.