Cornucopia3D Forum Index > Vue - Python Scripting View previous topic :: View next topic  

Pathnames in VuePython for loading Scenes, Objects, etc

Author

PostPathnames in VuePython for loading Scenes, Objects, etc 
    Posted: 02/07/2006 9:21 pm
 

I thought I would share this little gem of a problem I had regarding setting path variables in VuePython to ensure you can accurately locate files and directories programmatically. The basic problem is that when you start a Vue Python script fron the Vue Python shortcuts menu it will start the script from wherever the last current working directory was set. So for example, if you loaded a scene file and then executed a Python script by selecting its name from the shorcuts list, the script would execute thinking that the current path is the Vue Scenes folder. So if your Python script wanted to load a web page or load a file from some location based on a relative path, you would either have to give it an explict full pathname (not a good idea for cross platform usage) or find a reliable relative starting point from which you could find your files. I found a solution by using the later method:


# get the Vue python path
VuePythonPath = sys.path[1]

# get the Vue Python Folder
VuePythonFolder,junk = os.path.split(VuePythonPath)

# Get the Vue Root Path
VueRootPath,junk = os.path.split(VuePythonFolder)

From the Vue Root Path, I can find anything I need programmatically (e.g. scripts, scenes, objects, materials, etc)

One other thing to keep in mind. The PC and Mac use different directory and file seperators. The PC uses backslashes (\) while the Mac uses forward slashes (/). So if you are going to join a path, use Python's:

os.path.join (VueRootPath,"Materials/Basic.mtl")

The PC accepts forward and backward slashes. As an added measure of saftey, you could use:

os.path.abspath(os.path.join(VueRootPath,"Materials/Basic.mtl"))

which returns an absolute path using the slash convention of the operating system platform

 
Dave Burdick


Joined: 08/23/05
Posts: 956

Reply with quote

Post 
    Posted: 02/09/2006 5:29 am
 

Thanks.

I'd been struggling with this in a script I wrote that sometimes worked and sometimes didn't. When I get some time I'll go back and look at it again to see if I can get it to work all the time now.

 
Mark Caldwel...


Joined: 08/01/05
Posts: 348

Reply with quote

Display posts from previous:   

 
New Topic
Reply
         UsergroupsUsergroups       Log in to check your private messagesLog in to check your private messages