Grasshopper

algorithmic modeling for Rhino

Hi,

I have just started using GhPython, so the question might be very easy to answer.

I have created an external python script and I would like to run it from my GhPython script. If I want to do it in python the script would be:

import os

os.system("C:\Users\Stavroula\Desktop\test.py")

and it would execute the python script. When I use the same commands in GhPython it says that "Execution completed successfully" but it doesn't really execute the script.

Is there maybe another way to run external scripts-applications in GhPython?

Thank you for your time!

Views: 4193

Replies to This Discussion

Hi again,

in the end I think that the command is not the problem. I have tried to run Ansys in batch mode and even though it seems that it is opening the batch file in the end it is not calculating anything. It gives an error.

If I run the .bat file outside grasshopper then I have no problem.

So, i guess that the launching of applications from grasshopper is blocked. 

Does anyone know how to solve this issue?

Thank you!

Stavroula

If I run Rhino as administrator, then the .bat file is executed without problem. But still i can't make the .py file to run. 

If someone has an idea where might be the problem please let me know. Also, is there any other way to run .bat files, except for opening rhino as administrator?

Thank you in advance!

When I try to run an external program from within grasshopper, I do not have any access to thino or grasshopper until I quite out of the program.  This external program writes continuously to a file, the contents of which are read by another part of the grasshopper script.  It works when I fire up the external program separately (outside of grasshopper).

You can upload your file?

Sure!

I have created a simple python script that creates a .txt file and writes something in it and I am trying to ask it to run from GhPython. -> it is not working

I have also created a .bat file that runs ansys in batch mode and creates a results.out file. -> it is working.

I am using the same commands so I can't really understand the problem. If you can take a look it would be great.

p.s. you should change the directory where the file is saved in order to work.

Stavroula

Attachments:

Hi Stavroula

I would import the .py script as a python module. This means you can access the functions within the .py script.

I upload a modified .py script and gh script. You should make sure to change the sys.path.append('C:') to the place where you put your .py file. 

The output file will end up in c: as well. this can be changed in the .py file. 

I hope this helps

Henrik

Attachments:

Hi Henrik,

Thank you very much for your reply! I understand what you mean. I wasn't aware of this function. It is working perfectly!

Thank you again for the help!

Stavroula.

RSS

About

Translate

Search

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service