# Coding Python Nodes for Dynamo for Civil 3D in an External IDE

**URL:** <https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337>\
**Category:** Developers\
**Tags:** python, civil3d\
**Created:** [June 6, 2022, 4:28pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337 "2022-06-06T16:28:35Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 6, 2022, 4:28pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/1 "2022-06-06T16:28:35Z")

</div>

Coding python nodes for beginners here. What is a good way to set up an external IDE for python node development for civil 3d?

I see online that people have used “ctypes” to utilize .dll files in python. I also see that the default python nodes in dynamo “import clr”. I assume that’s referring to this package → [https://pypi.org/project/pythonnet/](https://pypi.org/project/pythonnet/)  
That would have to be installed into the external environment and then is that all that is needed? Then, the boilerplate code from the python nodes can be copied over into a jupyter notebook or any other IDE?

Does anyone have examples of doing this?

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 6, 2022, 4:42pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/2 "2022-06-06T16:42:23Z")

</div>

Looks like “clr” is allowing me to import the .dll files. and the

```auto
from Autodesk.AutoCAD.Runtime import *

```

type of code line is working fine but code such as:

```auto
import Autodesk.AutoCAD.ApplicationServices.Application as acapp

```

is not working. Guessing this is an issue with not having IronPython2 in my jupyter notebook IDE?

 ![ExampleCode](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/f/cfe8ed800b33b2fe26b0b74718ec694f105fd26a.png)

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 6, 2022, 4:47pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/3 "2022-06-06T16:47:53Z")

</div>

Guessing I just had to format it like this! Seems to be working…

 ![Proper Syntax](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/7/37b5ed8d479046c6be1478cf54d6c3a9a55ace63.png)

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 6, 2022, 11:15pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/4 "2022-06-06T23:15:08Z")

</div>

Trying to recreate this script in an external IDE to test but running into a problem already: [Rename XREFs in multiple dwgs - #29 by WrightEngineering](https://forum.dynamobim.com/t/rename-xrefs-in-multiple-dwgs/76331/29)

I’ve tried to use dir(Autodesk.AutoCAD.ApplicationServices.Application) and I can see that “.DocumentManager” is an available member but I get a `The type initializer for '<Module>' threw an exception.` error when I try to use it.

@jacob.small do you think this is because I am missing ironpython in an external IDE? I remember us talking about needing ironpython to get this to work for some reason. Is it possible to open and iterate through documents in an external IDE without ironpython? I seem to have been able to successfully import the .dlls and am very happy to be in a jupyter notebook instead of a python node but it would help if it was functional 😅

 ![OpeningDocumentsInExternalIDE](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/8/d8cf5d5c482ac49be21b419b14ae5bc80f443640.png)

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 7, 2022, 2:49am UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/5 "2022-06-07T02:49:20Z")

</div>

I think you need to save this and call it from inside the Dynamo for Civil 3D environment, although I haven’t attempted this type of setup before. Reason I think this is the case is that the Python file itself doesn’t have direct hooks into the active AutoCAD instance; DLLs are loaded sure, but you could load those without even having AutoCAD open after all.

There are two ways I have seen this done, load the .py in as a new library so you can call the definitions it contains, or by reading in the raw text of the file and using the [Pythton Script from String node.](https://dictionary.dynamobim.com/#/Core/Scripting/Action/Python%20Script%20From%20String)

That said, if you’re going to go though the trouble of setting up an external IDE, why not shuffle over to writing a zero touch node instead of Python based ones? They’ll be faster and more reliable as a result, with (as I understand it) minimal if any added effort beyond where you are going with this.

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 7, 2022, 3:34pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/6 "2022-06-07T15:34:13Z")

</div>

Jacob, Thanks for the reply!

That makes a lot of sense. In Dynamo, the Dynamo application is pointing to the active autoCAD application instance. I think reading the raw text of the file and using the python script from string node seems really useful but would mostly just be helping me not copy and paste as much to the python node in Dynamo.

I think the main draw for me to be able to use a jupyter notebook is that I can easily test and dissect code in bite size pieces without having to add comments repeatedly, easy access to documentation in the application without having to run the dynamo graph, ect. It has proved incredibly useful to me with ArcGIS Pro but I know there is something similar there where I have to actually load my jupyter notebook from the python environment that is installed with ArcGIS Pro to be able to code with “arcpy”.

