Jump to content

scripting question


Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :(

Link to comment
Share on other sites

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??? :angry:

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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. :D

Link to comment
Share on other sites

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

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...