Python Generator - Adding Shaders to Deformer Objects



  • 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
    


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

    See BaseShader Manual or GitHub.



  • 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
    


  • 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.



  • 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



  • @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



  • 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



  • 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



  • @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



  • @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



  • @mp5gosu

    Ah brilliant. Thanks for that!

    And apologies for being such a noob at this.


Log in to reply