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.
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).
As @jacob.small 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("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
# Ensure input is always a list...
def tolist(obj1):
if hasattr(obj1,"__iter__"): 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