I’m preparing to write my first Python script in Dynamo, had some previous experience with Python in Grasshopper but it’s been a couple years. In doing so, I’m just trying to run a simple command from the Revit API, IsPainted, but am getting an error that is telling me this command takes 3 arguments. When looking on the RevitAPI Docs page it says it only takes two.
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import Document
# The inputs to this node will be stored as a list in the IN variables.
elementID = IN[0]
face = IN[1]
# Place your code below this line
Result = Document.IsPainted(elementID,face)
# Assign your output to the OUT variable.
OUT = Result
To start out this Python project I have tried to get all the parameters for IsPainted within Dynamo and pass them into the Python node. I’m not sure I need to include the Revit file I’m working with here, as I had just opened up a new file drew a couple walls in 3D and painted random faces, then brought those walls into Dynamo via “Select Model Elements.”
I have added the following, but not exactly sure which I need and why. The examples from the primer page are using different combinations.
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
# Import Revit elements
from Revit.Elements import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
Also if I use the above then do I need still need to be adding the following
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import Document
Lastly I have read some things about the wrapping and unwrapping of “Revit data types” via the following GitHub page. Is this an instance when I need to be unwrapping the faces I’m trying to use?
The Python script below is what I currently have. Still have the same issue with IsPainted() takes exactly 3 arguments (2 given)
# Enable Python support and load DesignScript library
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import Document
# Import RevitNodes
clr.AddReference("RevitNodes")
import Revit
# Import Revit elements
from Revit.Elements import *
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import System
# The inputs to this node will be stored as a list in the IN variables.
elementID = IN[0]
face = IN[1]
# Place your code below this line
Result = Document.IsPainted(elementID,face)
# Assign your output to the OUT variable.
OUT = Result
Firstly you need to pay attention to the data type you are inputting to the python node. If you for instance use a Select Faces node, you’ll be getting a Autodesk.DesignScript.Geometry.Face object, whereas the API call states that the input must be a Autodesk.Revit.DB.Face. You can use an Object.Type node to check stuff like this:
To use the IsPainted method, as you also stated, you’ll need the ElementId and the Face as parameters:
So regarding the imports, you’ll only need to reference the API and the document to get this specific call to work. This looks like this:
import clr
#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument
Figuring out exactly what you need to import can be quite tough in the beginning, but you’ll get the hang of it if you keep practicing .
The entire scrip looks like this:
import clr
#Import the Revit API
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
#Import DocumentManager and TransactionManager
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
#Reference the active Document and application
doc = DocumentManager.Instance.CurrentDBDocument
#Start scripting here:
walls = UnwrapElement(IN[0]) #Unwrap the wall in order to expose the API object
opt = Options() #Geometry options object. Needed when extracting geometry from a Revit element.
output = [] #output list
for i in walls: #Iterate the walls
elemId = i.Id #Get the element id, which we need to use as a parameter in the IsPainted method
solids = i.get_Geometry(opt) #use the overloaded property get_Geometry to get the wall solids
temp = [] #Temp container
for j in solids: #Iterate the solids
faces = j.Faces #use the Faces property to get the faces
for f in faces: #Iterate the faces
temp.append(doc.IsPainted(elemId, f)) #append the result to the temp container
output.append(temp) #append the temp container to the out list
#Assign your output to the OUT variable.
OUT = output
@Kulkul & @MartinSpence thanks so much! I’m going to need to take some time to digest this, but thanks for helping me out. I’m sure I will have questions after I have taken a deeper dive.