그래서 포럼에서 내 첫 번째 질문이며 올바른 일을하기를 바랍니다. 일반 질문 : 변경하려는 컨텍스트 또는 매개 변수에 따라 사용자가 다른 데이터 유형의 값을 입력 할 수 있도록 스크립트를 작성할 때 파이썬이 오류를 반환하지 않도록하려면 어떻게해야합니까? 더 구체적 : 저는 python을 처음 사용하며 The Foundry 's Nuke의 사용자가 동일한 클래스의 여러 노드에서 값을 한 번에 변경할 수있는 스크립트를 작성하려고합니다. 변경하고자하는 매개 변수가 체크 박스 ('bool')인지, RGBA 입력 ('4 float')인지에 따라 입력이 다른 유형이어야합니다. 포럼을 검색 한 결과 형식이 () 유형으로 확인되었으며 isinstance() 함수의 if 문과 비교되었습니다. 나는 그것으로 일할 수 있다고 생각하지만, 예를 들면. Gradenode의 곱셈 노브는 'AColor_Knob'유형을 반환합니다. 나는 플로트 같은 것을 기대했다. 그리고 그것을 isinstance()에서 비교해도 비교 대상인 데이터 유형에 관계없이 일치하지 않습니다. 지금까지사용자가 모든 데이터 유형 (str, float, int, boolean ...)을 입력 할 수 있는지 확인하는 방법은 무엇입니까?
Mainscript : 나는 지금까지 데이터 유형을 확인하는 방법
nukescripts.clear_selection_recursive()
userInput = nuke.getInput('Which type of nodes would you like to select? (!!!first char has to be capitalized!!!)',
'Shuffle')
matchingNodes = []
for each in nuke.allNodes():
if each.Class() == userInput:
matchingNodes.append(each)
else:
pass
for i in matchingNodes:
i.setSelected(True)
nuke.message(str(len(
matchingNodes)) + ' matching Nodes have been found and are now selected! (if 0 there either is no node of this type or misspelling caused an error!)')
userInput_2 = nuke.getInput('Which parameter of these nodes would you like to change? \n' +
'(!!!correct spelling can be found out by hovering over parameter in Properties Pane!!!)',
'postage_stamp')
userInput_3 = nuke.getInput('To what do you want to change the specified parameter? \n' +
'(allowed input depends on parameter type (e.g. string, int, boolean(True/False)))', 'True')
for item in matchingNodes:
item.knob(userInput_2).setValue(userInput_3)
:
selected = nuke.selectedNode()
knobsel = selected.knob('multiply')
print(type(knobsel))
#if type(knobsel) == bool:
if isinstance(knobsel, (str,bool,int,float,list)):
print('match')
else:
print('no match')
답변 해 주셔서 감사합니다. 저는 초보자로서 많은 것을 배웠습니다. 그러나 나는 당신이 허용한다면 몇가지 질문을 가지고있다 : 나는 tcl에 익숙하지 않다. 그래서 무엇이 "노브 루트. {0}. {1}"{2} " '. format (node.fullName(), knob_name, knob_value)'do? 또한, 나는이 형식을 본 적이 없다 :''new = {} (예)''파이썬은 '(예)'로 무엇을해야하는지 어떻게 알 수 있습니까? – leabum
@leabum 문자열 형식을 조회하고 싶습니다. 여기에 몇 가지 링크가 있습니다 : formatstrings pep-3101 str.format Nuke의 TCL 명령에 대한 정보를 포함하도록 위의 원래 게시물을 편집했습니다. 그런데이 게시물은 python-3.x 태그가 붙어 있지만 Nuke는 여전히 2.7 (현재 버전 10.x)에서 실행됩니다. –