Friday, April 20, 2007

Tag team programming

Not long ago I was corresponding with W. Chesson Godfrey aka Wild_Bill from the forum and he shared a little script with me. As so often happens when two people look at an issue from two different perspectives they will each solve the puzzle as it best suits their office culture. This is a little something I hadn't thought about before, which I changed to use some functions he wasn't using and shazam (is that a word) we have WsMan.py or workspace manager. Another reason why discussion is almost always a good thing. This stuff is just too cool.



PromBox=VrPromBox('Set Active Ws',60,1)
# The whole app revolves around a single convenient Prompt box, so create an object.
PromBox.AddMessage ("Don't change workspaces\n in the middle of a function")
# A little helpful text.
PromBox.AddCombo ('Workspaces',PyVrWs().GetWsCount(),0,0)
'''
We'll use a ComboBox as the user interface, so create it with the
number of items set to the number of workspaces. In this case I'm not
implicitly creating a workspace object. I just use the class to call
a method. Someday I'll test to see if this method of creating a
temporary object causes memory problems in things like large loops,
but for now I'm just illustrating that you don't necessarily need to
do the Ws=PyVrWs() thing.
'''
for WsNum in range(PyVrWs().GetWsCount()):
....PromBox.AddComboItem (PyVrWs().GetFileName (WsNum))
# For every workspace, get it's name and add it to the combo box.
if (PromBox.Display(0) == 0):
....PyVrWs().SetAws(PromBox.GetCombo(0))
# If the user didn't hit cancel, then set the active workspace
# to match the one selected.

Get involved in the forums, there is a wealth of experience to be shared.

No comments:

For anyone interested in trying VrPython for the first time or if you are early in the game, I suggest going to the earliest posts and working forward. I use VrPython every day for many wonderful things, needless to say it will change and could potentially damage a file. Any risk associated with using VrPython or any code or scripts mentioned here lies solely with the end user.

The "Personal VrPython page" in the link section will contain many code examples and an organized table of contents to this blog in a fairly un-attractive (for now) form.