But I think the advantages are very limited if I can’t actually run any code. I know @zachri.jensen had recommended using an external IDE such as pycharm for python nodes. Now I see that he was probably referring to coding in that environment and then copying it over? Not actually running the code in the external IDE.

Also, I hadn’t heard of “zero touch nodes” before. But after looking it up I see that they are custom nodes such as the nodes in the camber package, ect. My intent with this was to write code that can be copied and pasted into a python node to help those on the forums with discrete issues that don’t necessarily warrant its own node and can be edited by the individual in dynamo. I believe if I were to write “zero touch” nodes, they wouldn’t be editable by the users and they would be difficult to share without releasing as a package, correct? Also, I unfortunately only know Python/HTML/CSS/Javascript right now and have no C# experience. (Although I do plan to work through Anton’s book on C# for AutoCAD now that it is in English).

I think the following may be a good question for @solamour: Is there a way to “hook” into an active instance of the Civil 3D/AutoCAD application in an external IDE when using python?

---

<div class="post-metadata">

**Author:** ![mzjensen](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@mzjensen](https://forum.dynamobim.com/u/mzjensen)\
**Post date:** [June 7, 2022, 4:27pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/7 "2022-06-07T16:27:56Z")

</div>

> [@WrightEngineering](#):
>
> Now I see that he was probably referring to coding in that environment and then copying it over?

That’s correct. It would be a challenge to actually hook it up to an AutoCAD process (via COM API). There’s this example for Revit, but I haven’t seen it done with AutoCAD. Probably because if you’re going to go through all of that work, you may as well just write ZT nodes.

> [@Debugging Python Code](https://forum.dynamobim.com/t/debugging-python-code/12729):
>
> Made a shinny new development toy, I though it might be useful to a few of you; allows you to launch an interactive console from a breakpoint anywhere in your python code. Demo: More info here: [http://revitpythonwrapper.readthedocs.io/en/latest/forms.html#console](http://revitpythonwrapper.readthedocs.io/en/latest/forms.html#console)

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 7, 2022, 5:11pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/8 "2022-06-07T17:11:07Z")

</div>

Hmmm. Yeah and even that doesn’t seem to be running the file directly through pycharm. Looks like there is some “wrapper” that needs to be used? Would be really cool if I could connect a jupyter notebook directly to an AutoCAD process but even that example with revit doesn’t seem to have that functionality. Super cool though!! Maybe if I can learn more about the COM API I can get something working but it’s definitely beyond my skill set at the moment. For now I’ll probably be coding in an IDE and copying it over but I’ll definitely keep this on my “long list” 🙂 Thanks for the info!!

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [June 7, 2022, 5:25pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/9 "2022-06-07T17:25:46Z")

</div>

> [@WrightEngineering](#):
>
> I think the following may be a good question for @solamour: Is there a way to “hook” into an active instance of the Civil 3D/AutoCAD application in an external IDE when using python?

As it stands right now, unfortunately not. Python itself is technically operating in this way with Dynamo though, as we use a `bridge` to transfer data between both worlds. The Python node itself will execute in the Python VM, and the results will get spit back out in Dynamo after being passed back into Dynamo’s world.

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 7, 2022, 5:38pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/10 "2022-06-07T17:38:49Z")

</div>

Very interesting. So there is a `bridge` between the Python VM and Dynamo that is built into the dynamo source code? Which is written in C#? Is it possible to build a bridge using C# as well? If so, do you know of any good learning materials? I may be above my head but I’m just curious 🙂

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [June 7, 2022, 6:56pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/11 "2022-06-07T18:56:05Z")

</div>

It’s beyond me too 😃 The developers on the team are bonkers awesome.

We use [Python.NET](https://github.com/pythonnet/pythonnet) as the CPython3 flavour that can talk to the world of .NET which could be worth exploring 🙌

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 7, 2022, 7:07pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/12 "2022-06-07T19:07:59Z")

</div>

Amazing! Thanks for sharing.

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [June 7, 2022, 7:23pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/13 "2022-06-07T19:23:41Z")

</div>

I have a colleague in our consulting org who swears by writing his python code in .py files, and reading those into the Python environment as discussed above. If you’re just looking for the nicer IDE, the “save the file \> load the file” might be the best path forward for now.

---

<div class="post-metadata">

**Author:** ![WrightEngineering](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/wrightengineering/32/115676_2.png) [@WrightEngineering](https://forum.dynamobim.com/u/WrightEngineering)\
**Post date:** [June 8, 2022, 6:42pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/14 "2022-06-08T18:42:00Z")

</div>

It was worth a try but still didn’t work. 😂 I installed jupyter notebook with pip into the embed python environment that is installed with dynamo for C3D. Still getting the same initializer error when trying to get acapp.DocumentManager. I can run a jupyter notebook from that environment but it still doesn’t know how to connect into dynamo as sol has mentioned. There is no bridge when an IDE is opened, even from the same environment. Maybe this would be obvious to someone more knowledgeable but I thought I should at least give it a shot.

 ![Embedded Python Environment](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/e/beaee35984688daa2504ec5d75888b6e38552c56.png)

---

<div class="post-metadata">

**Author:** ![solamour](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/solamour/32/153516_2.png) [@solamour](https://forum.dynamobim.com/u/solamour)\
**Post date:** [June 8, 2022, 7:12pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/15 "2022-06-08T19:12:43Z")

</div>

@Michael_Kirschner2 @martin.misol any thoughts on how @WrightEngineering could start to integrate Jupyter Notebooks into Dynamo? Good places to look, or documentation to read?

---

<div class="post-metadata">

**Author:** ![jose.r.zavala](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jose.r.zavala](https://forum.dynamobim.com/u/jose.r.zavala)\
**Post date:** [December 27, 2022, 8:48pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/16 "2022-12-27T20:48:50Z")

</div>

@WrightEngineering I have been trying to do this exact same thing for a couple of weeks now to no avail. As a civil engineer, I am only versed in high level languages like Python and Matlab, with no C# experience. And while it seems my life would be easier by just learning C#, I would very much rather just use the tools I already know and write my stuff for AutoCAD/Civil3D in Python. Writing and debugging code inside Dynamo is just tedious, and it would be awesome if those two things could be done from an external IDE, that would also have access to the appropriate namespaces to help with autocompletion suggestions.  
It seems that the best solution for now is writing the code on an external IDE, albeit without access to the Autodesk namespaces, and importing it through dynamo’s ‘Python Script From String’ node. Then we would have to debug by commenting stuff out and playing with the OUT variable in a back and forth between Dynamo and the IDE.

I think this should be a common situation. Languages like Python and Matlab are the ones civil engineers are usually familiar with. It seems odd that there’s not more people trying to hook into an active instance of AutoCAD/Civil3D. I’ll keep looking and report back if I find a better solution!

---

<div class="post-metadata">

**Author:** ![duyematsu](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/duyematsu/32/158408_2.png) [@duyematsu](https://forum.dynamobim.com/u/duyematsu)\
**Post date:** [May 9, 2023, 4:11pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/17 "2023-05-09T16:11:31Z")

</div>

Thanks for asking about this. I’d also benefit from an external IDE of some sort.

@WrightEngineering my fastest workflow right now is to copy-paste back and forth between VS-Jupyter notebook and each of my Dynamo nodes. I create “inputs” similar to what the nodes would receive - can’t test C3D or ACAD objects in ipynb files though.

@zachri.jensen Thanks for all your work! Let us know when more things come out, would appreciate this a lot

---

<div class="post-metadata">

**Author:** ![ab.chakraborty](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ab.chakraborty/32/161083_2.png) [@ab.chakraborty](https://forum.dynamobim.com/u/ab.chakraborty)\
**Post date:** [May 12, 2023, 8:14am UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/18 "2023-05-12T08:14:13Z")

</div>

@duyematsu I thought I was the only person working like that. Have you across something new which we can use to our advantage of using IDEs for coding and debugging?

Also, on a side note do you know how I can use

```auto
import clr

```

and other imports in an external IDE? Or do they work only within Dynamo?  
Do I need to install something to access the dll files?

Sorry for asking so many questions but these would really make working with dynamo much easier.

---

<div class="post-metadata">

**Author:** ![duyematsu](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/duyematsu/32/158408_2.png) [@duyematsu](https://forum.dynamobim.com/u/duyematsu)\
**Post date:** [October 2, 2023, 6:30pm UTC](https://forum.dynamobim.com/t/coding-python-nodes-for-dynamo-for-civil-3d-in-an-external-ide/77337/19 "2023-10-02T18:30:57Z")

</div>

@ab.chakraborty very late reply haha

Nothing exciting in my VS Code - mostly used for checking syntax errors and working w/ strings and lists. Was very useful for quickly testing regex functions.
