Class, how can i use them - practicaly?



Some stuff regarding classes, i do right now.
Does anybody have some practical use regarding architecture?

I have these small examples:

import clr
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
name = IN[0]
age = IN[1]

class Person:
def init(mysillyobject, name, age): = name
mysillyobject.age = age

def myfunc(abc):
return ("Hello my name is " +

p1 = Person(name, age)

OUT = p1.myfunc()

How can I use that for lists? And for what can I use that in my projects?


class.dyn (13.7 KB)


1 Like

I really like Coreys tutorials. Here’s one of them on Python classes.
The short story is - if you have no idea what Python class is and how you could use one - you probably do not need to use them as for now. Learning Python is still the way to go.

1 Like

A common application of classes is in object-oriented programming (OOP). Much of how you already interact with the Revit API uses similar concepts (methods and properties). See below:

Class Example.dyn (6.5 KB)

class Person:
	def __init__(self, name, age): = name
		self.age = age
	def is_older(self, age):
		"""Determines whether person is older than a given age.
			age (int): Age to compare against, in years.
			bool: True if Person is older than the given age.
		return self.age > age
names = IN[0]
ages = IN[1]
# Construct our Person objects
people = [Person(name, age) for name, age in zip(names, ages)]
test = []
for p in people:
	# Test whether each person is older than 40 years old.
OUT = test

why this not working?


make a new topic! than you get an answer very fast


You need to instantiate the class rather than simply passing the class itself. i.e. OUT should be MyClass() rather than MyClass. Both of the following are valid (although the first is a better approach):


Thanks you. I noticed that after my attempts. LOL