Jump to content

How to run python script node?


Shamanek

Recommended Posts

Hi guys,

a noob question here but I cannot continue without this and can't figure it out either.

How to run a python node? A guy in tutorial said ctrl+enter but that doesn't work for me and nothing happens in python shell.

 

image.thumb.png.b4463092f30adc52c7f4fbe30b233fed.png

Link to comment
Share on other sites

1 hour ago, jfaulkner said:

You'll need to assign the operation to a variable first and then output it using print()

Like:


var = 8+5
print(var)

 

But that still doesn't execute the code in the shell. Only when I put it directly into it or only if I use the Source Editor.

Does the ctrl+enter work for you?

Link to comment
Share on other sites

Dive inside the python node and place a null, anything will work just need something to have its flags on

Because the python nodes been created from obj level, it looks like it doesn't execute any script unless there's a node inside with its flags set on.

  • Thanks 1
Link to comment
Share on other sites

I was just about to write basically what jfaulkner just said, but he got there before me :lol:

What are you trying to do with this python node? Usually, python nodes are best suited (in my somewhat limited experience) to work with actual geometry in the scene. If you just want to make a tool or something else it is usually better to look into the source editor, the python module of an HDA or just a simple custom shelf tool.

Link to comment
Share on other sites

 

41 minutes ago, jfaulkner said:

Dive inside the python node and place a null, anything will work just need something to have its flags on

Because the python nodes been created from obj level, it looks like it doesn't execute any script unless there's a node inside with its flags set on.

I must do something wrong because that doesn't work for me yet.

image.png.3b4c379d0e5e8b65bc025df3948075d8.png

 

 

35 minutes ago, underscoreus said:

I was just about to write basically what jfaulkner just said, but he got there before me :lol:

What are you trying to do with this python node? Usually, python nodes are best suited (in my somewhat limited experience) to work with actual geometry in the scene. If you just want to make a tool or something else it is usually better to look into the source editor, the python module of an HDA or just a simple custom shelf tool.

I've just started with python. The reason I am doing this is that I want to know how it works and if it works. And the Varomix in his tutorial "Bites of Python" has a python node where he has written something simple and it is printed in the console after he hit ctrl+enter but that doesn't work for me.

So right now it is just a check on how to make it work before I start to do something more complex like manipulating geometry. And I am stressed out that it doesn't work rightat the start... :D :( 

Link to comment
Share on other sites

@Shamanek I would not stress out about this. It's not the end of the world if you don't get this one thing working.
Also, try doing this:
1. Add a null inside the python script node and make sure the display flag is on it

2. Jump back out to obj level and add this to the script field: print('hello world')

3. Hit ctrl+enter

 

This seems to be working for me. As long as the null node is inside the ctrl+enter thing works perfectly. The thing about executing code inside this node is that it does not echo back simple stuff like just writing 5+5, you have to explicitly call the print function to get anything out of this. However, if you use the python shell tab you'll get automatic echoing from simple stuff like 5+5.

Link to comment
Share on other sites

4 minutes ago, underscoreus said:

@Shamanek I would not stress out about this. It's not the end of the world if you don't get this one thing working.
Also, try doing this:
1. Add a null inside the python script node and make sure the display flag is on it

2. Jump back out to obj level and add this to the script field: print('hello world')

3. Hit ctrl+enter

 

This seems to be working for me. As long as the null node is inside the ctrl+enter thing works perfectly. The thing about executing code inside this node is that it does not echo back simple stuff like just writing 5+5, you have to explicitly call the print function to get anything out of this. However, if you use the python shell tab you'll get automatic echoing from simple stuff like 5+5.

Hmm, that's exactly what I did and it is not doing anything. Houdini v18.5.408
Check the file here please if the setup is the same as you have.

 

python_script.hiplc

Link to comment
Share on other sites

@Shamanek Try changing the thing you are printing from "hello world" to "foo bar" or anything else. It is a little fuzzy on opening the print dialog box if there haven't been any changes to the code since the last time you ran it. Your file worked for me by doing that. Also, try to make sure that the viewport is open since nodes in the node network don't always refresh and update if the viewport is not open.

Link to comment
Share on other sites

1 minute ago, underscoreus said:

@Shamanek Try changing the thing you are printing from "hello world" to "foo bar" or anything else. It is a little fuzzy on opening the print dialog box if there haven't been any changes to the code since the last time you ran it. Your file worked for me by doing that. Also, try to make sure that the viewport is open since nodes in the node network don't always refresh and update if the viewport is not open.

ohh, that's the thing. The viewport! It works now.
Thanks a lot! :) 

  • Thanks 1
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...