# Class, how can i use them - practicaly?

**URL:** <https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878>\
**Category:** Developers\
**Created:** [March 22, 2019, 2:19pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878 "2019-03-22T14:19:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [March 22, 2019, 2:19pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878/1 "2019-03-22T14:19:46Z")

</div>

Hello,

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

I have these small examples:

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.  
name = IN[0]  
age = IN[1]

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

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

p1 = Person(name, age)

OUT = p1.myfunc()

* * *

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

KR

Andreas  
[class.dyn](https://forum.dynamobim.com/uploads/short-url/k0MSrWO1Skv0jHIVRzdr6R7DhNq.dyn) (13.7 KB)

 ![2019-03-22_15h10_15](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/3/431987bd16f78b85beb19f63ab90cad8bf2dd742.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/9/6/96fc5f26ead80d38c79bfec8860a1357c86eb7a5.png)

---

<div class="post-metadata">

**Author:** ![Tomasz](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/tomasz/32/66785_2.png) [@Tomasz](https://forum.dynamobim.com/u/Tomasz)\
**Post date:** [March 22, 2019, 4:25pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878/2 "2019-03-22T16:25:32Z")

</div>

I really like Coreys tutorials. Here’s one of them on Python classes. [https://www.youtube.com/watch?v=ZDa-Z5JzLYM](https://www.youtube.com/watch?v=ZDa-Z5JzLYM)  
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.

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [March 22, 2019, 4:55pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878/3 "2019-03-22T16:55:22Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/9/4995b75d4f81813f1a41002aaa8a6393e93bfab6.png)  
[Class Example.dyn](https://forum.dynamobim.com/uploads/short-url/4b13eg1FudhrGz4vuQiTW6Q2NmJ.dyn) (6.5 KB)

```
class Person:
	def __init__ (self, name, age):
		self.name = name
		self.age = age
		
	def is_older(self, age):
		"""Determines whether person is older than a given age.
		
		Args:
			age (int): Age to compare against, in years.
		Returns:
			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.
	test.append(p.is_older(40))
	
OUT = test
```

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [April 26, 2019, 2:08pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878/5 "2019-04-26T14:08:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cgartland](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/cgartland/32/45378_2.png) [@cgartland](https://forum.dynamobim.com/u/cgartland)\
**Post date:** [April 26, 2019, 2:26pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878/6 "2019-04-26T14:26:44Z")

</div>

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):

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/1/2/12f08ce1abf70f942c98cbd55c43002433f2108a.png)  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/d/bd888ddce16f74a4e218dada8d9f742c56f59467.png)

---

<div class="post-metadata">

**Author:** ![Ricardo\_Freitas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/ricardo_freitas/32/9559_2.png) [@Ricardo\_Freitas](https://forum.dynamobim.com/u/Ricardo_Freitas)\
**Post date:** [May 9, 2019, 1:19pm UTC](https://forum.dynamobim.com/t/class-how-can-i-use-them-practicaly/33878/7 "2019-05-09T13:19:19Z")

</div>

Thanks you. I noticed that after my attempts. LOL
