Element.Pinned usage?


#1

Trying to figure out exactly how to set an element as pinned but not having any success. How does one use the set property??

<span class=“keyword”>public</span> bool <span class=“identifier”>Pinned</span> { <span class=“keyword”>get</span>; <span class=“keyword”>set</span>; }

 

Thanks in advance!


#2

Hey Danny,

You can read it like any other property. But the only way to modify it, is to perform it inside a transaction:

2015-09-15_10-43-10


#3

Thanks Dimitar! You’re the man with the answers. I wound up tweaking a bit to work with a list and Boolean for pin vs. unpinned.

Pinned


#4

Sorry to necro this thread.

Based on the discussion above and at the post below

I am trying to use the python script to pin/unpin elements, but to no avail.
The idea is to make sure that all elements are unpinned before they are modified.


This is the dynamo graph output.

The error popping up is
“Warning: Element.SetPinnedStatus operation failed. Element cannot be pinned or unpinned.”

image

On revitAPI docs it shows its an " [Autodesk.Revit.Exceptions InvalidOperationException]
which further defines this as “The exception that is thrown when a method call is invalid for the object’s current state.”
I don’t understand what revit is trying to tell me.

Any help is appreciated.
– Aditya


#5

Can you provide a sample rvt and your dyn so we can review? Could be a list issue or it could be you have an invalid element for pinning (say an element inside of a link).


#6

As @JacobSmall says, it’s useful to know what you are plugging in as it’s hard to say what the issue is.

However, you could help yourself by putting the try catch inside the for loop instead of outside. This way it is easier to debug where you are having the error as it might only be one element failing but the whole thing fails as it is currently written.

Another thing is you that should have your transaction open and close statements in-line. Currently, if the code within the Try scope fails, you skip closing the transaction and go straight to Except.

Also, Element.Pinned is a property so you can set it with a simple Element.Pinned = True/False.

Here is some working code which is a little more concise and should give you better insight to where you are getting errors.

import clr

clr.AddReference(&quot;RevitServices&quot;)
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference(&quot;RevitNodes&quot;)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference(&quot;RevitAPI&quot;)
from Autodesk.Revit.DB import *

# Ensure input is always a list...
def tolist(obj1):
    if hasattr(obj1,&quot;__iter__&quot;): return obj1
    else: return [obj1]

# IN Variables...
elems = tolist(UnwrapElement(IN[0]))
b = tolist(IN[1])[0]

# OUT Variables...
outList = []

# Main Body...
TransactionManager.Instance.EnsureInTransaction(doc)
for e in elems:
    try:
        e.Pinned = b
        outList.append(e)
except Exception, ex:
    outList.append(ex.message)
TransactionManager.Instance.TransactionTaskDone()

OUT = outList

Hope this helps.

Cheers,
Dan