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

    test for the exist of a preference-value

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 186 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 19/08/2014 at 08:29, xxxxxxxx wrote:

      Hello,

      i want to check if a preference-value even exists.
      But if I read the value I get an error.

        
      data = c4d.plugins.GetWorldPluginData(PLUGIN_ID)   
      

      retunes a false if the preferenzes does not exist.

      But I have to check for a special value like:

        
      last_usage_time = data.getString(1002)   
      

      I only get his error:
      AttributeError: 'c4d.BaseContainer' object has no attribute 'getString'

      So, how can I check if the value isn't defined.

      Thanks a lot

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

        On 19/08/2014 at 21:26, xxxxxxxx wrote:

        Hello,

        1. GetWorldPluginData() will not return False, but None when the data does not exist yet.
        2. The method is called GetString, not getString, Python is case-sensitive

        I'd suggest something like this

        data = c4d.plugins.GetWorldPluginData(PLUGIN_ID)
        if not data:
            data = c4d.BaseContainer()
          
        last_usage = data.GetString(1002)
        if not last_usage:
            # ...
        else:
            # ...
        

        Best,
        -Niklas

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