Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Iterate Attributes

    PYTHON Development
    0
    5
    835
    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
      Helper
      last edited by

      On 16/08/2017 at 04:30, xxxxxxxx wrote:

      Hello,

      I am trying to iterate trough tag attributes with a script:

      import c4d
      def main() :
        if op is None: return
        for tag in op.GetTags() :
            bc = tag.GetDataInstance()
            for value in bc:                
                print value

      if __name__=='__main__':
        main()

      It all goes well until it comes to some "unsupported" attributes, likes of Weight tag, Visual Selector tag...
      It gives an error with such tags stating:
      "AttributeError: Parameter value not accessible (object unknown in Python)"

      I really have no idea how to bypass this. Is there a better way of doing this? Or am I missing something obvious?

      Thanks,
       
      Sandi

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

        On 16/08/2017 at 05:09, xxxxxxxx wrote:

        I guess this thread will answerd your ask https://developers.maxon.net/forum/topic/5936/6027_how-to-list-keys-for-a-basecontainer&PID;=25407#25407

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

          On 16/08/2017 at 08:13, xxxxxxxx wrote:

          That did it, thank you!

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

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

            The AttributeError stating "Parameter value not accessible (object unknown in Python)" means the Python API doesn't support the data type for the parameter.
            So no data value can be given for such parameter.

            To bypass this error you can catch and process it like this:

            def main() :
                if op is None:
                    return
              
                for tag in op.GetTags() :
                    bc = tag.GetDataInstance()
                    print tag
              
                    # Loops through parameters
                    dataLen = len(bc)
                    for dataIdx in xrange(dataLen) :
                        dataID = bc.GetIndexId(dataIdx)    # Retrieves parameter ID for the given index
                        dataType = bc.GetType(dataID)      # Retrieves parameter data type
                        try:
                            data = bc[dataID]              # Tries tro get parameter data
                        except AttributeError:
                            print dataID, dataType, "Data not supported"
                            continue
              
                        # Prints information on parameter data
                        print dataID, dataType, data
            
            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

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

              That's even more elegant, thank you Yannick!

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