I am on dynamo 1.0.
Can a “python script” node in dynamo be used to execute notepad.exe with a text file preloaded? and if so how?
Thanks.
Are you trying to use some Python code that is saved as TXT and then run it in Dynamo? Is that what the question is? If that’s the question I suggest that you download a package called Ladybug and see how that is set up because I think @Mostapha is doing exactly that.
Ps. I don’t think you want to save that code as TXT. I would rather use the proper PY extension, but it should not matter if the TXT is properly formatted.
Hi Konrad. Thanks for the reply.
Ideally I would like the ability to execute notepad.exe with an already existing text file, so I could refer to it and edit that text file from within dynamo. I know that Excel can read and write from dynamo, but that seems like overkill for just a few paragraphs.
You need to be clearer about what you mean by “execute”. Do you want to use Dynamo to launch Notepad.exe and then write some lines or read some lines from it?
Please be specific about what you want to achieve, show a minimal sample file or a desired result.
Hi Nigel,
Did you try using notepad++. Its good for writing and modifying programming scripts. https://notepad-plus-plus.org/
Hi All.
Yes. I would like Dynamo (within revit) to launch Notepad.exe with a pre existing text file open within notepad so I can edit the text file. Then I would view and possibly even edit the text file. Then I would close the text file (and notepad would exit.) I would be left with dynamo still open with the current graph (.dyn) still loaded.
I see the use of this (if it’s possible) as something used for reference e.g a list of sizes or keyboard shortcuts etc., and obviously only maintain one copy of the information ( the text file). There are a lot of easier ways or work arounds, but I am curious if dynamo would be suited. I am not needing to write the contents of the textfile for further manipulation or use within dynamo.
You can simply use notepad.exe and pass the file name. Lines below opens up C:\test.txt
import os
os.system("notepad {}".format(r"C:\test.txt"))
Mostapha, thanks for the reply.
I have copied your 2 lines into a “python script” node and when I run the (dyn) graph, the node turns orange with error message
Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 1, in
ImportError: No module named os
Not sure how to proceed further.
Thanks
That’s because you’ll need to add the path to the python library first. It might be simpler if you use the dotNet equivalent:
This is how you add the path, but this only works if python is installed in the default location.
Hi Einar
Thank you. Your code with only 3 nodes above works great. It loads up notepad with the selected file already open. My first use of it will be to maintain a list of dynamo keyboard shortcuts.
Thank you to all who contributed.
Node to take specific lists formatting and convert them into strings and write to a text file; then open the text file asynchronously to allow the script to continue.
import clr
clr.AddReference("RevitAPIUI")
from Autodesk.Revit.UI import TaskDialog ##Import task dialog
##from datetime import datetime ##Formatting date time strings for files
import time ##Time as in NOW or tiem string format functions
import sys ##Validate thie is here and avaiable#########
sys.path.append(r'C:\Program Files (x86)\IronPython 2.7\Lib')
import subprocess ##Launching asynchronus processess like notepad
import os ##Operating system - CASE SENSITIVE
msg=IN[0] ##DAta in 0
##msgbox=TaskDialog ##Task Dialog
astr="" ##STR for formatting
for i in msg: ##BIG MESSAGE LIST
sstr="" ##SUB STRING
for j in i:
for k in j:
sstr=sstr + str(k) + "\t" ##ADD TAB SEPARATORS
sstr=sstr + "\n" ##ADD CARRIAGE RETURN to substring
astr=astr + sstr + "\n" ##ADD substring to main and spacer carriage return
##Set file name using date-time in C:\TEMP####
fn="C:\\temp\\DynamoError-" + time.strftime("%Y-%m-%dt%H%M%Z") + ".txt"
f= open (fn, "w+") ##Open file wor Write
f.write(astr) ##Write out ASTR
subprocess.Popen('notepad {}'.format(fn)) ##Open the file in Notepad Asynchronously
##msgbox.Show("Message", astr ) ##Will show message dialog in revit - WARNING - Synchronus- script will have to wait.
OUT=astr ##Pass formatted string out