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

    Python Light Controller

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 802 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 24/07/2018 at 11:05, xxxxxxxx wrote:

      Hey All,

      I'm still getting a handle on python basics so any help would be much appreciated. I'm trying to make a python tag that will select lights by name in my hierarchy and will then control certain parameters with user data. From all the examples I've seen, this code should be working....

      import c4d
                  
        
      def Lights() :
          
          for i in doc.GetObjects() :
              if (i.GetName() == 'v2' and 'v1') :
                  Lights = i
                          
      def main() :
        
          Vol_On = op[c4d.ID_USERDATA,1]  
          Lights = c4d.BaseObject (5102) # Light
          op[c4d.LIGHT_VLTYPE] = Vol_On 
               
          
          c4d.EventAdd() 
          
      if __name__=='__main__':
          main()
        
      
      

      Thanks!

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

        On 25/07/2018 at 02:51, xxxxxxxx wrote:

        Hi Bencaires,

        Thanks for writing to us. Please keep in mind tag is part of an object (is like adding an element to an object). So you are only allowed to modify the current object parameter, or the tag itself.

        To select an object according to its name. A script executed by the script manager will be more suited.
        The basic way to do this is to iterate over the scene, please read this blog Recursive hierarchy iteration[URL-REMOVED], Then check for the name and use SetActiveObject to select your objects.

        For the second part, to control certain parameters from user data, you are right, a tag is a good choice (but keep in mind tag, can only modify the current host object, he can read the user data from another object for sure if you respect priorities).
        And your code, is somehow correct, except "op" currently represent the operator which mean, the python tag itself. If you want to get the host object, use op.GetObject().

        light = op.GetObject()
        lightUserData = light[c4d.ID_USERDATA,1]
        light[c4d.LIGHT_VLTYPE] = lightUserData
        

        If you have any question, please let me know. 
        Cheers,
        Maxime


        [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