Creating a Custom Python Class


#1

Hi, I’ve recently been learning Dynamo and when I get to working with Python Scripts I run into a lot of questions. I couldnt find similar questions in the community so here they go:

In a Python Script node, is it possible to define a custom Python Class, populate it and pass it around as an argument? I would be looking to do something like this:

 

import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

class Circ:
parent=’‘
tipe=’‘
name=’’

var=Circ()

var.name=‘Nombre’

var.tipe=IN

OUT=var

If this cannot be done, can I create my own classes in a separate python file and then import it in my Python scripts? How can I go about doing this?

 

Thank you for your help

 


#2

It seems that you can create custom classes in one python node, then pass them around the graph and read the properties of the instance in another python node. I was actually a bit surprised by that. I don’t think I’d recommend this method for making custom classes in Dynamo tho.

2015-12-14_22-47-36


#3

It works, Thanks!

I will be using the class to order data from a messy excel sheet and pass it around the nodes as a Data Struct. Do you know of a better way of creating custom classes in Dynamo?

 

Again, thanks for your reply!


#4

AL,

You can define those classes inside of Python and pass them around but I prefer to define classes outside of Dynamo in a module file because that gives me access to them from any custom node without having to define it again.

Thanks!