- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello Forum,
How to get Element ID in schedules with c# and revit API? similar to this video with Dynamo - https://youtu.be/U-tVoCYilxo - but with c# and revit api.
here is my try:
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Nice3point.Revit.Toolkit.External;
using Ecoworx.Core.Elements;
namespace Ecoworx
{
[Transaction(TransactionMode.Manual)]
public class CreateScheduleCommandHandler : ExternalEventHandler
{
public override void Execute(UIApplication uiapp)
{
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
CreateSchedule(uiapp);
}
public static void CreateSchedule(UIApplication uiapp)
{
UIDocument uidoc = uiapp.ActiveUIDocument;
Application app = uiapp.Application;
Document doc = uidoc.Document;
using (Transaction t = new Transaction(doc, "Create single-category"))
{
t.Start();
// Create schedule
ViewSchedule vs = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Windows));
ElementId someId = new ElementId(BuiltInCategory.OST_Windows);
BuiltInParameter bip = (BuiltInParameter)(someId.IntegerValue);
doc.Regenerate();
// Add fields to the schedule
AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.CASEWORK_WIDTH));
AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.CASEWORK_HEIGHT));
AddRegularFieldToSchedule(vs, new ElementId(bip));
t.Commit();
}
}
public static void AddRegularFieldToSchedule(ViewSchedule schedule, ElementId paramId)
{
ScheduleDefinition definition = schedule.Definition;
// Find a matching SchedulableField
SchedulableField schedulableField =
definition.GetSchedulableFields().FirstOrDefault(sf => sf.ParameterId == paramId);
if (schedulableField != null)
{
// Add the found field
definition.AddField(schedulableField);
}
}
}
}
Solved! Go to Solution.
