Setting Read-Only STRING value in Description
-
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:

In my current Descriptions, I've tried using
STRINGandSTATICTEXTbut 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 errorTypeError:__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!
-
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_CUSTOMGUItoDTYPE_STATICTEXT.width = description.GetParameterI(c4d.READOUT_WIDTH) if width : width[c4d.DESC_CUSTOMGUI] = c4d.DTYPE_STATICTEXTThe 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!
-
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 yourInitfunction. Otherwise uninitialized type will be aint.
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
STATICTEXTorSTRING. It does create the expected fields. The StaticText can't be Animated anyway, i would remove theANIM OFFSTATICTEXT 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