# Access PythonNode

**URL:** https://forum.dynamobim.com/t/access-pythonnode/77658
**Category:** Developers
**Tags:** python, dynamo
**Created:** [June 14, 2022, 10:05pm UTC](https://forum.dynamobim.com/t/access-pythonnode/77658 "2022-06-14T22:05:58Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mircoBianchini](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mircoBianchini](https://forum.dynamobim.com/u/mircoBianchini)
#### Post date: [June 14, 2022, 10:05pm UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/1 "2022-06-14T22:05:59Z")

</div>

Hi all,  
I would like to access a Python node and re-write the boilerplate script it has per default.  
I can retrieve the node from the model filter by type in this way.

```auto
dynamoViewModel.Model.CurrentWorkspace.Nodes.Where(node => node.NodeType == "PythonScriptNode");

```

But to access the ‘Script’ property I need to cust the nodes ad `PythonNode` that is a class in the PythonNodeModels.dll that is not provided by the different Dynamo packages.  
You could say, just reference that dll from the folder nodes inside Dynamo, but this means I need to remember to change this manually, all the time I am going to update the NuGet packages.  
So, I am thinking if there is another way that I don’t see to access this component.  
I am sure @john_pierson, you will have some good advice 🙂

Thanks, heaps!!

---

<div class="post-metadata">

### Author: ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)
#### Post date: [June 15, 2022, 3:19am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/2 "2022-06-15T03:19:40Z")

</div>

Follow this with Dynamo CLOSED.  
[https://primer.dynamobim.org/10\_Custom-Nodes/10-6\_Python-Templates.html](https://primer.dynamobim.org/10_Custom-Nodes/10-6_Python-Templates.html)

---

<div class="post-metadata">

### Author: ![mircoBianchini](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mircoBianchini](https://forum.dynamobim.com/u/mircoBianchini)
#### Post date: [June 15, 2022, 4:59am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/3 "2022-06-15T04:59:11Z")

</div>

Thanks @SeanP  
I was aware of this solution, but I have not considered it because I should provide the file in a shared folder and ask to do the steps, even if are simple, to a very large group, and having the file in a shared folder is not ideal.

---

<div class="post-metadata">

### Author: ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)
#### Post date: [June 15, 2022, 5:14am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/4 "2022-06-15T05:14:37Z")

</div>

What we have done is pushed (by IT) a modified version of the XML file that sets the custom path to a network location. This way you only have to update one .py file and everyone gets it.

The problem you will run into with trying to change / update the information at runtime is that any changes made while Dynamo is running don’t stick and most often are overwritten when Dynamo closes.

---

<div class="post-metadata">

### Author: ![mircoBianchini](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mircoBianchini](https://forum.dynamobim.com/u/mircoBianchini)
#### Post date: [June 15, 2022, 5:28am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/5 "2022-06-15T05:28:44Z")

</div>

Yep, @SeanP is the alternative I was thinking and thanks for the information, very useful!!

---

<div class="post-metadata">

### Author: ![mircoBianchini](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mircoBianchini](https://forum.dynamobim.com/u/mircoBianchini)
#### Post date: [June 16, 2022, 6:23am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/6 "2022-06-16T06:23:53Z")

</div>

The hacky solution is setting the Script value using reflection.

```auto
PropertyInfo property = pythonNode.GetType().GetProperty("Script");
property.SetValue(pythonNode, Convert.ChangeType(_boilerPlate, property.PropertyType));

```

I have a .py file with the boilerplate that is read and passed to the property.  
I tested saving the definition and re-open it and no problems with overwriting.  
In this way, I’ll leave to the user the decision of using the boilerplate when needed.

Thanks again, @SeanP

---

<div class="post-metadata">

### Author: ![c.poupin](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/c.poupin/32/89152_2.png) [@c.poupin](https://forum.dynamobim.com/u/c.poupin)
#### Post date: [June 16, 2022, 8:22am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/7 "2022-06-16T08:22:05Z")

</div>

> [@mircoBianchini](#):
>
> using reflection.

I think you can use the setter directly  
 ![set_boiterplate_python](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/6/7/67a7de39eec40c974d4ac0b41efd0aa9685fd795.gif)

```auto
import clr

clr.AddReference('DynamoCore')
clr.AddReference('DynamoRevitDS')
import Dynamo 
from Dynamo.Graph.Workspaces import *
from Dynamo.Graph.Nodes import *

#access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
engine = dynamoRevit.RevitDynamoModel.EngineController
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

clr.AddReference('PythonNodeModels')
from PythonNodeModels import *

boilerPlate = IN[0]
#find the specific node
for node in currentWorkspace.Nodes:
	if "Test" in node.Name and node.NodeType == "PythonScriptNode":
		node.IsFrozen = True
		node.Script = boilerPlate

```

---

<div class="post-metadata">

### Author: ![mircoBianchini](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@mircoBianchini](https://forum.dynamobim.com/u/mircoBianchini)
#### Post date: [June 16, 2022, 8:45am UTC](https://forum.dynamobim.com/t/access-pythonnode/77658/8 "2022-06-16T08:45:21Z")

</div>

Yeah, true only difference is that I am calling an event via a custom toolbar menu, so to access the node, or I use reflection or I need to reference the .dll as I mentioned previously.  
Writing in C# and using reflection I did exactly what you did using IronPython 🙂  
Thanks for your message.
