使用getValue()时,Nuke下拉选择旋钮返回整数而不是字符串

2024-09-30 10:42:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在nuke中获取自定义下拉选择旋钮的value(),当我打印它时,它返回的是整数而不是Knob value,后者是一个字符串

ks = nuke.toNode('nodename').knob('pulldownchoice').getValue()
print ks

我希望输出是字符串,但我得到的输出是1.0


Tags: 字符串value整数printks旋钮nukeknob
2条回答

虽然在某些情况下,getValue()value()是可互换的,但是对于字符串,您必须使用value()方法,对于数字使用getValue()方法。在

In your case there are three methods available for accessing Enumeration_Knob values and one method for setting new ones:

  • getValue()给您带来一个数字(枚举所选对的索引)

  • value()会给您带来一个字符串(枚举所选对的名称)

  • values()为您提供所有字符串的列表(所有名称)

  • setValue()为旋钮设置一个新值(您可以在这里使用索引或名称)

You can use getValue() method for getting numeric properties like scale or rotate:

nuke.toNode('Transform1').knob('rotate').getValue()

nuke.toNode('Transform1')['rotate'].getValue()

nuke.selectedNode()['rotate'].getValue()

要打印所选节点的所有旋钮名称和相应值,请使用以下方法:

^{pr2}$

For pulldown menus 3 main methods are used – getValue(), value() and values() as well as setValue() method:

getValue()

g = nuke.toNode('Transform1')['filter'].getValue()
print(g)

# getValue() method brings properties' index (because it's enumerator)
# If your filter="Notch" getValue() brings 7.0 – i.e. eight element

# Result: 7.0

value()

v = nuke.toNode('Transform1')['filter'].value()
print(v)

# value() method brings a name of a chosen filter

# Result: Notch

值()

vv = nuke.toNode('Merge1')['bbox'].values()
print(vv)

# values() method brings a list of all strings stored in enum

# Result: ['union', 'intersection', 'A', 'B']

setValue()

s1 = nuke.toNode('Merge2')['operation'].setValue(0)

# setValue() method sets a new existing value in enum with index 0

# Result: atop

s2 = nuke.toNode('Merge3')['operation'].setValue("xor")

# setValue() method sets a new existing value in enum with name "xor"

# Result: xor

答案很简单,只需使用.value()而不是.getValue(),然后它将返回字符串而不是整数。在

感谢tk421storm

相关问题 更多 >

    热门问题