Jump to content

Hscript For Loop Issue


SpencerL

Recommended Posts

Hey,

I am using a for loop to import bgeos through a File SOP into my scene after they are rendered out. Here is my code so far

set t = 1
for $t = 1 to 3
opadd -n file Chunk$t
oplocate -x -8 -y -25 Chunk$t
opwire Chunk$t -$t merge1
set t = `$t+1`
end  

when i run it, it creats all 3 File Sops, but only oplocates and opwires the first one into the merge SOP. I am not really sure why it would only do it once when it apparently does run the loop 3 times since three File SOPs are created. Any suggestions?

I have also already looked at 'Import Obj, several files in one go' post to try to get some answers, but doesnt seem to work for me.

Thanks

-Spencer

Link to comment
Share on other sites

Your for loop syntax is wrong. The $t there should not have the dollar sign since it will then expand to "for 1 = 1 to 3". So you actually want "for t = 1 to 3". Your second mistake is to note that the for loop will change the counter t for you. So you don't need that extra logic for incrementing t yourself. Finally, I believe that input numbers start from 0, not 1. Putting that all together we have:

for t = 1 to 3
    opadd -n file Chunk$t
    oplocate -x -8 -y -25 Chunk$t
    opwire Chunk$t -`$t-1` merge1
end

Link to comment
Share on other sites

Thanks Edward,

Sorry if I wasnt clear about this, but the reason I had `set t=1` before the loop was that when I didnt, $t would output Chunk3, Chunk4, and Chunk5. resetting $t back to 1 seemed to be the only way to reset the value. not really sure why?

Ive tried switching the variable name to $i and it returns Chunk1, 2, and 3 the first time I run the loop, but any time after it returns Chunk3, 4, and 5 and this is after I have deleted the new Chunk File SOPs that it creates.

And I still have the same issue where Oplocate works on the first file SOP it creates and now Opwire works, but it wires the first File SOP `Chunk3` three times into the merge instead of wiring each one into the merge.

Thanks

-Spencer

Link to comment
Share on other sites

It wasn't incrementing because in your for loop line, you (wrongly) used $t instead of t. You might have screwed up the input state of the merge sop in your bad scripts because you didn't use `$t-1`. If you look at the merge sop's parameters, make sure there's no entries in it. You need to click on all the red x's to remove them. To be safe, delete your merge1 sop and recreate it. Finally, your oplocate works exactly as expected since it's told to put all three nodes in the same location. You would need to vary one of the x or y parameters for each one to see them placed in different locations.

PS. All this might also be confusing you if you already have Chunk1,2,3 SOPs in your network. Start a new file, dive down in /obj/model, create a merge1 sop. Open up a textport, cd /obj/model. Copy/paste the script I have above into the textport.

Link to comment
Share on other sites

the for loop does work fine when I run it in the Textport, but since I am using this in a HDA it needs to run in a post render script. Its when I run it in there that it does not work properly. Is there something else I need to do if I am going to run it in a ROP post render script?

PS the reason i use $t instead `$t-1` in my script is because i do already have one input into the merge SOP before the loop is run so the next input is 1 not 0.

Link to comment
Share on other sites

The only difference that I can see is that your working directory is not correct. Try putting an opcf at the beginning of the script to make sure it's at the right location. Other than that, I would hazard a guess that you haven't fixed your script correctly in the HDA and/or not running the script that you think you're running.

Link to comment
Share on other sites

  • 4 weeks later...

I have similar problems.... with my python script.. and I found that houdini needs different time for differnt hscript commands...

for example.. try using "opset" on a facet for example to enable cusp.. and post computer normal... I need to use a "sleep()" python function after each of 'em.. to make 'em working ... same for display and render flag.

apprently the Hscript is a sort of read/write to the Houdini gui which didnt "lock" the things until they're done..but it just goes on with next command anyway ...

in my case.. i firstly tought the socket connection wasnt fast enought.. but now i'm sure its the houdini gui isnt to support Hscript.. Or.. is just me which I'm doing something wrong here...

:)

Link to comment
Share on other sites

I have similar problems.... with my python script.. and I found that houdini needs different time for differnt hscript commands...

27393[/snapback]

I'm curious ... is there still a problem if you create one long command separated by semi-colons?

For example, instead of:

"opadd..."

"opparm..."

"opwire.."

What happens if you do:

"opadd... ; opparm... ; opwire..."

?

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