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

    Changing Object Props. / was: I quit,... [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 327 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 26/10/2014 at 11:40, xxxxxxxx wrote:

      Please, if some one can help with this code.

      The issue : Every time I change a any property of the object created with this plugin, the materials get created again.

      I'm new on python and c4d sdk, but I've got some help from Sebastian in this forum and I've able to achieve this code. Please, can some one help me?

      -------------  _ myPlugin.pyp ----------------_
      import os
      import sys
      import c4d
      from c4d import gui, plugins, bitmaps, documents

      PLUGIN_ID = // I CANNOT PUBLIC THIS //

      def CreateMaterialTag(name, color, light) :
          # doc
          doc = documents.GetActiveDocument()
          #Add Mat
          myMat = c4d.BaseMaterial(5703)
          myMat[c4d.MATERIAL_COLOR_COLOR] = color
          myMat.SetName(name)
          doc.InsertMaterial(myMat)
          return myMat

      def GenSoftBox(op) :
          if not op: return
          # cube
          cube = c4d.BaseObject(c4d.Ocube)
          # insert cube into op
          cube.InsertUnder(op)
          #mat1
          myTag1 = c4d.TextureTag()
          myTag1[c4d.TEXTURETAG_MATERIAL] = CreateMaterialTag("SoftBoxBlack",c4d.Vector(0.01,0.01,0.05), False)
          cube.InsertTag(myTag1)
          # ADD TO SCENE
          c4d.EventAdd()

      class myPlugin(plugins.ObjectData) :

      def __init__(self) :
              self.SetOptimizeCache(True)

      def GetVirtualObjects(self, op, hierarchyhelp) :
              # Disabled the following lines because cache flag was set
              # So the cache build is done before this method is called
              dirty = op.CheckCache(hierarchyhelp) or op.IsDirty(c4d.DIRTY_DATA)
              if dirty is False: return op.GetCache(hierarchyhelp)

      def Init(self, op) :
              GenSoftBox(op)
              return True

      def Message(self, node, type, data) :
              if type==c4d.MSG_DESCRIPTION_COMMAND:
                  if data['id'][0].id==SB_ON_OFF:
                      print "Pushed button with command ID"
              return True

      def main() :
          bmp = c4d.bitmaps.BaseBitmap()
          dir, file = os.path.split(__file__)
          fn = os.path.join(dir,"res","icon.tif")
          bmp.InitWith(fn)
          try:
              result = plugins.RegisterObjectPlugin(
                  id = PLUGIN_ID,
                  str = "myPlugin",
                  g = myPlugin,
                  description = "myDescription",
                  info = c4d.PLUGINFLAG_SMALLNODE | c4d.OBJECT_INPUT,
                  icon = bmp
              )
              if (result) :
                  print "Plugin initialized."

      except:
              exctype, value = sys.exc_info()[:2]
              c4d.gui.MessageDialog(value)
              print str(value)

      if __name__ == "__main__":
          main()

      I remarked the code where should look at, I believe I missing the method where the GenSoftBox() method should be called, but I really dont know what to do!!

      Any help will be appreciated!! Cheers!!

      BTW Sorry about my bad english.

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

        On 26/10/2014 at 12:00, xxxxxxxx wrote:

        Hi,

        download the sdk there are several example plugins, for example the Py-RoundedTube, which is an object plugin. I started with those and it was really helpful.
        I guess your function should better be placed at GetVirtualObjects().

        Best wishes
        Martin

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

          On 27/10/2014 at 02:36, xxxxxxxx wrote:

          Hello,

          to help us understand your issue please share more information about what you are trying to do.

          An object's Init()[URL-REMOVED] function is not meant to be used to edit the document. It is supposed to be used to define default parameter values etc. when a new instance of this object was created. For different reasons multiple instances of an object can exist (so Init() may be called multiple times).

          Also, a generator plugin typically does not create objects by making them child objects of itself. A generator creates virtual child objects in GetVirtualObjects()[URL-REMOVED]. These virtual child objects are re-created every time the generator object becomes dirty. To use your object as a generator you must set the OBJECT_GENERATOR   flag in RegisterObjectPlugin ()[URL-REMOVED].

          Since GetVirtualObjects() creates virtual child objects you should not create materials in that context because creating materials means to edit the document (which you should not do in this function, see Important Threading Information[URL-REMOVED] and Threading[URL-REMOVED]). So you should create the materials based on some user interaction (like pressing a button etc.).

          As Martin said, please take a look at the RoundedTube example[URL-REMOVED].

          best wishes,
          Sebastian


          [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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