SetLinkOverrides is not working for me.

SetLinkOverrides is not working for me.

vitruviusbim
Participant Participant
224 Views
1 Reply
Message 1 of 2

SetLinkOverrides is not working for me.

vitruviusbim
Participant
Participant

I've been working on a tool to override Revit Links. I use a new method, SetLinkOverrides (or Remove), but after running it, nothing happened. What went wrong? How can I change the visibility of a linked document? I use Revit 2024. Maybe this method is not working?



using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using RevitExtension.Elements;
using System.Linq;


namespace BuiltExporter.ExternalCommands
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    internal class TestCommandExternalCommand : ExternalCommand
    {
        public override void Execute()
        {
            UIDocument uidoc = new UIDocument(App.ActiveUIDocument.Document);

            // Get the active view
            View activeView = uidoc.ActiveView;

            //Get links
            FilteredElementCollector elements = new FilteredElementCollector(activeView.Document);
            var links = elements.OfClass(typeof(RevitLinkType)).ToList();

            var doc = activeView.Document;

            using (var Transaction = new Transaction(doc, "Remove Link Overrides"))
            {
                Transaction.Start("Remove Link Overrides");


                foreach (var link in links)
                {

                    RevitLinkGraphicsSettings settings = new RevitLinkGraphicsSettings()
                    {
                        LinkVisibilityType = LinkVisibility.ByHostView,
                    };

                    activeView.RemoveLinkOverrides(link.Id);
                    // view3D.SetLinkOverrides(link.Id, settings);

                }


                Transaction.Commit();
            }


        }
    }
}

vitruviusbim_0-1743687626853.png

My goal is  

vitruviusbim_1-1743687688132.png

or 

vitruviusbim_2-1743687715393.png

 

 

0 Likes
225 Views
1 Reply
Reply (1)
Message 2 of 2

TripleM-Dev.net
Advisor
Advisor

Hi @vitruviusbim,

 

I haven't used this yet, but from what I''m see you're resetting the Display override to "By Host view" which it already was.

The Visibility of the link doesn't cover this or at least not like this.

 

Try it, set a Display setting for a link to a override and run it, it should revert then to By Host View.

I've searched the API, can't find directly a method or so to control this..Like turning Categories on / off

 

Alternative you could id in which templates they are turned off/on...:

You could id viewtemplates that don't have the RevitLinkInstance visible in view with the template and check if it's due to workset or not.

And control visibility of links by the workset their on....depending workflow.

 

- Michel