Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
On 26/08/2018 at 07:20, xxxxxxxx wrote:
hi there,
is it possible to find the shader slot in a material for a given shader?
i.e. if i have this setup Mat[c4d.MATERIAL_USE_COLOR] = some_shader
can i find c4d.MATERIAL_USE_COLOR if i have only Mat and some_shader?
--> I'd need something like: findSlot(Mat, some_shader) # 2000 (c4d.MATERIAL_USE_COLOR)
best, index
On 27/08/2018 at 11:29, xxxxxxxx wrote:
Hi index,
welcome to the Plugin Café forums
Unfortunately no, there is no such function. If the shader setup is simple enough, you could just have an array with parameter IDs and then compare the linked shaders in your own FindSlot() function. A bit more complicated it gets, if the shader setups can be more complicated, including sub-shaders, like e.g. layer shader. Then you have to additionally iterate the shader tree for each slot.
On 28/08/2018 at 02:22, xxxxxxxx wrote:
tx andreas, an exciting world
i got a bit further with my findSlot(Mat, some_shader) and dont understand why i get Attribute Errors when i iterate over a bc:
def findSlot_v1(sh) : # sh = some shader already inserted in a material slot bc = mat.GetDataInstance() for i, v in bc: print i, v if v == sh: return i
--> AttributeError: Parameter value not accessible (object unknown in Python)
def findSlot_v2(sh) : # sh = some shader already inserted in a material slot bc = mat.GetDataInstance() for i, v in bc: try: if v == sh: return i except AttributeError: pass
def findSlot_v3(sh) : # sh = some shader already inserted in a material slot bc = mat.GetDataInstance() for i in range(len(bc) - 1) : try: index = bc.GetIndexId(i) if op[index] == sh: return index except AttributeError: pass
--> this finally works
but could anybody tell me why i get these strange AttributeErrors ?
the first version is straight from the book: https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d/BaseContainer/index.html?highlight=basecontainer#BaseContainer.__iter__
and... i guess there no nicer/faster solution without iterating over the complete bc?