selection set

selection set

Ning_Zhou
Advocate Advocate
3,451 Views
3 Replies
Message 1 of 4

selection set

Ning_Zhou
Advocate
Advocate

is here a way to persistently highlight elements, or at least create loadable selection set? i.e. Manage > Selection > Load Selection

 

for instance, API's fail or cancel will highlight related elements, but it's not persistent.

public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
   foreach (Element e in new FilteredElementCollector(commandData.Application.ActiveUIDocument.Document).OfClass(typeof(Wall)))
      elements.Insert(e);
   message = "whatever";
   //return Result.Succeeded;
   //return Result.Failed;
   return Result.Cancelled;
}

is it doable w/o using extra dialogbox?

 

 

or is it possible to create loadable selection set using API?

 

what i want to achieve is creating Dynamo node based on API's dll using zero touch method, not good at Python yet so don't know if it's doable using Python, but if Python can work then C# API should work too, below are links for similar request.

 

http://www.revitforum.org/dynamo-bim/27507-creating-selection-set.html

http://www.revitforum.org/dynamo-bim/27550-create-selection-set.html

0 Likes
Accepted solutions (1)
3,452 Views
3 Replies
Replies (3)
Message 2 of 4

Mustafa.Salaheldin
Collaborator
Collaborator
Accepted solution

Tell me if it works like a charm

 

#region Namespaces

using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;

using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;

//using Autodesk.Revit.Collections;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;

using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;

#endregion

namespace RevitAddinCS2
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class ExtCmd : IExternalCommand
    {
        #region Cached Variables

        private static ExternalCommandData _cachedCmdData;

        public static UIApplication CachedUiApp
        {
            get
            {
                return _cachedCmdData.Application;
            }
        }

        public static RvtApplication CachedApp
        {
            get
            {
                return CachedUiApp.Application;
            }
        }

        public static RvtDocument CachedDoc
        {
            get
            {
                return CachedUiApp.ActiveUIDocument.Document;
            }
        }

        #endregion

        #region IExternalCommand Members

        public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
        {
            _cachedCmdData = cmdData;

            try
            {
                //SelectionFilterElement sf = new SelectionFilterElement();

                FilteredElementCollector collector = new FilteredElementCollector(cmdData.Application.ActiveUIDocument.Document).OfClass(typeof(Wall));
                List<Element> elements = collector.Cast<Element>().ToList();
                List<ElementId> Ids = new List<ElementId>();

                foreach (Element e in elements)
                {
                    elemSet.Insert(e);
                    Ids.Add(e.Id);
                }

                cmdData.Application.ActiveUIDocument.Selection.SetElementIds(Ids);
                return Result.Succeeded;

            }
            catch (Exception ex)
            {
                msg = ex.ToString();
                return Result.Failed;
            }
        }

        #endregion
    }
}

Please don't forget to mark the reply as an answer if it satisfies your need.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Digital Integration Manager, DuPod

Facebook | Twitter | LinkedIn

Message 3 of 4

Ning_Zhou
Advocate
Advocate
right, as simple as that, pretty basic stuff that UIDocument do have selection method, typical overthinking leads to brain damage, too much coffee perhaps, thanks Mustafa for your quick reply and solution!

before i mark your answer, would you mind confirming that it is not yet possible to create or manipulate loadable selection set using API, maybe i missed something again?
0 Likes
Message 4 of 4

Ning_Zhou
Advocate
Advocate
did quick search on Revit API help file, yes, loadable selection set is indeed available, SelectionFilterElement, i knew i missed something simple again.
0 Likes