Posting OwnedByother failure

Posting OwnedByother failure

Anonymous
Not applicable
1,710 Views
8 Replies
Message 1 of 9

Posting OwnedByother failure

Anonymous
Not applicable

Hello,

 

I am trying to use the API to check out an element and, if the checkout fails, post the normal error message with the opportunity to resolve it:

 

Capture2.PNG

 

Attempting to check out is simple enough:

 

ICollection<ElementId> checkedOutIds = WorksharingUtils.CheckoutElements(doc, new ElementId[] { eid });
bool checkedOutSuccessfully = checkedOutIds.Contains(eid);

 

However, when it fails it does so silently, without showing the failure box. I attempted to show the box manually:

 

 

 

if (!checkedOutSuccessfully)
{
    using (Transaction tr = new Transaction(doc, "Posting failure message"))
    {
        tr.Start();
        FailureMessage fm = new FailureMessage(BuiltInFailures.EditingFailures.OwnedByOther);
        fm.SetFailingElement(eid);
        doc.PostFailure(fm);
        tr.Commit();
    }

    return null;
}

But this gives me a box without a username and no way to resolve the issue (ie Place Request). 

Capture.PNG

 

Is there some way I can accomplish what I am looking for?

1,711 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

Dear Drdanielfc,

 

I discussed this issue with the development team, and they say:

 

This is an interesting test case.

 

Are you aware of Scott Conover's Autodesk University class on the Worksharing API?

 

http://thebuildingcoder.typepad.com/blog/2013/12/au-day-2-worksharing-and-revit-2014-api-roundtables...

 

That would probably help.

As far as I remember,

1. If you want to have Revit just post the relevant message on a failure to edit, just try to perform the edit. Don’t checkout in advance. So if the edit is setting a parameter, open a transaction, edit the parameter, and on resolution you’ll get the posted error for the user to respond to.

 

2. If you want to handle failure to edit silently, you can respond to the failure message, or try to checkout first.

I am wondering about the posted failure missing the expected text. I’m not sure if this is a bug or a missing API that we should have for customizing FailureMessage objects.

 

If you can submit a reproducibkle case for this we could take a closer look:

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

I wish you a pleasant weekend.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 9

Anonymous
Not applicable

In my application, the user selects the element and then a custom dialog is opened where the user can edit the element. I want to check out the item before my dialog even opens so the user can receive permission to edit it before wasting their time working on it if someone else has the item checked out, because if another other person has it checked out then any edits they make in my dialog will have to be discarded so they can Reload Latest. I suppose if the checkout fails I could simply make a temporary edit to the element to force the Revit warning box to show up, but this seems inelegant and not a very universal solution.

 

I will make a reproducible case next week.

 

Have a good weekend!

Message 4 of 9

Anonymous
Not applicable

Can this dialog box be suppresed?

0 Likes
Message 5 of 9

Anonymous
Not applicable
I found it can!

public class EditingElementsWarningSwallower : IFailuresPreprocessor
{


public FailureProcessingResult PreprocessFailures(FailuresAccessor a)
{
// inside event handler, get all warnings
IList<FailureMessageAccessor> failures = a.GetFailureMessages();

foreach (FailureMessageAccessor f in failures)
{
// check failure definition ids
// against ones to dismiss:
FailureDefinitionId id = f.GetFailureDefinitionId();

if (BuiltInFailures.EditingFailures.CannotEditEditingElements == id)
{
if (failures.Count > 1)
{

a.DeleteWarning(f);


}

}

}


return FailureProcessingResult.Continue;
}


//Swap types
using (Transaction trans = new Transaction(_doc, "Ungroup"))
{
trans.Start();

failureHandlingOptions(trans);
element_old.ChangeTypeId(elemStyle_New.Id);

trans.Commit();
}
Message 6 of 9

jeremytammik
Autodesk
Autodesk

Congratulations!

 

Well done!

 

Thank you for letting us know.

 

The source code is more readable if you use the 'Insert Code' {i} button to insert it.

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 9

talalaevd
Collaborator
Collaborator

First I realized

 

public class MyWorksetElementPreprocessor : IFailuresPreprocessor
        {
            public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
            {
                IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>();
                failList = failuresAccessor.GetFailureMessages();
                foreach (FailureMessageAccessor failure in failList)
                {
                    FailureDefinitionId failID = failure.GetFailureDefinitionId();
                    if (failID == BuiltInFailures.EditingFailures.OwnedByOther)
                    {
                        failuresAccessor.ResolveFailure(failure);
                        return FailureProcessingResult.ProceedWithRollBack;
                    }
                }
                return FailureProcessingResult.Continue;
            }
        }

Then used

 

private static Transaction MakeTransaction(Document doc, string name, bool useFailureHandlingOpts)
        {
            Transaction t = new Transaction(doc, name);
            if (useFailureHandlingOpts)
            {
                FailureHandlingOptions opts = t.GetFailureHandlingOptions();
                opts.SetClearAfterRollback(true);
                opts.SetFailuresPreprocessor(new MyWorksetElementPreprocessor());
                t.SetFailureHandlingOptions(opts);
            }
            return t;
        }

In main code

 

public bool UpdateProjectEdit(Document _doc, TreeView _treeview, string _name)
        {
            bool result = false;
            TreeNode elms = _treeview.SelectedNode;
            Element elm_rename = (Element)elms.Tag;
            TransactionStatus t_status;
            using (Transaction t = MakeTransaction(_doc, "Rename element " + elm_rename.Name, true))
            {
                t.Start();
                elm_rename.Name = _name;
                t_status = t.Commit();
            }
            if (t_status != TransactionStatus.RolledBack)
            {
                result = true;
            }
            return result;
        }

 But there is one thing. I'm sending an edit request for an item. This window is displayed

2017-06-22_3-56-14.jpg
I do not know yet how to close this window automatically. Does anyone have any advice?

 



Дмитрий Талалаев
Эксперт BIM2B
Блог
Facebook | Twitter | LinkedIn

0 Likes
Message 8 of 9

BIM_S_S
Participant
Participant

i reached the same result does any one solved that.

0 Likes
Message 9 of 9

AndrewButenko
Advocate
Advocate

errr

0 Likes