From floor to solid to centroid


I’m trying to get the centroid point from floor elements using Python. Do not really understand what I am doing wrong.

Grateful for help!

Best regards,

Hi, @mikael.z

My first question would be, why do this in Python, when you can do this easily in Dynamo.

What the error tells you is:
You have a Floor object → floor
You query the Solids → floor.Solids
This will return a List with solids → Probably a list with only 1 solid.
So you would have to iterate through that list, before querying centroid

The example below shows a situation with a Floor containing 2 solids

Hello @Joelmick

Thanks for the reply!
I use Python because I find it easier to keep track of what I work with. If you use nodes, the graphs tend to be so large and looping in Python creates other possibilities.

Let’s say that I iterate over the list of solids and use the .Centroid method on each object and I get this result:

Do you know why I get this result and not the centroid point?

Best regards,

Okay, I can understand getting a messy graph, but it is 2 nodes in this case (See below for Dynamo Solution)

In your Python, you are not using the Method .Centroid() properly.

Quick overview on Object oriënted programming (OOP)
In OOP you have “Objects” (In this case your floor)
Objects have 4 things:
Constructor (This is to Create an Object)
Methods (Things you can do with Objects)
Properties (Data in the Object)
Events (Triggers functions when something happends, this you don’t need to think about right now)

In the case of this Python script, you first query a property from your Floor (floor.Solids) and later you try to use a Method like a Property (floor.Centroid). Methodes always and with () → floor.Centroid()

Inbetween the () come arguments needed to use the Method (In this case you dont need any additional arguments which is why it is “floor.Methods()”

Let me know if this makes sense to you or if you have any questions



Thank you so much for the help :slight_smile:
That explained a lot. Now everything works as it should.

Many thanks,
/ Mikael