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 Data unit

    Cinema 4D SDK
    r21 python
    2
    3
    403
    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.
    • chuanzhenC
      chuanzhen
      last edited by

      Hi,
      in picture object Position gui unit is real, Rotation gui unit is Degree , User data gui unit is Percent. how to know gui unit? and how to directly obtain the value displayed on the panel(Data = 0.1745, want to directly get 17.453)?
      无标题.jpg

      Thanks for any help!

      相信我,可以的!

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

        Hello @chuanzhen,

        thank you for reaching out to us. I will answer in bullet points, since there are sort of two questions within you question.

        1. The unit type of a parameter is being stored in the Description of the node that parameter is a part of. Each parameter is being described as a BaseContainer in the description of a node. The unit of the parameter is then stored in the field c4d.DESC_UNIT in such container. See example at the end for details.
        2. There are no prebuilt functions which would convert the value of a parameter into its display value. You would have to do that yourself with the unit type and the parameter value.

        Cheers,
        Ferdinand

        The example code:

        """Attempts to evaluate the unit type of the first user data parameter of the 
        currently selected object.
        
        Must be run in the Script Manger while having an object selected with at least
        one user data parameter. When the parameter has one of the unit types float,
        percent, degree or meter (there are other unit types), it will print out a
        matching message. If not, it will report that there is "another" unit type or
        no unit type when the parameter has no unit type set at all.
        """
        
        import c4d
        
        def main() -> None:
            """Attempts to evaluate the unit type of the first user data parameter of
            the currently selected object.
            """
            # op is a predefined module attribute in scripts referencing the currently
            # selected object.
            if not isinstance(op, c4d.BaseObject):
                raise RuntimeError("Please select an object.")
        
            # The id of the parameter we are interested in, the first user data
            # parameter of a node.
            pid = (c4d.ID_USERDATA, 1)
        
            # Get the description of the node.
            description = op.GetDescription(c4d.DESCFLAGS_DESC_NONE)
            # Get the first user data element in the description.
            parameterData = description.GetParameter(pid)
        
            # Bail when the container is empty, i.e., there is no such parameter in
            # the node.
            if len(parameterData) < 1:
                raise RuntimeError(f"Retrieved empty data container for {pid}.")
        
            # How to iterate over the flags of that parameter container.
            # for cid, value in data:
            #     print (cid, value)
        
            # Get the unit type flag for the element and bail if there is no value
            # set for that flag.
            unitType = parameterData[c4d.DESC_UNIT]
            if unitType is None:
                print (f"The parameter with the id {pid} has no unit type.")
                return
        
            # Do some stuff depending on the unit type.
            if unitType == c4d.DESC_UNIT_FLOAT:
                print (f"The unit type for {pid} is float.")
            elif unitType == c4d.DESC_UNIT_PERCENT:
                print (f"The unit type for {pid} is percent.")
            elif unitType == c4d.DESC_UNIT_DEGREE:
                print (f"The unit type for {pid} is degree.")
            elif unitType == c4d.DESC_UNIT_METER:
                print (f"The unit type for {pid} is meter, i.e., length.")
            else:
                print (f"The unit type for {pid} is another unit type.")
        
        if __name__ == '__main__':
            main()
        

        MAXON SDK Specialist
        developers.maxon.net

        chuanzhenC 1 Reply Last reply Reply Quote 0
        • chuanzhenC
          chuanzhen @ferdinand
          last edited by

          @ferdinand Thanks,great!

          相信我,可以的!

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