Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Check if element is editable

8 REPLIES 8
Reply
Message 1 of 9
jason.kunkel
1987 Views, 8 Replies

Check if element is editable

I've written a very teeny piece of code that runs through all the doors in a model and enters "--" in any field that is empty.

 

If the model has worksets active, and someone else has "checked out" a door, it pops up the usual "cannot edit element until so-and-so relinquishes..."

 

Is there any way the API can check to see if the entire element is editable before proceeding?  I am already checking if the parameter itself is read only, and thought that would do it, but no luck.

8 REPLIES 8
Message 2 of 9

I believe you can get the Element.WorksetId:

 

WorksetTable worksetTable = doc.GetWorksetTable();
WorksetId ElementWorksetId = ele.WorksetId;
Workset workset = worksetTable.GetWorkset(activeId);
if (workset.IsEditable)
{
}

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 3 of 9

Thanks for the reply.

 

Won't that give me the entire Workset?  I just want to find out of the element itself is editable, or do I misunderstand how the WorksetTable works in the API?

 

We don't have users "check out" entire worksets typically, just elements as they need them, so in our practice, the Worksets should always be editable (or at leat 95% of the time)

Message 4 of 9

If I'm getting your question right, an Element may not be editable if the respective Workset is not Editable.


This is simply opening the Workset to check if it is editable (not checking out).

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 5 of 9

Yes.  I agree.

 

So, if a Workset is NOT editable, then an element in that Workset is also NOT editable.

 

However, the inverse of that is NOT true.  If a Workset IS editable, an element is NOT NECESSARILY editable.

 

A user could have checked out the individual element and not the entire workset.  I need to know if the API can tell me if the individual element is editable.  It looks like "isEditable" only works for Worksets or Families, not individual Elements.  That's basically what I need to be able to check.

Message 6 of 9

The best approach to see if a specific element can be edited by an API command or macro is to try to check it out.  (WorksharingUtils.CheckoutElements())

If it checks out successfully it will be included in the returned collection.  

Note that there is WorksharingUtils.GetCheckoutStatus() – this reports a cached value that may not always be up to date.


Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
Message 7 of 9

This looks like just what I need, thanks.  Unfortunately, I am coding for 2013, and it looks like this was introduced in 2014.  I am going to assume there is no good solution for 2013 and will try to figure out a workaround.

Message 8 of 9
michael.kero
in reply to: jason.kunkel

Instead of doing a check before operating on an element, you can utilize the IFailuresPreprocessor Interface to swallow the warnings and errors.  This will process the errors and warnings as they bubble up.  

 

You then pass an instance of the class which implements the IFailuresPreprocessor to create a FailureHandlingOptions. You then attach the handling options to the open transaction with trans.SetFailureHandlingOptions. The Revit .chm file documents this all pretty well.  This interface is available in 2013 as well.

 

Hope this helps.

Message 9 of 9

Did something change in Revit 2018 in regard to CheckoutElements() call? It looks like it's not working for me as I would have expected. I am collecting all Viewports and checking them out. Then I am trying to edit them, and I am still getting errors that other users own some of the viewports. From the API documentation it seems like checked out elements should be mine to edit, and even if they are part of group etc. they should checkout all that is needed to actually edit that element. 

 

    ids = FilteredElementCollector(doc).OfClass(Viewport).WhereElementIsNotElementType().ToElementIds()
    #ids = [UnwrapElement(x).Id for x in IN[0]]
    netIds = List[ElementId](ids)
    checkedOut = WorksharingUtils.CheckoutElements(doc, netIds)
    output = [doc.GetElement(x) for x in checkedOut]
    # I would later edit them here

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community