Creating floors with python

Very good days.
I am continuing my learning of programming with python and now I am trying to create basic floors with python and now I am presented with the following error…
I don’t understand much about the revit api. It would be great if you could teach me how to understand it to apply it in my learning.

How can I correct it… please remember that a simple code will help me understand the solution… thank you very much

Hello @AM3D.BIM.STUDIO

You are not importing the Revit.DB classes, thats why the method you want to use is not recognized.

I’d recommend to just import everything you can in the beginning, you will learn later when you have to use which imports, so just use this code for now:

1 Like

To add to that, you are using a method, applied to a class. You must call out the class first (and within a transaction if you wish to change the document).

The correct syntax there is x.NewFloor(), where x is a document.

Thanks for the comments… in order not to feel confused, it is important for me to be clear about what happens in the code… excuse me if I am very basic but I would like to understand well to properly read a code when making my own.
In the image I describe my query… thank you

Look at the annotated version of the boilerplate code in the link which was previously posted. That explains what the CLR and the main imports are for, which covers #1 and 2 above.

For questio. 3, Document in this case is a class in the Revit.Creation namespace. The * is indicating to bring in all the classes in Creation, which is a lot, but Revit.DB is a LOT more. Reducing the number of imports is a best practice when trying to build effective code as it reduces the amount of items in the memory.

1 Like

According to what is mentioned in the link and the descriptions of the lines of code, the line of code “clr.AddReference(“RevitAPI”), refers to the dll files of the REVIT API.”, my question would be where are these “DLL” files? " so I can know their names and be able to place or reference them in my Python code

I would skip the boilerplate for now - it’s a distraction when learning the basics. Try mine here which comes with most of what you need to write in Revit API for Dynamo/Python.

Come back to it later once you’ve got the hang of writing some Revit API. The main thing to understand about the boilerplate is it is rounding up code from other places which provides Python with the tools it needs to support your code. Whilst you can import specific pieces of the API selectively for more optimized code, most people just import all * from the required places as the speed difference is negligible in most common cases.

My boilerplate also includes a transaction template, functions to force objects into lists or unwrapped lists and input/output zones. I begin all my Python nodes with it but putting this exact file on my computer at:

C:\Users%USERNAME%\AppData\Roaming\Dynamo\Dynamo Revit\X.XX\PythonTemplate.py

2 Likes

In the Revit application folder, same spot as Revit.exe. The names aren’t direct extractions from those though. They come from the namespaces of the Revit API here: Namespaces

As Gavin mentions though, worry less about the python environment setup (what this part of the boilerplate code is doing) and more about setting up a good boilerplate and writing what comes next to achieve the results you want.

1 Like