michael Posted April 19, 2003 Share Posted April 19, 2003 I've always heard that if find you have to do the same thing more than 10 times that it's a good candidate for a script...well I want to create 52 file nodes...so I would like to script it, but since I'm a novice scripter (at best) I'd like some advice... what I want to do is to tell Houdini to look in a folder and for every *.obj in that folder > create a geo node with the name of the obj as the geo's name > bring in the obj's one at a time.... I've looked into the opscript for the default file1 and get: opadd -n geo geo1 opcf geo1 # Node file1 opadd -n file file1 etc etc which is fine...great in fact - not as easy as Maya's 'echo all commands' but in the end it seems better - and while I know you can use for loops etc, and that you can direct Houdini to a file just by giving it the path, I have no idea how to create the path to 52 objects (they have unique names) inside of Houdini... should I just use Perl or something to build the cmd then source the cmd in Houdini? thanks Quote Link to comment Share on other sites More sharing options...
edward Posted April 19, 2003 Share Posted April 19, 2003 Untested script: (Be very careful with the single forward and backward quotes) opcf /obj set cmd = ' "ls-F c:/home/*.obj" ' foreach file ( `system("csh -c $cmd")` ) set geo_name = `substr( $file, 0, strlen($file)-4 )` set geo_obj = `opadd -nv geo $geo_name` opcf $geo_obj set file_sop = `opadd -nv file` opparm $file_sop file ( $file ) opcf .. end Quote Link to comment Share on other sites More sharing options...
michael Posted April 19, 2003 Author Share Posted April 19, 2003 thanks edward... I'll test it in the morning... looks like it will work, I guess what I was looking for was system()... Quote Link to comment Share on other sites More sharing options...
michael Posted April 19, 2003 Author Share Posted April 19, 2003 this is the script I'm using : set saved_path = `execute("oppwf")` # go into obj opcf /obj # create command to list obj's set cmd = ' "ls-F E:/Blocks_obj/*.obj" ' # loop foreach file ( `system("csh -c $cmd")` ) set geo_name = `substr( $file, 0, strlen($file)-4 )` set geo_obj = `opadd -nv $geo_name` opcf $geo_obj set file_sop = `opadd -nv file` opparm $file_sop file ( $file ) opcf .. end opcf $saved_path but I'm getting this error (52 times ) E:/blocks.cmd (14): Expression error: Syntax error - extra tokens detected in expression / E:/blocks.cmd (16): Expression error: Syntax error - extra tokens detected in expression E:/blocks.cmd (17): Can't find E:/blocks.cmd (18): Path .. not found any advice? Quote Link to comment Share on other sites More sharing options...
Jason Posted April 20, 2003 Share Posted April 20, 2003 i haven't tried it, but i think the line set geo_obj = `opadd -nv $geo_name` should be: set geo_obj = `opadd -nv geo $geo_name` I'm secretly hoping that there will be a day when dragging and dropping files from the windows explorer or linux file managers will create the relevant nodes. Not terribly important but it could be easy to implement, and it'd be pretty useful. Quote Link to comment Share on other sites More sharing options...
edward Posted April 20, 2003 Share Posted April 20, 2003 Thanks for the correction, Jason! I did say it was untested right? Quote Link to comment Share on other sites More sharing options...
Jason Posted April 20, 2003 Share Posted April 20, 2003 Yeah, I was just cursing your bad scripting skillz back there. Lucky you have us here to correct you, eh? ;-) Quote Link to comment Share on other sites More sharing options...
michael Posted April 20, 2003 Author Share Posted April 20, 2003 thanks guys...but I get the very same errors : E:/blocks.cmd (14): Expression error: Syntax error - extra tokens detected in expression / E:/blocks.cmd (16): Expression error: Syntax error - extra tokens detected in expression E:/blocks.cmd (17): Can't find E:/blocks.cmd (18): Path .. not found Alex and I worked on it a bit yesterday but coudn't get it to work.... I think I'll do it out of Maya - since that's where the obj's are coming from I might as well write the cmd to bring them into Houdini at the same time...it will be messy though Quote Link to comment Share on other sites More sharing options...
michael Posted April 21, 2003 Author Share Posted April 21, 2003 well....I got something to work out of Maya... OBJ2Houdini.mel it's ugly but it works select an object (polys) and run the script, it asks for a destination directory, then exports the objects as obj's, and builds a cmd file in that dir that can be sourced in Houdini... Quote Link to comment Share on other sites More sharing options...
anakin78z Posted April 21, 2003 Share Posted April 21, 2003 this here worked for me without a hitch: opcf /obj set path = "$HOME/geofiles/" foreach file ( `system("ls $path")` ) set name = `strcat( "file_", substr( $file, 9, 4) )` set pathname = `strcat($path,$file)` opadd -n geo $name opcf /obj/$name opadd -n file $name opparm $name file ($pathname) opcf /obj end of course you can adjust the name to your liking. Anyhoo, hope this helps. P.S. Why can't I paste from the textport into a browser??? Quote Link to comment Share on other sites More sharing options...
michael Posted April 21, 2003 Author Share Posted April 21, 2003 thanks anakin78z... I used edwards "`substr( $file, 0, strlen($file)-4 )`" so what I have now is : opcf /obj set path = "$HOME/Blocks_obj/" foreach file ( `system("ls $path")` ) set name = `substr( $file, 0, strlen($file)-4 )` set pathname = `strcat($path,$file)` opadd -n geo $name opcf /obj/$name opadd -n file $name opparm $name file ($pathname) opcf /obj end and it works just fine.. now I just ned to update that mel script... Quote Link to comment Share on other sites More sharing options...
old school Posted April 22, 2003 Share Posted April 22, 2003 Not to beat this one to death but whenever I see strcat() I can't but add that you don't need to use strcat() but just use the "+" operand in the line. You can build strings using various bits without a maze of nested strcat()'s. set name = `strcat("file_", substr( $file, 9 4))` replaced with: set name = `"file_"+substr( $file, 0, strlen($file)-4)` P.S. Why can't I paste from the textport into a browser??? I can in windoze and linux. Just select the text, ctrl-c, then in your favourite editor ctrl-v. Houdini 6 even support multi-line selection>cutting and pasting. Quote Link to comment Share on other sites More sharing options...
michael Posted April 26, 2003 Author Share Posted April 26, 2003 I updated the script a little...now it will scale the objects by .1 before it exports them (by grouping them under a locator > scaling the locator > then exporting) then puts eveything back to normal... later I'll add the ability for the user to determine the scaling and also the name of the cmd file...and I think also allow the user to decide if they want all the obj's as objects or as sops in one object... anyway if you try it and have any problems let me know: OBJ2Houdini.mel 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.