Revit API. Work with the form in VS.

Revit API. Work with the form in VS.

andron_kozmos
Advocate Advocate
315 Views
2 Replies
Message 1 of 3

Revit API. Work with the form in VS.

andron_kozmos
Advocate
Advocate

Good afternoon!

created a class- SortLevels

public class SortLevels : IExternalCommand
    {
       
        public bool IsTemplate { get; private set; }

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
           
            UIDocument uiDoc = commandData.Application.ActiveUIDocument;

            Document doc = uiDoc.Document;

            FilteredElementCollector collector = new FilteredElementCollector(doc);
            ICollection<Element> levels = collector.OfCategory(BuiltInCategory.OST_Views).Where(x => !(x as Autodesk.Revit.DB.View).IsTemplate 
            && (x as Autodesk.Revit.DB.View).ViewType != ViewType.Elevation
            && (x as Autodesk.Revit.DB.View).ViewType != ViewType.ThreeD
            && (x as Autodesk.Revit.DB.View).ViewType != ViewType.Section).ToList();

 

as an example, displays the following kinds of levels.

andron_kozmos_0-1669627296715.png

Can you tell me, how to get the class into the form? How can this collector be inferred in the form in  checkedListBox1

andron_kozmos_1-1669627500480.png

private void checkedListBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {

            



        }

 

316 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor

This is non-api knowledge best available elsewhere.

 

To start with you should create your own cut down class version of View containing: Id, Name and IsChecked.

You then need to put that into a collection object and bind the control to it (this is easier to do in WPF than Forms).

 

You are using a Forms CheckedListBox which is notoriously awkward in not allowing a binding to the check status of the individual item. Instead you could more easily use a WPF ListBox with a DataTemplate that has a CheckBox with CheckBox.IsChecked bound to IsChecked and CheckBox.Content bound to Name.

 

I would make it completely abstract since we are basically creating a checked listbox which could be used for any object not just Views

 

That is: if you create an interface with members 'Name' and 'IsChecked' then your class that you create to represent the view could implement that interface. Your dialogue could then just deal with the interface not caring at all what the object is. Selecting Views, Levels, Categories, Doughnuts (all the same).

 

 

 

Message 3 of 3

andron_kozmos
Advocate
Advocate

Сan i see a sample code somewhere? I'm a beginner so it's hard for me to accept.