itriix Posted November 20, 2008 Share Posted November 20, 2008 Hey everyone, I'm writing a python script that will do a few different things: essentially, it will create a number of file nodes, based on how many .bgeos are in a sequence. then it will merge all of the file nodes together.... well the issue i'm having is trying to READ in and navigate within the houdini python shell. example: in a folder on my harddrive i have a sequence of bgeos... girl.1.bgeo, girl.2.bgeo... etc.... from python shell, how can i read in the sequence containing the name girl.$F.bgeo... essentially, and THEN, find out which one has the largest number... *the last one in the sequence.* i will use this number in my script to decide how many file nodes to create.... yes i know i can do all this just by looking in the folder myself and setting the number in my script manually however that defeats the purpose, plus im just curious how to navigate python appreciate everyones thoughts J Quote Link to comment Share on other sites More sharing options...
mic Posted November 20, 2008 Share Posted November 20, 2008 to browse files and change directory to your path you should use 'os' module, for example, import os path =os.getcwd() a = os.listdir(path) prints to a all files in your current work directory ( python path by default ) to change directory use os.chdir() method. and import glob b = glob.glob('*.bgeo') will create the array with all your .bgeo files len(b) gives you the number of your files. Quote Link to comment Share on other sites More sharing options...
itriix Posted November 20, 2008 Author Share Posted November 20, 2008 that's fantastic thanks! just for my own knowledge, what if the folder that had all the bgeos, had different kinds, such as: girl.1.bgeo, girl.2.bgeo, wildman.1.bgeo, wildman.1.bgeo... if all i wanted were the girl bgeos... how do i do that? in your example: import glob b = glob.glob('*.bgeo') could i do: import glob b = glob.glob('girl.*.bgeo') to browse files and change directory to your path you should use 'os' module, for example, import os path =os.getcwd() a = os.listdir(path) prints to a all files in your current work directory ( python path by default ) to change directory use os.chdir() method. and import glob b = glob.glob('*.bgeo') will create the array with all your .bgeo files len(b) gives you the number of your files. Quote Link to comment Share on other sites More sharing options...
mic Posted November 20, 2008 Share Posted November 20, 2008 that's fantastic thanks!just for my own knowledge, what if the folder that had all the bgeos, had different kinds, such as: girl.1.bgeo, girl.2.bgeo, wildman.1.bgeo, wildman.1.bgeo... if all i wanted were the girl bgeos... how do i do that? in your example: import glob b = glob.glob('*.bgeo') could i do: import glob b = glob.glob('girl.*.bgeo') hmm, yes of course, check it=) Quote Link to comment Share on other sites More sharing options...
itriix Posted November 20, 2008 Author Share Posted November 20, 2008 true! so i just checked it... len( is returning 0 so i tried to see what the os.getcwd() was getting, and it looks as though it's getting the root level of my computer directory... just a / but my hip directory is at a different location. i checked my environment variable for $HIP and it's in the correct location... a long path name any ideas how to get my $HIP directory to be used? Thanks again. currently still a little new to the combo of python and houdini. there's been a few things that just don't seem as intuitive as i'm used to doing Quote Link to comment Share on other sites More sharing options...
itriix Posted November 20, 2008 Author Share Posted November 20, 2008 just reread what you wrote... didn't see the os.chdir() method earlier i will try now.... Quote Link to comment Share on other sites More sharing options...
mic Posted November 20, 2008 Share Posted November 20, 2008 aha =) it is useful to explore 'os', 're', 'glob' and other modules in py for quick solving such small tasks.. Quote Link to comment Share on other sites More sharing options...
itriix Posted November 20, 2008 Author Share Posted November 20, 2008 okay well i tried it a few times with nothing but errors... path = os.chdir("/Users/Me/School/Directed_Study/week10/") seems to work but then when i do: returns an error. but i've copy and pasted the path into the script so it's the correct path... a = os.listdir(path) Quote Link to comment Share on other sites More sharing options...
mic Posted November 20, 2008 Share Posted November 20, 2008 hm os.chdir("/Users/Me/School/Directed_Study/week10/") path = os.getcwd() a = os.listdir(path) Quote Link to comment Share on other sites More sharing options...
itriix Posted November 20, 2008 Author Share Posted November 20, 2008 That was it! Been playing with this all day, so i think my brain is kinda loopy! appreciate it! thanks J Quote Link to comment Share on other sites More sharing options...
itriix Posted November 20, 2008 Author Share Posted November 20, 2008 actually while we're on the topic, i do have a new question: i'm noticing that by using this os.chdir("path") process, it's definately going to be machine dependent so when i move my files somewhere else, i'll have to update it. i'm thinking if i keep to a structure such as $HIP/Week10/bgeos then no matter what computer i go to, the script will work... are you aware of any method to use some path as such? maybe using a different method than the os.chdir and os.getcwd method? Quote Link to comment Share on other sites More sharing options...
rdg Posted November 20, 2008 Share Posted November 20, 2008 actually while we're on the topic, i do have a new question:i'm noticing that by using this os.chdir("path") process, it's definately going to be machine dependent so when i move my files somewhere else, i'll have to update it. i'm thinking if i keep to a structure such as $HIP/Week10/bgeos then no matter what computer i go to, the script will work... are you aware of any method to use some path as such? maybe using a different method than the os.chdir and os.getcwd method? If you move your code into the pythonModule of a HDA - which can be made from an empty subnetwork - you can use the gui items like browse for file - to set you variables: http://www.sidefx.com/docs/houdini9.5/hom/assetscripts Quote Link to comment Share on other sites More sharing options...
mic Posted November 20, 2008 Share Posted November 20, 2008 .. and i don't know how to get $HIP in python.. maybe http://www.sidefx.com/docs/houdini9.5/hom/hou/Variable which is not yet implemented?.. Quote Link to comment Share on other sites More sharing options...
edward Posted November 20, 2008 Share Posted November 20, 2008 Can't you just use a Trail SOP followed by a Cache SOP? I've attached an example. geo_mosaic.hip Quote Link to comment Share on other sites More sharing options...
graham Posted November 20, 2008 Share Posted November 20, 2008 You can get $HIP in python using either: hou.expandString('$HIP') or hou.hscriptExpression('$HIP') Quote Link to comment Share on other sites More sharing options...
mic Posted November 20, 2008 Share Posted November 20, 2008 thank you, graham, answer was easy) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.