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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Art shader, or load from content browser ?

    PYTHON Development
    0
    3
    1.8k
    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
      Helper
      last edited by

      On 30/08/2018 at 02:01, xxxxxxxx wrote:

      Hi,

      First off I'm new here, and also very new with python.
      I'm trying to create a pretty basic material using python, but it seems not so easy.

      I have two questions:
      How can I add the Art shader to a channel?

      It's not listed in the SDK shader list.
      So it's probably not like I'm just missing the right word here, is it ?

      > matt[c4d.MATERIAL_USE_LUMINANCE] = True
      >
      > Art = c4d.BaseList2D(c4d.X...something.....)
      >
      > matt.InsertShader( Art )
      >
      > matt[c4d.MATERIAL_LUMINANCE_SHADER] = Art

      I also want it to load a image in the art shader, so I figured, why don't I just create a preset folder in the content browser and load the material form that folder. 
      Turns out it's quite tricky to import materials from the content browser too.

      > fn = "preset://somefolder/Cube.2.c4d"
      >
      > c4d.documents.LoadFile(fn)

      If I use anything else then LoadFile, it will tell me to use a base document in the console.

      From my understanding, I have to make a virtual base document and then import it from that.
      How does that look like in code ?

      I only need one to work, but I am very interested in both!

      Cheers,
      Tim

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

        On 30/08/2018 at 23:11, xxxxxxxx wrote:

        I figured out how to load the material form the content browser:

        > doc = c4d.documents.GetActiveDocument()
        >
        > location = "preset://somefolder.lib4d/mymat"
        >
        > c4d.documents.MergeDocument(doc, location, c4d.SCENEFILTER_MATERIALS)

        But I prefer creating the material in python rather then loading it, if anyone knows how to access and apply the Art shader, let me know 😉

        - Tim

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

          On 31/08/2018 at 04:07, xxxxxxxx wrote:

          Hi Myosis, first of all, welcome in the plugincafe community!

          Even if shader didn't get a proper symbols name, each BaseList2D get an ID. And symbols only refer to this ID.
          So if you want to know the current ID of an Art shader. Simply create a shader in a material, then drag and drop the channel where the shader is into the console. Press enter and it will print you the ID.
          For the art shader, it's 1012161.

          About bitmap do the same technique, simply drag and drop the parameter into the console to know the parameter ID.

          Then you can create it using the following script

          import c4d
            
          def main() :
              mat = doc.GetActiveMaterial()
              if not mat:
                  return
              
              # Create the bitmap shader
              bmpShader = c4d.BaseShader(c4d.Xbitmap)
              bmpShader[c4d.BITMAPSHADER_FILENAME] = "YourTexturePath"
              
              # Create a art Shader and insert our bmp shader
              artShader = c4d.BaseShader(1012161)
              artShader.InsertShader(bmpShader)
              artShader[c4d.ARTSHADER_TEXTURE] = bmpShader
              
              # Then insert our art Shader into the active material, and use it in the color channel
              mat.InsertShader(artShader)
              mat[c4d.MATERIAL_COLOR_SHADER] = artShader
              
              c4d.EventAdd()
            
          if __name__=='__main__':
              main()
          

          As you already figured out, in python the only way to load stuff from content browser is to use LoadFile/MergeDocument.

          If you have any question, please let me know!
          Cheers,
          Maxime!

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