Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    H2 generate Mat Texture settings?[Solved]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 310 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        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
        
        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

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

          1 Reply Last reply Reply Quote 0
          • First post
            Last post