How to take ownership of elements in a script

Hello, is there a way to take ownership of an list of elements before running a script, actually inside the script?

the problem is sometimes scripts take a long time to run. maybe 1hr+ but then at the very end, when it tries to populated some data into the revit elements, Revit will say, so and so, owns the element, or the elements are not currently editable, or whatever other error messages. Because someone else probably has ownership of some of the elements you are trying to modify with your script and stops the script from finishing, dead in its tracks.

However, if you go in to revit, select all of those elements that you want to run the script on and set them to “Make elements editable” or “make workset editable” beforehand, you wont get those error messages above, which can stop the script in its tracks. My question is are these features available in dynamo somewhere? is there a node for them? I would like the script to make elements editable before trying to write to them. Please advise thanks!

image

Most likely not possible without diving into the Revit API (See: WorksharingUtils)

1 Like

Is there a way to do this in python? I am not very advanced at writing my own python that calls on the Revit API unfortunately. Do you know of any place I can learn it?

Something like this? :sunglasses:

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('System.Core')
from System.Collections.Generic import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

def ToList(x):
    if isinstance(x,list):
        return UnwrapElement(x)
    else:
        return [UnwrapElement(x)]

elem = ToList(IN[0])

iDs = [el.Id for el in elem]
Ids = List[ElementId](iDs)

try: checkedout_el = WorksharingUtils.CheckoutElements(doc,Ids)
except Exception,er: checkedout_el = str(er)

OUT = checkedout_el
2 Likes

@Ewan_Opie
Hello Ewan, is it possible to edit this script to make it make “Worksets Editable” for good measure?
Thanks!

Yep @mix here you go. :slight_smile:

import clr

clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

clr.AddReference('System.Core')
from System.Collections.Generic import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

def ToList(x):
    if isinstance(x,list):
        return UnwrapElement(x)
    else:
        return [UnwrapElement(x)]

def GetWorkset(item):
	if hasattr(item, "WorksetId"): return item.Document.GetWorksetTable().GetWorkset(item.WorksetId)
	else: return None

elem = ToList(IN[0])

wks = [GetWorkset(e) for e in elem]

iDs = [w.Id for w in wks]
Ids = List[WorksetId](iDs)

TransactionManager.Instance.ForceCloseTransaction()

try: checkedout_wks = WorksharingUtils.CheckoutWorksets(doc,Ids)
except Exception,er: checkedout_wks = str(er)

OUT = checkedout_wks
1 Like

Hello @Ewan_Opie

Can you please tell me the intended input of this script? I cant seem to find anything it likes. I would like to just make one workset editable so I can move a list of elements there without having to worry about ownership issues. Please advise.

It looks like it expects either a single Element or list of Elements. Your bottom input looks to be a list of lists which is why that isn’t working either.

1 Like

why Not just manually take ownership of the full workset before running the graph? This would inform you if there was an issue coming and expose who the coworkers which you will be interacting with are so you can communicate directly with the people you’ll be overlapping elements with and likely give them the heads up sooner. Remember once you start those coworkers are tied out for 1hr+.

1 Like

Hi Jacob! Its because I intend to automate this script. I intend to have it run after hours when no one is in the office. But I need to take ownership because some people dont close Revit/relinquish. Its inevitable that someone will own something I need eventually.

Hi @Ewan_Opie
Does this script force ownership?, I seem to be getting this error message:
image

It isn’t possible to force relinquish using the Revit API, so this will have to be done manually. Elements can be filtered before attempting to check them out by using WorksharingUtils.GetCheckoutStatus. If this returns CheckoutStatus.OwnedByOtherUser you can assume you are not able to edit it, although, as noted in the API documentation:

Return values from inquiries about the worksharing status of elements or worksets rely on local caching of information from the central model so it is possible that the information is out of date. Because of this, the return value is suitable for reporting to an interactive user (e.g. via a mechanism similar to Worksharing display mode), but cannot be considered a reliable indication of whether the element can be immediately edited by the application. To make an immediate attempt to edit elements, use [!:CheckoutElements()] and check the return status, then confirm if the elements are up to date.

2 Likes

Hi @cgartland
do you know if this syntax is supposed to work in a code block? I cant seem to get it to work…Do you have any help pages for how to read the API page that you sent me to? I dont understand the layout of it or how I am supposed to use the commands on there.

Otherwise do you think this node from GeniusLoci does the same thing? Just filter out Owners that are not me?

Hi,

It’s not totally the same API call.
On the link above : WorksharingUtils.GetCheckoutStatus :
The API explains : “Gets the ownership status and outputs the owner of an element.”

The custom node uses the WorksharingTooltipInfo.Owner.
The API explains : “The current owner of the element or empty string if no one owns the element.”

I admit that I don’t understand the difference.

@Ewan_Opie

what happens in your above scripts if the element(s) that are pushed into them are not able to be “Made Editable” does it exclude those ones? It does not seem to give any sort of indication that it did not work for “some” of the input elements…