Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Python Generator - Adding Shaders to Deformer Objects

    Cinema 4D SDK
    python
    4
    11
    1.5k
    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.
    • M
      moGRR
      last edited by

      Hi all.

      I'm trying to use a python generator to create a Displacer deformer object that has a Color shader. However, I can't seem to get the Color shader bit of it to work. The Displacer object is generated but with nothing in it's [c4d.ID_MG_SHADER_SHADER]property. Here is an example of the code I'm using:

      def main():
          myNull = c4d.BaseObject(c4d.Onull)
          myCube = c4d.BaseObject(c4d.Ocube)
          myDeformer = c4d.BaseObject(1018685) # Deformer Object - Displacer
          myShader = c4d.BaseShader(5832) # Color Shader
          myDeformer[c4d.ID_MG_SHADER_SHADER] = myShader
          myCube.InsertUnder(myNull)
          myDeformer.InsertUnder(myNull)
      
          return myNull
      
      1 Reply Last reply Reply Quote 0
      • P
        PluginStudent
        last edited by

        Newly created shaders have to be inserted into the host object using InsertShader().

        See BaseShader Manual or GitHub.

        1 Reply Last reply Reply Quote 0
        • M
          moGRR
          last edited by

          Thanks again @PluginStudent

          I'm not sure I fully understand how to get it working still... I adapted my code to below, but it still is generated with nothing in the [c4d.ID_MG_SHADER_SHADER] property

          def main():
              myNull = c4d.BaseObject(c4d.Onull)
              myCube = c4d.BaseObject(c4d.Ocube)
              myDeformer = c4d.BaseObject(1018685) # Deformer Object - Displacer
              myShader = c4d.BaseList2D(c4d.Xcolor) # Color Shader
              myDeformer.InsertShader(myShader)
              myCube.InsertUnder(myNull)
              myDeformer.InsertUnder(myNull)
              print myShader
              return myNull
          
          1 Reply Last reply Reply Quote 0
          • P
            PluginStudent
            last edited by

            The shader instance has to be inserted using InsertShader() AND assigned as you already did in your previous post.

            Please read the linked manual and take a look at the example on GitHub.

            1 Reply Last reply Reply Quote 0
            • M
              moGRR
              last edited by

              Thanks @PluginStudent - that's working now.

              Just so you know that I wasn't being lazy, I did look at the linked manual and the GitHub link, I just sometimes find them hard to follow as I'm not a coder.

              Thanks again for your help
              Jamie

              M 1 Reply Last reply Reply Quote 0
              • M
                m_adam @moGRR
                last edited by

                @moGRR said in Python Generator - Adding Shaders to Deformer Objects:

                Thanks @PluginStudent - that's working now.

                Just so you know that I wasn't being lazy, I did look at the linked manual and the GitHub link, I just sometimes find them hard to follow as I'm not a coder.

                Thanks again for your help
                Jamie

                What did you don't understand?
                and how could we improve them in your opinion?

                Cheers,
                Maxime

                MAXON SDK Specialist

                Development Blog, MAXON Registered Developer

                M 1 Reply Last reply Reply Quote 0
                • M
                  moGRR @m_adam
                  last edited by

                  Hi @m_adam

                  Hmm good questions.

                  I found the BaseShader Manual confusing because it looks like the example code isn't Python? It might be useful to have something that explicitly states what language the example code is in and what it does to help people like myself.

                  The GitHub link was more useful but I think it could benefit from having a few more examples of the code being used in context. It helped me get a better understanding of what I was trying to do, but without actually confirming to me what it is I had to do exactly.

                  I hope this makes sense?

                  Thanks,
                  Jamie

                  1 Reply Last reply Reply Quote 0
                  • M
                    m_adam
                    last edited by

                    Yes unfortunately for the moment manual exists only in C++. There are only a few in Python.

                    I'm not sure to fully understand "from having a few more examples of the code being used in the context" what do you mean in context? Keep in mind that you have an issue but other people have different issues regarding the same topics so having an example for each possible scenario is almost impossible (or you will never need to develop ;)).

                    But if you have a feeling an example about XYZ is missing please ask for it by either posting here, create a new topic or create a new GitHub issue.

                    Cheers,
                    Maxime

                    MAXON SDK Specialist

                    Development Blog, MAXON Registered Developer

                    M 1 Reply Last reply Reply Quote 0
                    • M
                      moGRR @m_adam
                      last edited by

                      @m_adam

                      Sorry I should have made that a bit clearer. I didn't mean a specific context to my problem, obviously that is impractical.

                      To give a better idea, with the GitHub link that Plugin Student sent, I'd find it really beneficial if there was a summary text that explained what the code does, and then maybe another example showing the code in another context?

                      As someone that isn't a coder but is eager to learn the benefits of Python in C4D, I'd personally find that really helpful.

                      Cheers,
                      Jamie

                      M 1 Reply Last reply Reply Quote 0
                      • M
                        mp5gosu @moGRR
                        last edited by

                        @moGRR said in Python Generator - Adding Shaders to Deformer Objects:

                        I'd find it really beneficial if there was a summary text that explained what the code does

                        There is. Every section has a readme. https://github.com/PluginCafe/cinema4d_py_sdk_extended/blob/master/plugins/readme.md

                        M 1 Reply Last reply Reply Quote 0
                        • M
                          moGRR @mp5gosu
                          last edited by

                          @mp5gosu

                          Ah brilliant. Thanks for that!

                          And apologies for being such a noob at this.

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