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

    Material not rendering in PV [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    6 Posts 0 Posters 500 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 05/06/2016 at 04:43, xxxxxxxx wrote:

      Hello,

      I have a litle problem with an Object Plugin.
      In my plugin I import a material from an c4d file in the res folder (its a more complex material,so I don't create it in my plugin)
      I have searched and read some threads about this but it just doesn't seem to work for me.

      My code:

      import os
      import c4d
      import random
      from c4d import plugins, bitmaps, utils, gui, storage
        
      PLUGIN_ID = 1037525
        
      class olightroom(plugins.ObjectData) :  
          
          def __init__(self) :
              self.SetOptimizeCache(False)
              doc = c4d.documents.GetActiveDocument()
              if doc.SearchMaterial("MITA_HDRI") == None:
                  dir, f = os.path.split(__file__)
                  path = os.path.join(dir, "res/mats", "hdri.c4d")
                  c4d.documents.MergeDocument(doc, path , c4d.SCENEFILTER_0|c4d.SCENEFILTER_OBJECTS|c4d.SCENEFILTER_MATERIALS|c4d.SCENEFILTER_MERGESCENE)
              self.hdri_material = doc.SearchMaterial("MITA_HDRI")
              self.textureTag = c4d.TextureTag()
              
              self.textureTag.SetMaterial(self.hdri_material)
              self.textureTag.Message(c4d.MSG_UPDATE)
              self.hdri_material.ChangeNBit(c4d.NBIT_OHIDE, c4d.NBITCONTROL_SET) 
        
          def GetVirtualObjects(self, op, hh) :
              doc = c4d.documents.GetActiveDocument()
              main_obj = c4d.BaseObject(c4d.Onull)
              hdri_object = c4d.BaseObject(c4d.Osky)
        
              hdri_object.InsertTag(self.textureTag, None)
              hdri_object.InsertUnder(main_obj)
              hdri_object.ChangeNBit(c4d.NBIT_OHIDE, c4d.NBITCONTROL_SET)   
              return main_obj
        
      if __name__ == "__main__":
          path, fn = os.path.split(__file__)
          bmp = bitmaps.BaseBitmap()
          bmp.InitWith(os.path.join(path, "res", "icon.tif"))
        
          plugins.RegisterObjectPlugin(id=PLUGIN_ID, str="Mita's Lightroom 1.0", g=olightroom, description="olightroom", icon=bmp, info=c4d.OBJECT_GENERATOR)
      

      The funny thing is, that it works in the opengl view.
      Hopefully someone can help me.

      greetings,
      neon

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

        On 10/06/2016 at 09:10, xxxxxxxx wrote:

        Hasn't got anyone an idea?

        Or was I just not clear enough?

        greetings, 
        neon

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

          On 10/06/2016 at 11:07, xxxxxxxx wrote:

          __init__() is the wrong place to do this, and GetActiveDocument() is
          not always the right document to do this with.
          Also, consider what happens when the material is deleted by the user.

          Maybe that helps,
          Cheers

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

            On 13/06/2016 at 02:50, xxxxxxxx wrote:

            Hello,

            a NodeData based plugin like ObjectData could be used in any context or situation (background rendering, team render client, etc.). So it is never save to call GetActiveDocument() from a NodeData based plugin.

            If you want to modify or interact with the scene that will receive the object instance when it is created from the GUI you can catch the message MSG_MENUPREPARE. This message is sent to the object before it is inserted into the BaseDocument. But the given data is a reference to the target BaseDocument.

            See the DoubleCircle example.

            Best wishes,
            Sebastian

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

              On 24/06/2016 at 06:16, xxxxxxxx wrote:

              Hello Neon,

              was you question answered?

              Best wishes,
              Sebastian

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

                On 24/06/2016 at 11:05, xxxxxxxx wrote:

                Hello Sebastian,

                yes my question was answered!
                I actually did reply but I think I missed the post reply button and closed the Window to early, sry my bad.

                Thanks again for all the Information.

                regards, 
                neon

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