Hide linked scope boxes

Hide linked scope boxes

ottosson_mathias
Advocate Advocate
2,432 Views
4 Replies
Message 1 of 5

Hide linked scope boxes

ottosson_mathias
Advocate
Advocate

I'm trying to hide scope boxes from a linked file from my current view, but it doesn't seem to work. I know you can hide scope boxes from the Revit UI like this:

 

image.png

 

But when I try to do the same with the API nothing happens...

 

var docs = commandData.Application.Application.Documents;
var currentDocument = commandData.Application.ActiveUIDocument.Document;
var currentView = commandData.Application.ActiveUIDocument.ActiveView;

foreach (Document doc in docs)
{
    var linkedScopeBoxes = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_VolumeOfInterest).ToElementIds();

    if (linkedScopeBoxes.Count > 0)
    {
        var scopeBoxCategory = doc.Settings.Categories.get_Item(BuiltInCategory.OST_VolumeOfInterest);

        using (var transaction = new Transaction(currentDocument, "Hide scope boxes"))
        {
            transaction.Start();
            currentView.HideCategoryTemporary(scopeBoxCategory.Id);
            transaction.Commit();
        }
    }
}

 

 

The scope boxes does not get hidden. I don't understand where I go wrong...

Can someone point me in the right direction?

 

Thanks!

 

 

0 Likes
Accepted solutions (1)
2,433 Views
4 Replies
Replies (4)
Message 2 of 5

Sean_Page
Collaborator
Collaborator

The problem is that your element collector is only searching the Scope Boxes in the main model (doc) and not the Link (linkDoc). You need to get the linked document then the SB in it then get the reference to it in the main document then hide in the view.

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 3 of 5

ottosson_mathias
Advocate
Advocate

I do find the scope boxes with my FilteredElementCollector. When I'm testing the add-in I use a model with one linked model, and when I iterate commandData.Application.Application.Documents I first get nothing from the current document since it does not have any scope boxes, but in the second pass I do get the scope boxes that I can see in my view.

 

scopeBoxesFound.png

 

So the error is not that I can't find them, but rather that It doesn't get hidden in he transaction.

 

I shouldn't really have to do the filtered element collection and simply just hide the scopeBoxCategory.

0 Likes
Message 4 of 5

ottosson_mathias
Advocate
Advocate
Accepted solution

I got it working like this!

scopeBoxCategory.set_Visible(currentView, false);

 

0 Likes
Message 5 of 5

TripleM-Dev.net
Advisor
Advisor

Hi,

 

Try to use the Temporary Hide/Isolate tools in the UI, it doesn't work for links only for elements in the current model.

So it wouldn't work for the API either. (Always try the workflow in the UI first.)

 

Iterating all open documents could include non-linked documents, retrieve the links in the current drawing.

And obtain the document from those. Now any open document could cause the count > 0

 

You will always Hide the Category of the HOST document and not the LINKED document's setting in the Host document (this isn't possible in the API!).

 

- Michel

0 Likes