Import all Design Script Methods to Python

Currently, when we start a Python Script, the script starts with the import of the DesignScript.Geometry library. I’m no python expert, so does anyone know how to import the rest of the DesignScript libraries? Specifically, I want to use String.StartsWith, but Python tells me that it does not recognize “String” - which clues me in to needing to import some more things…

Ideas?

Hi Ben,

You can import the core list, math and string functions like so:

2015-10-01_23-13-20

Tho it might be a lot simpler if you use native python instead:

2015-10-01_23-13-43

Agreed Python might be easier…if you know by heart all of the ways to do things in Python. If i don’t know the python way, but i do know the Dynamo Node way, it’s much more efficient to Sketch it out in Dynamo , NodeToCode, then Copy/Paste into Python and modify as needed (compared to StrackOverflow searching). Yes it’s lazy, but it works. I really prefer this to DS because the If/ElIf/Else and Try/Except in Python are much more logical to me. Why reinvent something if i can get it in two seconds?

So if i wanted all string methods, would i follow “DSCore.String” with “import *”?

And if i wanted all list methods, “DSCore.List”? etc, etc…

I was just looking at setting up Python and some math modules on my mac graphic design rig at home. It’s that or keep learning Mathmatica 10 but that’s harder to get into REVIT later on. How much python code runs in Dynamo? It doesn’t seem to be a very well explored topic.

The Python in Dynamo is a little different than the Python that you would install as a stand-alone on your computer. It is IronPython. You can Google it and the differences in IronPython and Python. There are a few methods that might not be part of it, but I’ve found thus far i’m the limiting factor rather than Python. Also, Python is available in the Revit Macro editor, so learning IronPython will get you a skill you can use on two fronts (Dynamo and Revit).

Python is a very well explored topic here on the forum. Most any custom package you download (Clockwork, SteamNodes, Archi-Lab) is 75-80% python script. Google “archi-lab.net” and have a read through Konrad’s blog. Plenty-o-Python up in there. Also google Daren Thomas and the RevitPythonShell… Or search this forum for “Python” and look at any one of the 850 results.

1 Like

Ben,

clr.AddReference(‘DSCoreNodes’)
from DSCore import *

should import everything from core. Whatever is fastest for you is always the right way :slight_smile:

1 Like

This was a great help . Thanks Dimitar

I think the forums were down yesterday when I tried to reply to this thread. I looked up Iron python and was intimidated. While detailed posts about python applications in Dynamo exist here on the forums, I should have been more precise in stating there is little material on the relative merits of python in Dynamo/Revit, sort of on a strategic level versus specific examples. That kind of info would help me make choices about what approaches to try in parametric design. Furthermore, relative to the scale of the global internet, a few hundred posts here on the forums signals to me that expertise in applying python is scarce indeed. All the more reason we should try to learn it because it might become a valuable skill to certain employers in the future. For myself, as someone who is trying to learn Dynamo BIM, the smaller community also means there is few people to ask for help. (Compare here the Adobe Illustrator forums I participate in which are magnitudes bigger in size.) Of course, none of this should persuade one to stop learning Dynamo. I love to build and think Dynamo BIM is great!

1 Like

Blair,

I would definitely advise to learn Python as the first or “entry” language. It not only has been implemented in Dynamo and Revit via PythonShell (shutout to Darren Thomas), but it actually has been implemented in Revit Macro Manager. Now, with that being said it is a .NET implementation called IronPython but limitations are very specific and it might be a little while before you notice any difference. Also, it’s worth mentioning that other design software, namely Rhino and Grasshopper, have Python implementation. In Grasshopper you can download ghPython and Rhino has a Python editor built into it. Now, people will most certainly argue that C is the native language for all these programs but from experience I can tell you that if you need a quick and dirty hack to get something to work and get it out the door, Python offers a more immediate return on investment in all these packages. Now, if you wish to do some more serious developments you will eventually gravitate to C and knowing Python will not hurt you one bit. Good luck!

Ps. There is a lot more material available here that references Python than any other language. You will most certainly get your Python related questions answered here (of course in context of Dynamo).

Hope this helps. Good luck!

2 Likes