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

    Why use InitAttr()? [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    2 Posts 0 Posters 247 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 30/10/2014 at 18:02, xxxxxxxx wrote:

      Why should one use InitAttr() and subscripting to access object data over GetDataInstance() and then the Get/Set() type specific methods (ie, GetBool())?

      I keep seeing plugins that do either or, sometimes both. There will be one plugin that calls InitAttr() in the Init() method to setup subscripting access (I'm assuming that's what InitAttr() does, since if you don't do that then any attempts to access that data via subscripting just return "None" instead), then access all the object data like obj[c4d.SomeObjectParameter] = 40.0.

      Then there's plugins that just forego this and call bc = op.GetDataInstance() and access the data via the various type specific getters and setters, like bc.SetBool(c4d.SomeObjectParamter, False).

      What's the difference? Why should I use one or the other? It seems like MAXON's examples tend to access things via GetDataInstance() rather then subscripting. Various third party plugins tend to use the alternative though, presumably because it's less typing.

      -CMPX

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

        On 31/10/2014 at 02:22, xxxxxxxx wrote:

        Hello,

        using InitAttr()[URL-REMOVED] you make the sure that a parameter is initiated with an element of the correct type and a default value.

        When you handle an object in Cinema 4D you can't be sure if a value is stored in it's BaseContainer or somewhere else. So when you are handling a BaseContainer and you know the value you want is stored in that BaseContainer (like in your own object etc.) it's fine to access the BaseContainer.

        But when you handle another object you should ask the object for the parameter, not it's BaseContainer. This way you ensure that the object can react to this request properly and can deliver the correct value. Please read this thread about the issue.

        Also, since Release 16 Python supports SetParameter() and GetParameter()[URL-REMOVED]. Using this functions you can now set different flags.

        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