Hi, this may seem a bit silly but I am trying to find a way to select all of the walls in a view that are pinned. I found Rhythm’s Element.SetPinnedStatus node (python below) but I am totally new to Python. I feel like I am frustratingly close but would appreciate some help. The goal is to select all of the pinned walls and then override them in a view to graphically highlight to other users that the elements have been pinned. Thank you!
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
# Import DocumentManager and TransactionManager
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
#The inputs to this node will be stored as a list in the IN variable.
dataEnteringNode = IN
#unwrap all elements to use with API
items = UnwrapElement(IN)
#SEt pinned status over list
typelist = list()
for i in items:
i.Pinned = IN
# "End" the transaction
#Assign your output to the OUT variable
OUT = IN
Hi @Jordan_Billingsley - I already have a very simple Python script that accomplishes supplying a boolean output for whether or not elements are pinned are not, which I will provide below. You can use this inputting your wall elements, then using Filter.ByBoolMask with its output.
To encourage you to understand how the script works & to further learn using Python with the Revit API I will provide an explanation on how it works. if you look at the API Docs that @Nick_Boyts referenced above you will see that “Pinned” property is a Boolean. You are on the right track by seeking a resolution to retrieving pinned elements by looking at the Element.SetPinnedStatus node’s Python code.
for i in items:
i.Pinned = IN
These lines in that code are essentially saying, for each element in the input list of element, set “true” for “Pinned”. Understanding this will help to understand the code I am providing below, that determines if elements are pinned or not:
from Autodesk.Revit.DB import *
elems = UnwrapElement(IN)
elementlist = list()
for elem in elems:
OUT = elementlist
Thank you Amy for the details! I have been steadily building my dynamo knowledge and starting to gather resources for python learning. I definitely believe in doing/struggling/learning but would love to get your prospective - where did you start in your python journey?
@Jordan_Billingsley To be honest, coding was a side hobby of sorts when I was in college and I did a lot of the codeacademy.com courses (back when they were all free) while procrastinating my actual schoolwork.
There are a lot of free resources for learning Python out there www.learnpython.org is a good place to start - keep in mind, with Python and Revit/Dynamo you also need to familiarize yourself with the Revit API: http://www.revitapidocs.com
Reading forum posts that include Python codes and inspecting those is also a great help in learning.
To further what @awilliams said - reading the code on the site helps, but even better is to experiment with it. Paste it into a python node and take it apart line by line until you understand what each snippet of code does. Do the same for your favorite packages which use Python extensively. I found the Archi-Lab nodes were really useful for this.
Jumping in the train a bit late here, but would like to give an additional perspective.
For some people (myself included), interactive tutorials won’t do the trick alone when learning something from scratch. I feel the need to have someone teaching me, because it helps to set the pace and keep myself motivated. If that is the case for you too, I recommend either looking for a tutor that can teach you in person, or take an introductory online course on Python. If you decide for the latter, I recommend checking out the courses at Classpert (they don’t create the courses, but rather gather them from several providers and display them on a single search engine for you to find which suits you the best)