Jump to content

python script question


itriix

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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=)

Link to comment
Share on other sites

true! so i just checked it... len(B) 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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...