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

    script syntax help

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 379 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 02/05/2017 at 06:16, xxxxxxxx wrote:

      Hi guys,
      sometimes I use the Script log to see what a command syntax looks like, and usually fail to create a Python script out of it.
      For example, using:
          prefs(465001620)[c4d.PREF_INTERFACE_CENTEROBJECT]=True
          prefs(465001620)[c4d.PREF_INTERFACE_CENTEROBJECT]=False

      turns the "Create New object at View Center" on and off.
      How would I create a script that toggles between states, with the icon being Active (blue) when it's on and grey when it's off?

      just pasting the code in a script gives me an error:
      Traceback (most recent call last) :
        File "'scriptmanager'", line 11, in <module>
        File "'scriptmanager'", line 7, in main
      NameError: global name 'prefs' is not defined

      Cheers
      Noseman

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

        On 02/05/2017 at 07:00, xxxxxxxx wrote:

        import c4d
          
        def main() :
            interface = c4d.plugins.FindPlugin(465001620, c4d.PLUGINTYPE_PREFS)
            interface[c4d.PREF_INTERFACE_CENTEROBJECT] = not bool(interface[c4d.PREF_INTERFACE_CENTEROBJECT]) #toogle
            c4d.EventAdd()
                            
        if __name__=='__main__':
            main()
        

        For the state take a look at my video here (in french) 

        .
        Or look at this post where you have everything you need for doing it https://developers.maxon.net/forum/topic/423/13564_plugins-in-plugin-or-icons&PID=53811#53811

        Btw I wanted to say a big thank you!
        You are one of the guy who inspire me about doing pythonic stuff. So thanks for your love of c4d and all your share !

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

          On 02/05/2017 at 10:09, xxxxxxxx wrote:

          Thank you so much for your help.
          I was trying to help out a user on CG Society.
          I'm going to post your script alongside another solution.

          Also, I'm glad I could inspire you to push the limits of C4D... keep up the great work!

          Cheers

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