H2 generate Mat Texture settings?[Solved]

On 16/11/2015 at 13:04, xxxxxxxx wrote:

Trying to set a Mat settings to open a image file from res?
It dont do that, it Just generate material with the settings but not the Texture Setting to the Imagine file.
What I am doing wrong?
PlZ Help GUYS!

-----------------------------------------------------------------------------------------------------------------------
CODE:
    def Execute(self, doc) :
#--| Generate MAT |--#
        Tex2K = c4d.BaseMaterial(5703)
        Tex2K[c4d.ID_BASELIST_NAME] = "2K Checker Tex"
        doc.InsertMaterial(Tex2K)

#--| OPEN THIS IMAGE from the Res Folder |--#
        filename_TEXpath = os.path.join(os.path.dirname(__file__), "res/CB_Textures", "UV Checkers Box -[2K Tex].png")

#--| SET MATERIAL SETTINGS |--#
        Tex2K[c4d.MATERIAL_PREVIEWSIZE]=11
        Tex2K[c4d.MATERIAL_USE_REFLECTION]=False
49    Tex2K[c4d.BITMAPSHADER_FILENAME]=filename_TEXpath

c4d.EventAdd()
        return True
-------------------------------------------------------------------------------------------------------------------------
Console Say:
Traceback (most recent call last) :
  File "'2K Checkers Texture.pyp'", line 49, in Execute
TypeError: __setitem__ expected int or bool, not str
-------------------------------------------------------------------------------------------------------------------------

Plz Help or Tips,
Ashton

On 17/11/2015 at 03:54, xxxxxxxx wrote:

Hi Ashton,

a standard Material has no parameter BITMAPSHADER_FILENAME, that's why your script fails.
Instead you need to allocate a Bitmap Shader, set the parameter there and then insert the shader into the material. An example can be seen on InsertShader().

In your case it could look like so:

    #--| Generate MAT |--#
    Tex2K = c4d.BaseMaterial(5703)
    Tex2K[c4d.ID_BASELIST_NAME] = "2K Checker Tex"
  
    #--| OPEN THIS IMAGE from the Res Folder |--#
    filename_TEXpath = os.path.join(os.path.dirname(__file__), "res", "CB_Textures", "UV Checkers Box -[2K Tex].png")
  
    shdBitmap = c4d.BaseShader(c4d.Xbitmap)
    if shdBitmap is None:
        print "Error: Shader allocation failed"
        return
    shdBitmap[c4d.BITMAPSHADER_FILENAME] = filename_TEXpath
  
    #--| SET MATERIAL SETTINGS |--#
    Tex2K[c4d.MATERIAL_PREVIEWSIZE] = 11
    Tex2K[c4d.MATERIAL_USE_REFLECTION] = False
    Tex2K[c4d.MATERIAL_COLOR_SHADER] = shdBitmap
    Tex2K.InsertShader(shdBitmap)
    doc.InsertMaterial(Tex2K)
    c4d.EventAdd()
    return

On 17/11/2015 at 06:09, xxxxxxxx wrote:

Thanks  Andreas it works! , really thanks man , your a hero! 
Cheers,
Ashton