Sort/Grouping field in schedule

Sort/Grouping field in schedule

nia98bim
Enthusiast Enthusiast
488 Views
3 Replies
Message 1 of 4

Sort/Grouping field in schedule

nia98bim
Enthusiast
Enthusiast

hey everyone , I create a wall schedule ,but I want to sort by type in API .

i read the topics regarding that but still couldnt find way for that.

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

namespace Schedule
{
    [Transaction(TransactionMode.Manual)]
    public class ExportSchedule : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;

            try
            {
                using (Transaction trans = new Transaction(doc, "Create schedule"))
                {
                    trans.Start();

                    // Create a new schedule
                    ViewSchedule wallSchedule = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Walls));
                    wallSchedule.Name = "Wall Schedule";

                    // Add 'Type' field
                    SchedulableField typeField = wallSchedule.Definition.GetSchedulableFields()
                        .FirstOrDefault(sf => sf.GetName(doc).Equals("Type"));
                    if (typeField != null)
                    {
                        wallSchedule.Definition.AddField(typeField);
                    }
                    else
                    {
                        throw new Exception("Type field not found in schedule definition.");
                    }

                    // Add 'Area' field
                    SchedulableField areaField = wallSchedule.Definition.GetSchedulableFields()
                        .FirstOrDefault(sf => sf.GetName(doc).Equals("Area"));
                    if (areaField != null)
                    {
                        wallSchedule.Definition.AddField(areaField);
                    }
                    else
                    {
                        throw new Exception("Area field not found in schedule definition.");
                    }

                    // Sort by 'Type' field
                  

                    ScheduleSortGroupField sortField = new ScheduleSortGroupField(typeField.ParameterId, ScheduleSortOrder.Ascending);

                    wallSchedule.Definition.ClearSortGroupFields();
                    wallSchedule.Definition.AddSortGroupField(sortField);

                    trans.Commit();
                }

                TaskDialog.Show("Success", "Wall Schedule created successfully.");
                return Result.Succeeded;
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return Result.Failed;
            }
        }
    }
}

but in this part of code there is problem that i have no idea to how to solve it !

 

                    // Sort by 'Type' field
                  

                    ScheduleSortGroupField sortField = new ScheduleSortGroupField(typeField.ParameterId, ScheduleSortOrder.Ascending);

                    wallSchedule.Definition.ClearSortGroupFields();
                    wallSchedule.Definition.AddSortGroupField(sortField);

(type Field is not able to convert parameter id )

 

here is the link below that I used for sort/group.

sort/grouping apidoc 

 

thank you in advance.

 

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

jeremy_tammik
Alumni
Alumni

Does this fundamental article help?

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

nia98bim
Enthusiast
Enthusiast

thank you for your reply, I saw that article , but actually is not help me .

my problem is what item should place in schedule field id  to sort and itemize walls by type .

 

https://www.revitapidocs.com/2024/e437cc01-b976-fe8a-225a-1a0024171fae.htm

 

0 Likes
Message 4 of 4

nia98bim
Enthusiast
Enthusiast
Accepted solution
0 Likes