<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Element ID in schedules c# revit api in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/element-id-in-schedules-c-revit-api/m-p/11535494#M15716</link>
    <description>&lt;P&gt;Hello Forum,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to get&amp;nbsp;Element ID in schedules with c# and revit API? similar to this video with Dynamo&amp;nbsp; -&amp;nbsp;&lt;A href="https://youtu.be/U-tVoCYilxo" target="_blank"&gt;https://youtu.be/U-tVoCYilxo&lt;/A&gt;&amp;nbsp;- but with c# and revit api.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.ApplicationServices;&lt;BR /&gt;using Autodesk.Revit.Attributes;&lt;BR /&gt;using Autodesk.Revit.DB;&lt;BR /&gt;using Autodesk.Revit.UI;&lt;BR /&gt;using Autodesk.Revit.UI.Selection;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using Nice3point.Revit.Toolkit.External;&lt;BR /&gt;using Ecoworx.Core.Elements;&lt;/P&gt;&lt;P&gt;namespace Ecoworx&lt;BR /&gt;{&lt;BR /&gt;[Transaction(TransactionMode.Manual)]&lt;BR /&gt;public class CreateScheduleCommandHandler : ExternalEventHandler&lt;BR /&gt;{&lt;BR /&gt;public override void Execute(UIApplication uiapp)&lt;BR /&gt;{&lt;BR /&gt;UIDocument uidoc = uiapp.ActiveUIDocument;&lt;BR /&gt;Application app = uiapp.Application;&lt;BR /&gt;Document doc = uidoc.Document;&lt;/P&gt;&lt;P&gt;CreateSchedule(uiapp);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public static void CreateSchedule(UIApplication uiapp)&lt;BR /&gt;{&lt;BR /&gt;UIDocument uidoc = uiapp.ActiveUIDocument;&lt;BR /&gt;Application app = uiapp.Application;&lt;BR /&gt;Document doc = uidoc.Document;&lt;/P&gt;&lt;P&gt;using (Transaction t = new Transaction(doc, "Create single-category"))&lt;BR /&gt;{&lt;BR /&gt;t.Start();&lt;/P&gt;&lt;P&gt;// Create schedule&lt;BR /&gt;ViewSchedule vs = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Windows));&lt;/P&gt;&lt;P&gt;ElementId someId = new ElementId(BuiltInCategory.OST_Windows);&lt;BR /&gt;&lt;BR /&gt;BuiltInParameter bip = (BuiltInParameter)(someId.IntegerValue);&lt;/P&gt;&lt;P&gt;doc.Regenerate();&lt;/P&gt;&lt;P&gt;// Add fields to the schedule&lt;BR /&gt;AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.CASEWORK_WIDTH));&lt;BR /&gt;AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.CASEWORK_HEIGHT));&lt;BR /&gt;AddRegularFieldToSchedule(vs, new ElementId(bip));&lt;/P&gt;&lt;P&gt;t.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public static void AddRegularFieldToSchedule(ViewSchedule schedule, ElementId paramId)&lt;BR /&gt;{&lt;BR /&gt;ScheduleDefinition definition = schedule.Definition;&lt;/P&gt;&lt;P&gt;// Find a matching SchedulableField&lt;BR /&gt;SchedulableField schedulableField =&lt;BR /&gt;definition.GetSchedulableFields().FirstOrDefault(sf =&amp;gt; sf.ParameterId == paramId);&lt;/P&gt;&lt;P&gt;if (schedulableField != null)&lt;BR /&gt;{&lt;BR /&gt;// Add the found field&lt;BR /&gt;definition.AddField(schedulableField);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2022 10:20:47 GMT</pubDate>
    <dc:creator>alena.karle</dc:creator>
    <dc:date>2022-11-07T10:20:47Z</dc:date>
    <item>
      <title>Element ID in schedules c# revit api</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/element-id-in-schedules-c-revit-api/m-p/11535494#M15716</link>
      <description>&lt;P&gt;Hello Forum,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to get&amp;nbsp;Element ID in schedules with c# and revit API? similar to this video with Dynamo&amp;nbsp; -&amp;nbsp;&lt;A href="https://youtu.be/U-tVoCYilxo" target="_blank"&gt;https://youtu.be/U-tVoCYilxo&lt;/A&gt;&amp;nbsp;- but with c# and revit api.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my try:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;using Autodesk.Revit.ApplicationServices;&lt;BR /&gt;using Autodesk.Revit.Attributes;&lt;BR /&gt;using Autodesk.Revit.DB;&lt;BR /&gt;using Autodesk.Revit.UI;&lt;BR /&gt;using Autodesk.Revit.UI.Selection;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;BR /&gt;using System.Text;&lt;BR /&gt;using Nice3point.Revit.Toolkit.External;&lt;BR /&gt;using Ecoworx.Core.Elements;&lt;/P&gt;&lt;P&gt;namespace Ecoworx&lt;BR /&gt;{&lt;BR /&gt;[Transaction(TransactionMode.Manual)]&lt;BR /&gt;public class CreateScheduleCommandHandler : ExternalEventHandler&lt;BR /&gt;{&lt;BR /&gt;public override void Execute(UIApplication uiapp)&lt;BR /&gt;{&lt;BR /&gt;UIDocument uidoc = uiapp.ActiveUIDocument;&lt;BR /&gt;Application app = uiapp.Application;&lt;BR /&gt;Document doc = uidoc.Document;&lt;/P&gt;&lt;P&gt;CreateSchedule(uiapp);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public static void CreateSchedule(UIApplication uiapp)&lt;BR /&gt;{&lt;BR /&gt;UIDocument uidoc = uiapp.ActiveUIDocument;&lt;BR /&gt;Application app = uiapp.Application;&lt;BR /&gt;Document doc = uidoc.Document;&lt;/P&gt;&lt;P&gt;using (Transaction t = new Transaction(doc, "Create single-category"))&lt;BR /&gt;{&lt;BR /&gt;t.Start();&lt;/P&gt;&lt;P&gt;// Create schedule&lt;BR /&gt;ViewSchedule vs = ViewSchedule.CreateSchedule(doc, new ElementId(BuiltInCategory.OST_Windows));&lt;/P&gt;&lt;P&gt;ElementId someId = new ElementId(BuiltInCategory.OST_Windows);&lt;BR /&gt;&lt;BR /&gt;BuiltInParameter bip = (BuiltInParameter)(someId.IntegerValue);&lt;/P&gt;&lt;P&gt;doc.Regenerate();&lt;/P&gt;&lt;P&gt;// Add fields to the schedule&lt;BR /&gt;AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.CASEWORK_WIDTH));&lt;BR /&gt;AddRegularFieldToSchedule(vs, new ElementId(BuiltInParameter.CASEWORK_HEIGHT));&lt;BR /&gt;AddRegularFieldToSchedule(vs, new ElementId(bip));&lt;/P&gt;&lt;P&gt;t.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public static void AddRegularFieldToSchedule(ViewSchedule schedule, ElementId paramId)&lt;BR /&gt;{&lt;BR /&gt;ScheduleDefinition definition = schedule.Definition;&lt;/P&gt;&lt;P&gt;// Find a matching SchedulableField&lt;BR /&gt;SchedulableField schedulableField =&lt;BR /&gt;definition.GetSchedulableFields().FirstOrDefault(sf =&amp;gt; sf.ParameterId == paramId);&lt;/P&gt;&lt;P&gt;if (schedulableField != null)&lt;BR /&gt;{&lt;BR /&gt;// Add the found field&lt;BR /&gt;definition.AddField(schedulableField);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;}&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 10:20:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/element-id-in-schedules-c-revit-api/m-p/11535494#M15716</guid>
      <dc:creator>alena.karle</dc:creator>
      <dc:date>2022-11-07T10:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Element ID in schedules c# revit api</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/element-id-in-schedules-c-revit-api/m-p/11535636#M15717</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;Similar to this video, you need to create a FilteredElementCollector for the required category, select all its instances and for each element get its Id and assign a value to some of its instance parameters (for example, to "Comments" parameter). Then you can add this parameter as a schedule field and retrieve the ElementId through the schedule. Here is an example in python, I'm sure you can adapt it to C#:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;elements = FilteredElementCollector(doc) \
    .OfCategory(DB.BuiltInCategory.OST_Windows) \
    .WhereElementIsNotElementType()

with DB.Transaction(doc, 'Set "Comments" Parameter Value for windows') as t:
    t.Start()
    for element in elements:
        element.Parameter[DB.BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS].Set(str(element.Id))
    t.Commit()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 11:49:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/element-id-in-schedules-c-revit-api/m-p/11535636#M15717</guid>
      <dc:creator>architect.bim</dc:creator>
      <dc:date>2022-11-07T11:49:39Z</dc:date>
    </item>
  </channel>
</rss>

