>
> I have managed to use multiple dropdowns in this form incidentally, not the
> neatest, but does work.
>
Yes, I meant more in the line of when/if you eventually need to set some
callbacks to populate dropdowns based on the choices made on other
dropdowns, etc. At that point you will definitely benefit from using a
PythonPanel instead.
I've done some more testing, and it gets weirder, it starts to lose its
> factor of 4 as the list gets longer.
>
If you use the .index() method on a string object, the string essentially
becomes a "list of characters", so you're definitely getting an index to
that "list of characters" instead of your original shot items. From the
Python docs:
*string.find(s, sub[, start[, end]])*
Return the lowest index in s where the substring *sub* is found such that *
sub* is wholly contained in s[start:end]. Return -1 on failure. Defaults for
start and end and interpretation of negative values is the same as for
slices.
*string.index(s, sub[, start[, end]])*
Like find() but raise ValueError when the substring *sub* is not found.
If you really must use a string for other reasons, then just keep it as a
separate object, but use your original list for indexing.
For example, instead of:
shots = ' '.join(shots)
do:
shotString = ' '.join(shots)
And then:
r = nuke.Panel("SenateVFX Shot System")
r.addEnumerationPulldown("Please choose a Shot:", shotString)
if r.show():
shot = r.value("Please choose a Shot:")
index = shots.index(shot)
I don't know what other operations you need to do on that string, but I'd
still recommend doing them on the list instead. It should be a lot easier.
Hope that helps.
Cheers,
Ivan
On Wed, Sep 28, 2011 at 9:38 AM, tntdyna <[email protected]
> wrote:
> **
> Hi,
>
> Thanks for the replies! As pointed out initially, I'm collapsing the shot
> list so that I can put it into an Enumerationpulldown, this is embedded into
> the workflow but will perhaps have a look into using PythonPanel instead at
> somepoint. I have managed to use multiple dropdowns in this form
> incidentally, not the neatest, but does work.
>
> I'm having to collapse the shot list into a string, as I didn't mention
> that more than one artist name could be returned and the format they were
> being returned lent itself most easily to being manipulated as a string (I'm
> doing a name comparison as well).
>
> Ivan, I think that you might be right when you said its looking at the
> index of the character where the 1st match starts. Though the only 4 I can
> see being coincidental are the 4 sets of data being pulled from the
> database. I've done some more testing, and it gets weirder, it starts to
> lose its factor of 4 as the list gets longer.
>
> I think I need to go do some more testing and try and make my code a bit
> prettier than it is at the moment.
>
> Thanks for the help
>
> *ivanbusquets wrote:*
> As Alex said, you're collapsing your shot list into a string, and then
> indexing to that string, in which case you get the index of the character
> where the first match starts. It is coincidental that these are increments
> of 4 (or it means that all your shot names have 4 characters).
>
> My guess is you're just building that string so you can feed it to your
> EnumerationPulldown. In that case, just create a separate object for that,
> but use your original list to index into.
>
> You could also use a PythonPanel instead of the older nuke.Panel, which
> would allow you to use regular Enumeration Knobs and have access to any of
> its methods (like setValues(), which you could feed your list). Doesn't look
> necessary for the example you've shown, but if you plan on expanding your
> panel to include multiple dropdowns, etc., it might be worth switching to
> using PythonPanels.
>
> Cheers,
> Ivan
>
>
> On Wed, Sep 28, 2011 at 8:15 AM, Alex Schworer ** wrote:
> *Quote:*
> Just after a glance, but are you sure you want to do:
> shots = ' '.join(shots)
>
>
> That will create a long string out of the list of shots you grabbed from
> your DB, which unless you're printing that string to the console somewhere,
> you almost certainly don't want.
> --alex
>
>
> On Sep 28, 2011, at 7:46 AM, "tntdyna" ** wrote:
>
>
>
> *Quote:* Hi All,
>
> I'm getting a funny bug in some of my python coding that I hope someone
> might be able to help me out with.
>
> The background: I have a custom start up panel that links into the write
> node, with the data being pulled from a SQL database through an ODBC
> connection. It provides the artist with a drop down of projects that they
> can select, and then gives them a list of the shots that they are working on
> for that project. This then sets several knobs on a custom tab on the write
> node which are, project, shot and resolution. The part I'm having trouble
> with is the resolution�
>
> When the shot is chosen two arrays are created, one containing the shot
> names and the other the corresponding resolutions at the same index. To get
> the correct resolution I do a comparison of the shot to the items in the
> list to get its index, and then use that to pull the resolution. The issue
> is that the index that I get from the comparison is a factor of 4. For
> example, if I want to get the 1st or 2nd index (e.g. resolution[0]) of the
> resolution list I have to divide by 4. If I want to access only the 1st 4
> items in the list then I divide by 8, for the 1st 6 items then 12. e.g. if I
> have a list of 10 items, if I divide the index by 8 I will only be able to
> get values for the 1st 4 items, the other 6 will claim 'list index out of
> range'. I've tested the code in a python shell, and in the Nuke script
> editor itself, and they both produce the correct output, it only seems to be
> when Nuke is starting up that the multiplication is occurring.
>
> I'm hoping that someone can tell me whether its my code, or Nuke that is
> causing the problem. I don't think its my code, as explained above it works
> in the python shell. Below is the relevant code:
>
> Code: production = 'some_project'
> shots = []
> res_list = []
> for shot in cursor.execute("SELECT name, shot, resolution, project FROM
> table WHERE project = '"+production+"' ORDER BY production"):
> � �s = str(shot)
> � �ss = eval(s)
> � �shots.append(ss[1])
> � �res_list.append(ss[2])
> � �� �
> shotarray = string.join(shots, ',')
> shots.append('None')
> res_list.append('')
> shots = ' '.join(shots)
>
> r = nuke.Panel("SenateVFX Shot System")
> r.addEnumerationPulldown("Please choose a Shot:", shots)
> if r.show():
> � �shot = r.value("Please choose a Shot:")
> index = shots.index(shot)
> real_index = pos / 8
>
> The result of the above would be: shots = [shot1, shot2, shot3, �],
> res_list = [1024x576, 1280x720, 1920x1080, �], index = 16, real_index = 2.
>
> Thanks for any help.
>
>
>
>
>
>
>
>
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
>
>
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python