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

    what is op[0]

    Scheduled Pinned Locked Moved PYTHON Development
    9 Posts 0 Posters 1.3k 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 17/08/2017 at 04:17, xxxxxxxx wrote:

      Hello,

      I was just watching a quick tutorial on different ways of calculating spline length, and I came across some syntax I can't figure out:

      op[0]

      what does this mean?

      reference useage:

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

        On 17/08/2017 at 05:03, xxxxxxxx wrote:

        https://developers.maxon.net/docs/Cinema4DPythonSDK/html/modules/c4d.utils/SplineLengthData/index.html?highlight=splinelengthdata#c4d.utils.SplineLengthData

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

          On 17/08/2017 at 05:52, xxxxxxxx wrote:

          that doesn't mention, let alone explain what op[0] is.
          Also there is no instance in that documentation of SplineLengthData being called as SlineLengthData(anything)

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

            On 17/08/2017 at 09:56, xxxxxxxx wrote:

            Ah, completely oversaw that. Apologies.

            Good question, although I believe, that this does nothing at all.
            I'd say, that the constructor wrapper just filters out any arguments, that are too much.

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

              On 17/08/2017 at 11:00, xxxxxxxx wrote:

              No prob, it just confuses me! whats it for?! I'll have to try without and see what happens.

              I was hoping I could figure out how to use it by just looking at that original documentation page, but I had no idea that it first needed to have an instance created with that specific syntax, or is that what ".__init__()" is supposed to represent? ..

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

                On 17/08/2017 at 11:09, xxxxxxxx wrote:

                I suggest you to read http://www.python-course.eu/python3_magic_methods.php

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

                  On 18/08/2017 at 02:31, xxxxxxxx wrote:

                  What op[0] does depends on what op is. It's syntactic sugar for
                  calling op.__getitem__(0). When you see __getitem__() in the
                  docs of a class, that's when you can use [] on objects of that
                  class. E.g. you can use it to retrieve values from a BaseContainer.

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

                    On 18/08/2017 at 06:39, xxxxxxxx wrote:

                    Not much left to add for me...

                    In Script Manager op is a predefined variable pointing to the currently selected object. So if op hasn't been reassigned in the tutorial, that's what it is.

                    And yes, when creating a SplineLengthData the parameter will be ignored. It's redundant in that line of the tutorial and I'd recommend to omit passing a parameter there.

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

                      On 23/08/2017 at 14:25, xxxxxxxx wrote:

                      Thanks everyone! Much appreciated.

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