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

    Struggling on SetParameter for OLight

    Cinema 4D SDK
    python s26
    2
    4
    845
    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.
    • mocolocoM
      mocoloco
      last edited by mocoloco

      Hello there!

      I'm starting a new TAG plugin development and I would like to affect OLight parameter, i.e. c4d.LIGHT_COLOR, but my DescId does not reach its target.

      All this is happening in dataTag.Execute.

      Here the code, and the GetParameter returns only None, which means there is something wrong...

       # TAG Execute() method
      def Execute(self, tag, doc, op, bt, priority, flags):
          self.tagData = tag.GetDataInstance()
          sim_color = c4d.Vector(0) # For debug purpose, set a black color value
      
          if op.GetType() == c4d.Olight:
              # For debug purpose  
              print( op.GetParameter( c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR, c4d.DTYPE_COLOR, 0)), c4d.DESCFLAGS_GET_PARAM_GET ) )
      
              op.SetParameter( c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR, c4d.DTYPE_COLOR, 0)), sim_color, c4d.DESCFLAGS_SET_USERINTERACTION )
          
              return c4d.EXECUTIONRESULT_OK
      

      I tried different flags for SetParameter, but based on @ferdinand explanation on CTrack, it seems that c4d.DESCFLAGS_SET_USERINTERACTION is the good one.

      If someone can light me up on this, that would be awesome.

      Cheers,
      Christophe

      1 Reply Last reply Reply Quote 0
      • mocolocoM
        mocoloco
        last edited by

        Little addition after looking for a solution and reading more on OLight, it seems that the correct data type is c4d.DTYPE_VECTOR instead of c4d.DTYPE.COLOR. But even with this I can't reach the value.

         # TAG Execute() method
        def Execute(self, tag, doc, op, bt, priority, flags):
            self.tagData = tag.GetDataInstance()
            sim_color = c4d.Vector(0) # For debug purpose, set a black color value
        
            if op.GetType() == c4d.Olight:
                # For debug purpose  
                print( op.GetParameter( c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR, c4d.DTYPE_VECTOR, 0)), c4d.DESCFLAGS_GET_PARAM_GET ) )
        
                op.SetParameter( c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR, c4d.DTYPE_VECTOR, 0)), sim_color, c4d.DESCFLAGS_SET_USERINTERACTION )
            
                return c4d.EXECUTIONRESULT_OK
        
        1 Reply Last reply Reply Quote 0
        • M
          m_adam
          last edited by

          Hi @mocoloco for such a parameter, using the bracket operator will be more easy.
          Find bellow the code within a Python Scripting tag, this work as expected.

          from typing import Optional
          import c4d
          
          doc: c4d.documents.BaseDocument # The document evaluating this tag
          op: c4d.BaseTag # The Python scripting tag
          flags: int # c4d.EXECUTIONFLAGS
          priority: int # c4d.EXECUTIONPRIORITY
          tp: Optional[c4d.modules.thinkingparticles.TP_MasterSystem] # Particle system
          thread: Optional[c4d.threading.BaseThread] # The thread executing this tag
          
          def main() -> None:
              obj = op.GetObject()
              previousLightColor = obj[c4d.LIGHT_COLOR]
              print(previousLightColor)
              newLightColor = c4d.Vector(0.0, 1.0, 1.9)
              obj[c4d.LIGHT_COLOR] = newLightColor
          

          But if you really want to use G/SetParameter you can do it with the code bellow. The issue with your code is that DESCFLAGS_GET_PARAM_GET mean to be used within the implementation to notify the system that this parameter have been already retrieved so no need to retrieve it again. So if you pass this flag as an input therefor you will have nothing in return.

              obj = op.GetObject()
              previousLightColor = obj.GetParameter(c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR, c4d.DTYPE_VECTOR, 0)), c4d.DESCFLAGS_GET_NONE)
              print(previousLightColor)
              newLightColor = c4d.Vector(0.0, 0.0, 1.9)
              obj.SetParameter( c4d.DescID(c4d.DescLevel(c4d.LIGHT_COLOR, c4d.DTYPE_VECTOR, 0)), newLightColor, c4d.DESCFLAGS_SET_NONE )
          

          Cheers,
          Maxime.

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • mocolocoM
            mocoloco
            last edited by

            Hi @m_adam,

            Thanks a lot for the flags, it does work as expected now.
            Are c4d.DESCFLAGS_GET_NONE and c4d.DESCFLAGS_GET_0 similars?

            Cheers,
            Christophe.

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