1

Nuke の起動時に開き、いくつかのパラメーターを設定するパネルを作成しようとしています。

私がやりたいのは、同じパネルに一連のプルダウンを配置することです。プルダウン内のアイテムはフォルダーから取得されます。

私が抱えている問題は、最初のプルダウンを設定し、このプルダウンの選択から2番目のプルダウンがその選択を反映し、メニュー項目がその変更を反映し、各プルダウンで基本的にフォルダを掘り下げることです構造ですが、各プルダウン結果は変数として使用されます。

あまり進んでいませんが、

    import os
import nuke
import nukescripts

## define panel

pm = nuke.Panel("project Manager")

## create pulldown menus

jobPath = pm.addEnumerationPulldown( 'project', os.walk('/Volumes/Production_02/000_jobs/projects').next()[1])


seqPath = pm.addEnumerationPulldown('sequence', os.walk('/Volumes/Production_02/000_jobs/projects').next()[1])


shotPath = pm.addEnumerationPulldown('shot', os.walk('/Volumes/Production_02/000_jobs/projects').next()[1])


print jobPath
print seqPath
print shotPath

#pm.addKnob(job)
#pm.addKnob(seq)
#pm.addKnob(shot)

pm.show()

また、プルダウンに表示される文字列は [' ' などで囲まれていますか?

乾杯 - アダム

4

1 に答える 1

0

You probably want to use a PythonPanel, rather than the old-style Panel, which is basically a TCL wrapper. That way, you can get callbacks when the knobs in the panel are changed.

Here's a basic example:

import os

import nuke
import nukescripts.panels


class ProjectManager(nukescripts.panels.PythonPanel):
    def __init__(self, rootDir='/Volumes/Production_02/000_jobs/projects'):
        super(ProjectManager, self).__init__('ProjectManager', 'id.ProjectManager')

        self.rootDir = rootDir
        self.project = self.sequence = self.shot = None

        projectDirs = [x for x in os.listdir(rootDir)
                       if os.path.isdir(os.path.join(rootDir, x))]
        self.project = projectDirs[0]
        self.projectEnum = nuke.Enumeration_Knob('project', 'project', projectDirs)
        self.addKnob(self.projectEnum)

        self.seqEnum = nuke.Enumeration_Knob('sequence', 'sequence', [])
        self.addKnob(self.seqEnum)

        self.shotEnum = nuke.Enumeration_Knob('shot', 'shot', [])
        self.addKnob(self.shotEnum)

        self._projectChanged()

    def _projectChanged(self):
        self.project = self.projectEnum.value()
        projectDir = os.path.join(self.rootDir, self.project)
        projectSeqDirs = [x for x in os.listdir(projectDir)
                          if os.path.isdir(os.path.join(projectDir, x))]
        self.seqEnum.setValues(projectSeqDirs)
        self._sequenceChanged()

    def _sequenceChanged(self):
        s = self.seqEnum.value()
        if s:
            self.sequence = s
            seqDir = os.path.join(self.rootDir, self.project, s)
            seqShotDirs = [x for x in os.listdir(seqDir)
                           if os.path.isdir(os.path.join(seqDir, x))]
        else:
            self.sequence = None
            seqShotDirs = []
        self.shotEnum.setValues(seqShotDirs)
        self._shotChanged()

    def knobChanged(self, knob):
        if knob is self.projectEnum:
            self._projectChanged()
        elif knob is self.seqEnum:
            self._sequenceChanged()
        elif knob is self.shotEnum:
            self.shot = self.shotEnum.value()


p = ProjectManager()
if p.showModalDialog():
    print p.project, p.sequence, p.shot

Note that this example is only to demonstrate the basic design of a PythonPanel subclass. It has a few small logic issues (in the context of Nuke), and is written to be as clear as possible, rather than as efficient or idiomatic as possible.

Anyway, hopefully this gives you an idea of how to go about building what you're after.

于 2014-12-08T01:07:02.130 に答える