How to highlight elements when selecting them

How to highlight elements when selecting them

desdinova
Advocate Advocate
1,277 Views
8 Replies
Message 1 of 9

How to highlight elements when selecting them

desdinova
Advocate
Advocate
List<ElementId> elemIdList = new List<ElementId>();
            try
            {
              
                while (true)
                {
                    elemIdList.Add((uidoc.Selection.PickObject(ObjectType.Element, "Pick a room").ElementId));
                    uidoc.Selection.SetElementIds(elemIdList);
                    uidoc.RefreshActiveView();
                   
                }
                
            }
            catch { }

hi friends

i want to highlight elements when i am selecting them like ctrl and pick objects

How can i do that in while loop in api?

Thanks in advance..... 

0 Likes
Accepted solutions (1)
1,278 Views
8 Replies
Replies (8)
Message 2 of 9

Aaron.Lu
Autodesk
Autodesk

Dear, what about shi:

    try
    {
        while (true)
        {
            elemIdList.Add((uidoc.Selection.PickObject(ObjectType.Element, "Pick a room").ElementId));
        }
    }
    catch 
    {
        uidoc.Selection.SetElementIds(elemIdList);
        uidoc.RefreshActiveView();
    }


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 9

desdinova
Advocate
Advocate
Thank you Aaron.Lu
It doesn't work for me.
0 Likes
Message 4 of 9

Aaron.Lu
Autodesk
Autodesk
What is your revit version.
it works for me on Revit 2015.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 5 of 9

desdinova
Advocate
Advocate
I use Revit 2015
0 Likes
Message 6 of 9

Aaron.Lu
Autodesk
Autodesk

Not sure what is the problem...

 

Attachment is video to demo how it works,

Full code I'm using:

 

    [TransactionAttribute(TransactionMode.Manual)]
    public class Pickwhile : IExternalCommand
    {
        public Document doc;
        public Autodesk.Revit.ApplicationServices.Application RevitApp;
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            RevitApp = commandData.Application.Application;
            var uidoc = commandData.Application.ActiveUIDocument;
            if (uidoc == null)
            {
                message = "Please open a document";
                return Result.Failed;
            }

            doc = commandData.Application.ActiveUIDocument.Document;
            List<ElementId> elemIdList = new List<ElementId>();
            try
            {
                while (true)
                {
                    elemIdList.Add((uidoc.Selection.PickObject(ObjectType.Element, "Pick a room").ElementId));
                }
            }
            catch
            {
                uidoc.Selection.SetElementIds(elemIdList);
                uidoc.RefreshActiveView();

                var td = new TaskDialog("Info");
                td.MainInstruction = commandData.Application.ActiveUIDocument.Selection.GetElementIds().Aggregate("", (ss, el) => ss + "," + el).TrimStart(',');
                td.TitleAutoPrefix = false;
                td.Show();
            }

            return Result.Succeeded;
        }
    }


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 7 of 9

desdinova
Advocate
Advocate

Hi and thank you again...

I want to make selection like this..

Please see attachment.

Regards...

0 Likes
Message 8 of 9

Aaron.Lu
Autodesk
Autodesk
Accepted solution
I think my demo code could do what you want.
if not, would you let me know what is the problem? e.g. errors or behaviors you not expected.

and another choice is to use PickObjects() method. Did you try that?


Aaron Lu
Developer Technical Services
Autodesk Developer Network
Message 9 of 9

desdinova
Advocate
Advocate
Thank you again
PickObjects() method does what i want...
0 Likes