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

    Setting Read-Only STRING value in Description

    Cinema 4D SDK
    python
    2
    3
    371
    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.
    • ?
      A Former User
      last edited by A Former User

      Hello,
      I'm trying to set the value of a string with a Static Text interface in my ObjectData plugin.

      Here is an example of what I'm trying to achieve. I created it in the UserData by adding Data with a String Data Type and Interface set to String, setting the value, then changing the Interface to Static Text:
      74d936a4-aad3-425f-b12a-4dcd83de7c75-image.png

      In my current Descriptions, I've tried using STRING and STATICTEXT but neither has produced the desired result.

      STATICTEXT READOUT_WIDTH { ANIM OFF; }
      
      STRING READOUT_WIDTH { ANIM OFF; }
      

      When using STRING, I try to set the value, but I get the error TypeError:__setitem__ expected float, not str. I don't know how to set it's value then make it a read-only/Static Interface.

      op[c4d.READOUT_WIDTH] = str(width)
      

      Can anyone please help me create this type of static text string? Thank you!

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User
        last edited by

        I sort of have a solution, but would love feedback on the right way to do this:

        I'm setting the string with this code:

        node.SetParameter(c4d.READOUT_WIDTH, str(width), c4d.DESCFLAGS_SET_0)
        

        Then in NodeData.GetDDescription, I'm setting the Description Parameter's DESC_CUSTOMGUI to DTYPE_STATICTEXT.

                width = description.GetParameterI(c4d.READOUT_WIDTH)
                if width :
                    width[c4d.DESC_CUSTOMGUI] = c4d.DTYPE_STATICTEXT
        

        The difference between this and the UserData version is the UserData version has a box around the String's value while the above does not. Any feedback would be fantastic. Thank you!

        1 Reply Last reply Reply Quote 0
        • ManuelM
          Manuel
          last edited by

          hi,

          Sorry for the delay of this answer, we simply missed your post.

          When using STRING READOUT_WIDTH { ANIM OFF; } it's important that you initialize the parameter in your Init function. Otherwise uninitialized type will be a int.
          At some point, the code is comparing the old value type with the new value. That's why it's waiting for a Int while you provide a Str. (feel like a bug to me)

          I don't see the problem using STATICTEXT or STRING. It does create the expected fields. The StaticText can't be Animated anyway, i would remove the ANIM OFF

                  STATICTEXT PYPREFERENCE_STATICTEXT  {}
                  STRING PYPREFERENCE_STRING { }
          

          about the border around the static text you can declare the field like this in your ressource file:

            STATICTEXT PYPREFERENCE_STATICTEXT_BORDER  {BORDER;}
          

          Cheers,
          Manuel

          MAXON SDK Specialist

          MAXON Registered Developer

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