Grasshopper

algorithmic modeling for Rhino

Hi Everyone,

I am trying to make a wrapper for an executable.

Firstly about the executable: Once its open the following appears as you can see I need to enter an input between 1 and 4.

Once I've done that I then need to enter another input between 1 and 8.

After this the executable will create a textfile from which I need to read some values back into Grasshopper.

I'm having a lot of issues with how to open this executable and then enter the values from GH (Using a virtual keyboard?) I've tried the code below in Python

import os

os.system("C:\EnergyPlusV8-1-0\PreProcess\CalcSoilSurfTemp.exe")

but I get an error and the command window closes immediately. I'm a bit lost on how to do this can anyone please point me in the right direction? I am using Python but if you know how to do this in C# or VB it would also be helpful.

Thankyou!

Views: 840

Replies to This Discussion

Hi Anton,

I'm not sure how virtual keyboard will work for you but to run the line try this:

import os
os.system("C:/EnergyPlusV8-2-6/PreProcess/CalcSoilSurfTemp/CalcSoilSurfTemp.exe")

You are trying the wrong filepath and also you need to use "/" or "\\" or put an r before the address in the filepath.

Hope it helps,

Mostapha

Also as far as I can see there is a batch file "RunCalcSoilSurfTemp.bat" that should let you pass the arguments from the command line.

Hi Mostpha

Thanks that line works the issue is now that I need to work out how to write a BAt file so that CalcSoilSurfTemp.exe uses the epw file.

Hi Anton, Try something similar to lines below in a bat file. You can pass the arguments using echo. In this example I'm sending 2 and 3 as inputs:

(
echo 2
echo 3
) |
CalcSoilSurfTemp.exe weatherFilePath

This are some seriously sexy options Anton.

I'm running a test now with a console app mockup and C#. I'll let you know what transpires.

I'm not getting anywhere invoking the app directly from C#. I attached the app here in case someone else wants to do some testing. It asks for two keypresses, then writes a file called output.txt in the same folder and exits.

Attachments:

Hi David

Thanks for your reply, Sorry I dont really understand what you are trying to do here. Using Mostapha's tips Ive now got the exe opening but I dont know the best way to generate key events in Python in Grasshopper could you point me in the right direction?

I didn't have your app, so I couldn't test anything. So I wrote this small console test app. I didn't manage to send keystrokes successfully though.

Just for everyone's future reference the best way to approach this is to create a bat file which then opens a text that contains the key strokes an explanation of this can be seen here:

http://steve-jansen.github.io/guides/windows-batch-scripting/part-4..., you need to use redirection to send inputs into a exe. 

To send a message to cmd you could create a virtual com port pairing and use
copy com2 con | whatever.exe
https://en.m.wikibooks.org/wiki/Serial_Programming/DOS_Programming
You could then send your commands to cmd using serial send via firefly or program it in Python. I would like to know if you got the virtual keyboard working and if so how. Thanks for the os.system command.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2022   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service