Hi Matt, Very in depth explanation. Thanks a lot.
I will see if I can process this tomorrow morning and get it to work. :) Cheers again Daniel Sweeney 3D Creative Director *Mobile:* +44 (0)7743429771 *Email:* dan...@northforge.co.uk *Web:* http://northforge.co.uk On Thu, Dec 4, 2014 at 3:59 PM, Matt Lind <speye...@hotmail.com> wrote: > A list is a 1-dimensional array. A combo box is a list of label/value > pairs using a 1-dimensional array to mimic a 2-dimensional array. the > _DefineLayout() callback is defined as such: > > def ComboTest_DefineLayout( in_ctxt ): > > oLayout = in_ctxt.Source > oLayout.Clear() > oLayout.AddEnumControl("List", ("chocolate", 0, "vanilla", 1, > "strawberry", 2), "Flavor", constants.siControlCombo ) > oLayout.AddButton("Update") > > return true > > > If we make some simple visual adjustments to how we write our code, it can > give us some basic insight how it works: > > list aComboBoxItems = ( > "chocolate", 0, > "vanilla", 1, > "strawberry", 2 > ); > oLayout.AddEnumControl( "List", aComboBoxItems, "Flavor", > constants.siControlCombo ); > > By putting each label/value pair on it’s own line, I visually make the > intended associations. when the list populates the combo box in the PPG, > the PPG shows the label in the menu, but when you change the parameter or > request the parameter’s value, you’ll receive the associated numeric > value. for example, if you choose “vanilla” in the PPG, querying the > parameter will return the value of 1. conversely, if you want a script to > update the PPG and display “strawberry” in the menu, you must assign the > value of 2 to the parameter (eg; CustomProperty.Parameters( “List” ).value > = 2). > > If we strip away the cosmetics and look at the underlying structure, the > list is a set of indices: > > # rewriting the list replacing the label/value pairs with their > respective indices: > list aComboBoxItems = [ > 0, 1, > 2, 3, > 4, 5 > ]; > > When the PPG is displayed, the menu only shows the even numbered indices > in the combo box. When you request the value or modify the value of the > parameter, you only have access to the odd numbered indices. To answer > your own question, if you want the label portion of the current combo box > item, you must extract the list and pull the even numbered index associated > with the value. > > example: > > CustomProperty = PPG.Inspected.Item(0); > oParameter = oCustomProperty.Parameters( "List" ); > > oPPGLayout = CustomProperty.PPGLayout; > oPPGItem = oPPGLayout.Item( "List" ); > aComboBoxItems = oPPGItem.UIItems; > > # assumes ‘value’ in the label/value pair is numbered in > ascending order from 0. > LabelIndex = ( oParameter.Value * 2 ) – 1; > Label = aComboBoxItems[ LabelIndex ]; > > LogMessage( "Label: " + Label, constants.siComment ); > > > Alternately, if you have no use for the value being a number, you can make > it a string with whatever you’d prefer to pass on to your render script. > for example: > > list aComboBoxItems = ( > "chocolate", "Chocolate", > "vanilla", "Vanilla", > "strawberry", "Strawberry" > ); > oLayout.AddEnumControl( "List", aComboBoxItems, "Flavor", > constants.siControlCombo ); > > > This, of course, precludes you from using the simple algorithm in the > previous example to extract the label portion of the combo box item. In > which case, you’ll need to traverse the odd numbered items in the list > until you find your desired value, then backup one index to get the > associated label. > > I’ve always found it good form to make your code visually tidy and neat as > it serves a few practical purposes: > > - easier to read > - can make code easier to understand > - makes inconsistencies easy to spot (ie; bugs and syntax errors) > > > Matt > > > > > > > > > Date: Thu, 4 Dec 2014 12:52:28 +0000 > From: Daniel Sweeney <dan...@northforge.co.uk> > Subject: Pulling a PPG combo box name into a Render token path - Help > please. > To: softimage@listproc.autodesk.com > Message-ID: > <CAH98=h4NXxEy479DTtWRUL=YxC8czgMgpdAW3Xr15=6kige...@mail.gmail.com> > Content-Type: text/plain; charset="utf-8" > > Hi List, > > First off I am no way a scripter. been trying to get this to work but > cannot. > > So I have some code to make a PPG with a combo box from stephen blair. > > http://xsisupport.com/2011/01/10/updating-a-combo-box-from-an-onclicked-callback/ > > now all I want to do is pull the Lable of the combo box into the render > path via > [Value] token > > when I pull in the combo box with [Value ComboTest.list] all it pulls in is > the array value. > > is there anyone that can help with this? > > Cheers. > > Daniel >