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

    How to get/set single vector value from USERDATA

    Cinema 4D SDK
    python
    2
    2
    292
    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.
    • mikeudinM
      mikeudin
      last edited by

      Hello!
      After dragging to console there is no way to get single value from vector UserData parameter.

      >>> Cube[c4d.ID_USERDATA,2,c4d.VECTOR_Z]
      Vector(0, 0, 0)
      >>> Cube[c4d.ID_BASEOBJECT_REL_POSITION,c4d.VECTOR_X]
      52.0
      

      Screenshot 2022-05-17 at 22.30.10.png

      And no way to set this single value:

      >>> Cube[c4d.ID_USERDATA,2,c4d.VECTOR_Z] = 12
      Traceback (most recent call last):
        File "console", line 1, in <module>
      TypeError: __setitem__ expected c4d.Vector, not int
      

      There is a soution without creating a new c4d.Vector() variable? 🤔 I need to get dragged to plugin dialog c4d.DRAGTYPE_DESCID from one single vector UserData parameter.
      Thank you!

      Checkout my python tutorials, plugins, scripts, xpresso presets and more
      https://mikeudin.net

      ferdinandF 1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand @mikeudin
        last edited by ferdinand

        Hello @mikeudin,

        Thank you for reaching out to us. Vectors represented by the type c4d.Vector are immutable in Cinema 4D, so one intentionally cannot change one of the components of a vector after it has been instantiated (matrices are not immutable over their vector components on the other hand). To achieve what you want to do, you must write:

        old = Cube[c4d.ID_USERDATA, 2]
        Cube[c4d.ID_USERDATA, 2] = c4d.Vector(old.x, old.y, 12)
        

        The following would also be possible, but it is not an improvement IMHO:

        Cube[c4d.ID_USERDATA, 2] = c4d.Vector(Cube[c4d.ID_USERDATA, 2].x, Cube[c4d.ID_USERDATA, 2].y, 12)
        

        Cheers,
        Ferdinand

        MAXON SDK Specialist
        developers.maxon.net

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