Friday, August 30, 2013

Lazy - Efficient, Potato - Potaaahto

I don't really tend to share my most complex and production related scripts because this is more of a tutorial and tip related blog.  In that same vane I have mentioned in the past that there are times that you do the same task several times or come up with a new procedure that you implement in several jobs that just begs for a simple script.  This is one of those times.

I have found over the years that having a simple command that saving the current states of things so you can recall them later is a big time saver.  For example save the current window display parameters so you can come back to the same settings later, or save the layer on/off states for easy recall.  There are ways to do stuff like this but I just want one two letter macro to save something and another to restore it.  Lately I have been working with 5-6 files at a time and if I jump out of the program or switch from VrOne to VrTwo I want to open the same files.  Hence StoVr.py, and GetVr.py to take a snapshot of open files and re-open them if I need to.

print 'stovr.py modified 9:08 AM Friday, August 30, 2013'
# Store Vr filenames of open files for later recall
'''
Copyright 2013 Dennis Shimer
No warranties as to safety or usability expressed or implied.
Free to use, copy, modify, distribute with author credit.

Echos the names  of currently open files to the command windows
and saves them for later recall.
'''

Ws=PyVrWs()
WorkSpaceCount=Ws.GetWsCount()
print 'File names saved'
if WorkSpaceCount:
    SaveFileNamesFile=open(VrCfg().GetVrHomeDir()+'\\hostdir\\SavedVrFileNames.txt','w')
    for WsNum in range(WorkSpaceCount):
        SaveFileNamesFile.write(Ws.GetFileName (WsNum)+'\n')
        print Ws.GetFileName (WsNum)
    SaveFileNamesFile.close()
else: print 'No workspaces open'

print 'getvr.py modified 9:08 AM Friday, August 30, 2013'
# Get Vr filenames previously stored
'''
Copyright 2013 Dennis Shimer
No warranties as to safety or usability expressed or implied.
Free to use, copy, modify, distribute with author credit.

Echos the previously saved names to the command window with
workspace numbers as they are opened.
'''

Ws=PyVrWs()
SaveFileNamesFile=open(VrCfg().GetVrHomeDir()+'\\hostdir\\SavedVrFileNames.txt','r')
FileNameDataList=SaveFileNamesFile.readlines()
for FileName in (FileNameDataList):
    PyVrGui().PushKeyin ('opevr '+FileName.rstrip())
    print Ws.GetWsCount(),FileName.rstrip()
SaveFileNamesFile.close()

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.