Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.
thank you in advance.
Solved! Go to Solution.