Copy/Paste Python scripts from a text file

Hello everyone!
I’ve recently started studying Phyton scripts inside Dynamo and I’ve a problem that i haven’t been able to solve yet. When i finish a script that works fine i save it in a OneNote Notebook by copy/paste the script from the Python windows. When i try to copy/paste this text in a new python node it always give me this kind of error:

2020-02-16 10_36_51-Dynamo .
Even though the script is correct and it has no syntax errors, every time i have to write the script from scratch, it’s really annoying specially because i often have to switch from a dynamo version to another, so it’s impossible to copy/paste directly the python node. Anyway, i have the same error even when i copy the text from a dyn file of the same version.
What am i doing wrong?
Thank you very much!

Welcome to the Dynamo Forum @Paslet87

One thing it could be is when copying code from text files or even online is the code can lose its formatting and tabs are converted to spaces. Make sure all indents are as tabs and not mixed tabs and spaces.

Do you have an example of your code that is failing?

Thanks Daniel for your answer.
It seems there is an error almost in every line, in the image below there is a very simple python script where i’ve just added a few references. Even if i keep just the first line, where i import the clr, the error is the same even if there are no indentation or extra-spaces…

I’ve tried also to copy/paste from a .py file written with Visual Studio Code, the result is the same…

Can you do a screencast showing your process? This certainly works for me.

Also what version of Dynamo are you on?

Hi @Paslet87

Do you have pyRevit installed in your PC?

@JacobSmall I’ve registered a video where i copy/paste a working script from a .dyn file to a one note page and then copy/paste it from one note to a python script in a new .dyn file without success but i am not able to upload it because i am a new user. :cry: i am using the 2.0 version.

@Kulkul no, i haven’t pyRevit installed on my PC. Would it be of any use to solve my problem?

Tank you all guys.

Try post it again, and if that fails due to permissions, file size, or other reason use another hosting service like Dropbox, OneDrive, Box, GoogleDrive, or similar.

@Paslet87 don’t use the notebook. Better to use a python editor (notepad++, spider, etc). Save tour files in gdrive or onedrive. Use the node Python from string. This way you can still copy and paste(in nodepad++) and you don’t loose the formatting. Plus nodepad++ has more functionality than the dynamo python editor.

1 Like

@salvatoredragotta true, it seems that when I copy the text of the script in one note it loses its format. I saved it in a .py file and it worked fine, many thanks!

1 Like