pointer
Best pit stop to learn how things are done at first is going through some of the ressources available like
-
Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
-
Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
and looking at the pyrevit tools, if there is a tool that looks pretty similar to something you are trying to achieve, ALT+Click on it and then look into the script.py file, trying to understand the code is a must to get going quickly
-
ApiDocs.co is probably the best place to understand the pieces of the big Revit API Lego. at the top right there is a <> sign that will provide you with code samples in most of the cases (not all…)
-
Dynamo forum, Dynamo primer, Dynamo python primer
-
and obviously here, but you need to try first, like on any forum, define the goals, try it, hit the wall 100x then ask for help in the most documented way and if possible provide pictures or text of your code and the errors you are recieving
explainations
not a C# pro at all here but I can help a bit:
Variable
IEnumerable<ElementType> dimTypes
is declaring a data type before creation of a variable. Basically saying you are creating a “dimTypes” container that can only contain ElementType kind of thing
in python, you don’t need to declare the data type of the variables you are assigning things to (thank god IMHO)
proper syntax in python for the same thing would be:
dim_types
now to the right side of the equal sign:
new FilteredElementCollector(doc)
.WhereElementIsElementType()
.Cast<ElementType>()
.Where(t=>t.FamilyName.Contains("Text"));
FilteredElementCollector
is basically a tool to collect stuff from the revit api, the ‘new’ in front of it is required in C#
new FilteredElementCollector(doc)
but not in python:
FilteredElementCollector(doc)
but that implies to you imported that FilteredElementCollector class before using it
either from the Revit API directly like so:
import clr
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import FilteredElementCollector, ElementType
or from pyrevit (my preference):
from pyrevit import DB, revit
doc = revit.doc # declaring which document you gonna work with, something that did not show in you C# example but that was most certainly done in the same manner
# then you can use it like so
dim_types = DB.FilteredElementCollector(doc). # .etc
WhereElementIsElementType()
is kind of a milestone here as you need to understand the difference between grabbing the type of something and the instances of this type.
- WhereElementIsElementType() while filter out the instances
- WhereElementIsNotElementType() will filter out the types
- Not using this filter will get you both types and instances
the Cast() is totally C# stuff (I could not explain)
Where(t=>t.FamilyName.Contains("Text"));
is also very C#ie
possible solution with pyRevit
from pyrevit import DB, revit
doc = revit.doc
text_notes = DB.FilteredElementCollector(doc).OfClass(DB.TextNote).WhereElementIsNotElementType().ToElements()
# then if you would like to display the text of the text notes for example:
for text_note in text_notes:
print(text_note.GetFormattedText())
see more advanced example around text notes here ApiDocs.co
I hope that will help you go a bit further a bit quicker
cheers