<?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 Re: API c# question in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/12061176#M73931</link>
    <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good morning,&amp;nbsp;&lt;/P&gt;&lt;P&gt;i writed this code to set the numbering automatically, but in each time I re-execute my code it begin the numbering from 0 instead of lastassignednumber.&lt;/P&gt;&lt;P&gt;so where is the error ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&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.Events;&lt;BR /&gt;using Autodesk.Revit.DB.ExtensibleStorage;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;/P&gt;&lt;P&gt;namespace Number&lt;BR /&gt;{&lt;BR /&gt;[Transaction(TransactionMode.Manual)]&lt;BR /&gt;public class Code : IExternalCommand&lt;BR /&gt;{&lt;BR /&gt;private const string SchemaGUID = "633FEF1C-4DF3-4C07-A812-D392C8015194";&lt;BR /&gt;private const string MinRangePropertyName = "MinRange";&lt;BR /&gt;private const string MaxRangePropertyName = "MaxRange";&lt;BR /&gt;private const string LastAssignedNumberPropertyName = "LastAssignedNumber";&lt;/P&gt;&lt;P&gt;private int currentNumber;&lt;BR /&gt;private int minRange;&lt;BR /&gt;private int maxRange;&lt;BR /&gt;private ICollection&amp;lt;ElementId&amp;gt; addedElementIds = new List&amp;lt;ElementId&amp;gt;();&lt;/P&gt;&lt;P&gt;public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)&lt;BR /&gt;{&lt;BR /&gt;UIApplication uiApp = commandData.Application;&lt;BR /&gt;UIDocument uiDoc = uiApp.ActiveUIDocument;&lt;BR /&gt;Document doc = uiDoc.Document;&lt;/P&gt;&lt;P&gt;addedElementIds = GetWallElement(doc);&lt;/P&gt;&lt;P&gt;if (!RetrieveRangeValues(doc))&lt;BR /&gt;{&lt;BR /&gt;// Range values not found, prompt the user to enter the range&lt;BR /&gt;using (Window window = new Window(doc))&lt;BR /&gt;{&lt;BR /&gt;window.ShowDialog();&lt;/P&gt;&lt;P&gt;minRange = window.minRange;&lt;BR /&gt;maxRange = window.maxRange;&lt;BR /&gt;currentNumber = minRange;&lt;/P&gt;&lt;P&gt;StoreRangeValues(doc);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;currentNumber = RetrieveLastAssignedNumber(doc);&lt;BR /&gt;if (currentNumber &amp;lt; minRange || currentNumber &amp;gt; maxRange)&lt;BR /&gt;{&lt;BR /&gt;// Handle the case where the last assigned number is outside the specified range&lt;BR /&gt;// You can display an error message or take appropriate action here&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;TaskDialog.Show("Range", "Your entered range is between: \n" + minRange.ToString() + " - " + maxRange.ToString() + "\n" +&lt;BR /&gt;"Current Number: " + currentNumber);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Subscribe to the Idling event&lt;BR /&gt;uiApp.Idling += HandleIdlingEvent;&lt;/P&gt;&lt;P&gt;return Result.Succeeded;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void HandleIdlingEvent(object sender, IdlingEventArgs e)&lt;BR /&gt;{&lt;BR /&gt;UIApplication uiApp = sender as UIApplication;&lt;BR /&gt;Document doc = uiApp.ActiveUIDocument.Document;&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Check for newly added walls in the document&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(doc);&lt;BR /&gt;collector.OfCategory(BuiltInCategory.OST_Walls);&lt;/P&gt;&lt;P&gt;ICollection&amp;lt;ElementId&amp;gt; currentElementIds = collector.ToElementIds();&lt;/P&gt;&lt;P&gt;// Find the added wall element ids by comparing the current element ids with the previously stored ids&lt;BR /&gt;IEnumerable&amp;lt;ElementId&amp;gt; newElementIds = currentElementIds.Except(addedElementIds);&lt;/P&gt;&lt;P&gt;if (newElementIds.Any())&lt;BR /&gt;{&lt;BR /&gt;using (Transaction trans = new Transaction(doc, "Assign Number to Walls"))&lt;BR /&gt;{&lt;BR /&gt;trans.Start();&lt;/P&gt;&lt;P&gt;foreach (ElementId elementId in newElementIds)&lt;BR /&gt;{&lt;BR /&gt;Element element = doc.GetElement(elementId);&lt;/P&gt;&lt;P&gt;if (element is Wall wall)&lt;BR /&gt;{&lt;BR /&gt;// Get the custom "Number" parameter&lt;BR /&gt;Parameter parameter = wall.LookupParameter("Number");&lt;/P&gt;&lt;P&gt;if (parameter != null &amp;amp;&amp;amp; parameter.StorageType == StorageType.String)&lt;BR /&gt;{&lt;BR /&gt;parameter.Set(currentNumber.ToString());&lt;BR /&gt;currentNumber++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;trans.Commit();&lt;/P&gt;&lt;P&gt;// Update the added element ids for the next idling event&lt;BR /&gt;addedElementIds = currentElementIds;&lt;/P&gt;&lt;P&gt;// Store the last assigned number&lt;BR /&gt;StoreLastAssignedNumber(doc, currentNumber);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public ICollection&amp;lt;ElementId&amp;gt; GetWallElement(Document doc)&lt;BR /&gt;{&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(doc);&lt;BR /&gt;collector.OfCategory(BuiltInCategory.OST_Walls);&lt;BR /&gt;return collector.ToElementIds().ToList();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private bool RetrieveRangeValues(Document doc)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema != null)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = doc.ProjectInformation.GetEntity(schema);&lt;/P&gt;&lt;P&gt;if (entity.IsValid())&lt;BR /&gt;{&lt;BR /&gt;minRange = entity.Get&amp;lt;int&amp;gt;(schema.GetField(MinRangePropertyName));&lt;BR /&gt;maxRange = entity.Get&amp;lt;int&amp;gt;(schema.GetField(MaxRangePropertyName));&lt;BR /&gt;currentNumber = entity.Get&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName));&lt;/P&gt;&lt;P&gt;currentNumber = RetrieveLastAssignedNumber(doc); // Retrieve the last assigned number&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return false;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private int RetrieveLastAssignedNumber(Document doc)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema != null)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = doc.ProjectInformation.GetEntity(schema);&lt;/P&gt;&lt;P&gt;if (entity.IsValid())&lt;BR /&gt;{&lt;BR /&gt;return entity.Get&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName));&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Return a default value if the last assigned number cannot be retrieved&lt;BR /&gt;return 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void StoreRangeValues(Document doc)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema == null)&lt;BR /&gt;{&lt;BR /&gt;SchemaBuilder schemaBuilder = new SchemaBuilder(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;schemaBuilder.SetSchemaName("NumberSchema");&lt;BR /&gt;schemaBuilder.SetReadAccessLevel(AccessLevel.Public);&lt;BR /&gt;schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);&lt;/P&gt;&lt;P&gt;FieldBuilder minRangeField = schemaBuilder.AddSimpleField(MinRangePropertyName, typeof(int));&lt;BR /&gt;FieldBuilder maxRangeField = schemaBuilder.AddSimpleField(MaxRangePropertyName, typeof(int));&lt;BR /&gt;FieldBuilder lastAssignedNumberField = schemaBuilder.AddSimpleField(LastAssignedNumberPropertyName, typeof(int));&lt;/P&gt;&lt;P&gt;schema = schemaBuilder.Finish();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;using (Transaction trans = new Transaction(doc, "Store Range Values"))&lt;BR /&gt;{&lt;BR /&gt;trans.Start();&lt;/P&gt;&lt;P&gt;Entity entity = new Entity(schema);&lt;/P&gt;&lt;P&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(MinRangePropertyName), minRange);&lt;BR /&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(MaxRangePropertyName), maxRange);&lt;/P&gt;&lt;P&gt;doc.ProjectInformation.SetEntity(entity);&lt;/P&gt;&lt;P&gt;trans.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void StoreLastAssignedNumber(Document doc, int number)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema != null)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = doc.ProjectInformation.GetEntity(schema);&lt;/P&gt;&lt;P&gt;if (entity.IsValid())&lt;BR /&gt;{&lt;BR /&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName), number);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;entity = new Entity(schema);&lt;BR /&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName), number);&lt;BR /&gt;doc.ProjectInformation.SetEntity(entity);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Jun 2023 15:02:20 GMT</pubDate>
    <dc:creator>hasan_kassem</dc:creator>
    <dc:date>2023-06-26T15:02:20Z</dc:date>
    <item>
      <title>API c# question</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/5506500#M73928</link>
      <description>&lt;DIV class="lia-message-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First of all I haven't found an answer to my question in an existing post, please feel free to redirect me there if you know one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently coding a plugin for Revit 2015 that insert a family of my choice inside an existing project.&lt;/P&gt;&lt;P&gt;I want to insert the family directly on a face of an existing 3D item. But depending on the situation I must insert it on different type of faces, such as planar faces or cylindrical. Problem is, I can't get my code to function on either, I don't know how to check for the type of face prior to my operations.&lt;/P&gt;&lt;P&gt;That's my code for cylindrical faces&lt;/P&gt;&lt;PRE&gt;                Reference r = uidoc.Selection.PickObject(ObjectType.Face,
                  "Please pick a point on a face for family instance insertion");

                Element e = doc.GetElement(r.ElementId);
                GeometryObject obj = e.GetGeometryObjectFromReference(r);
                //PlanarFace face = obj as PlanarFace;
                CylindricalFace face = obj as CylindricalFace;
                    XYZ p = r.GlobalPoint;
                    XYZ v = face.Axis.CrossProduct(XYZ.BasisZ);
                    if (v.IsZeroLength())
                    {
                        v = face.Axis.CrossProduct(XYZ.BasisX);
                    }
                    doc.Create.NewFamilyInstance(r, p, v, symbol);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;And that's my code for planar faces&lt;/P&gt;&lt;PRE&gt;                Reference r = uidoc.Selection.PickObject(ObjectType.Face,
                  "Please pick a point on a face for family instance insertion");

                Element e = doc.GetElement(r.ElementId);
                GeometryObject obj = e.GetGeometryObjectFromReference(r);
                PlanarFace face = obj as PlanarFace;
                //CylindricalFace face = obj as CylindricalFace;
                    
                XYZ p = r.GlobalPoint;
                XYZ v = face.Normal.CrossProduct(XYZ.BasisZ);
                if (v.IsZeroLength())
                {
                    v = face.Normal.CrossProduct(XYZ.BasisX);
                }
                doc.Create.NewFamilyInstance(r, p, v, symbol);&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Almost nothing changes except for the declaration of v with the change : Axis/Normal&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been using the code from Jeremy Tammik thebuildingcoder, I'm fairly new to programming and totally new to C#, and I've never used any API before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have other questions :&lt;/P&gt;&lt;P&gt;Right now I'm typing the path and the name of the family item that I want to insert directly inside my code. Ideally, I'd like the user to pick the family when he starts the plugin, but I have no idea how to do that.&lt;/P&gt;&lt;P&gt;Last thing I'd like to know is, after my family is inserted, how do I run automatically an interference check to see if there is any collision. The plugin is aimed to people totally new to geomatics, that have never used any software like autocad, I want them to push the least buttons possible to achivieve their goal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much in advance for your time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jordi&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 13 Feb 2015 15:23:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/5506500#M73928</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-02-13T15:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: API c# question</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/5507353#M73929</link>
      <description>&lt;P&gt;Dear Jordi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Happy Valentine's Day!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That sounds like a pretty cool project.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Congratulations on getting so far with it already.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I answered your queries pretty extensively on The Building Coder:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2015/02/determining-the-face-tangent-at-a-picked-point.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2015/02/determining-the-face-tangent-at-a-picked-point.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;</description>
      <pubDate>Sat, 14 Feb 2015 14:17:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/5507353#M73929</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2015-02-14T14:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: API c# question</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/5508167#M73930</link>
      <description>&lt;P&gt;Hi Jeremy !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much I'll take a look right away !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jordi&lt;/P&gt;</description>
      <pubDate>Mon, 16 Feb 2015 07:45:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/5508167#M73930</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2015-02-16T07:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: API c# question</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/12061176#M73931</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good morning,&amp;nbsp;&lt;/P&gt;&lt;P&gt;i writed this code to set the numbering automatically, but in each time I re-execute my code it begin the numbering from 0 instead of lastassignednumber.&lt;/P&gt;&lt;P&gt;so where is the error ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&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.Events;&lt;BR /&gt;using Autodesk.Revit.DB.ExtensibleStorage;&lt;BR /&gt;using System;&lt;BR /&gt;using System.Collections.Generic;&lt;BR /&gt;using System.Linq;&lt;/P&gt;&lt;P&gt;namespace Number&lt;BR /&gt;{&lt;BR /&gt;[Transaction(TransactionMode.Manual)]&lt;BR /&gt;public class Code : IExternalCommand&lt;BR /&gt;{&lt;BR /&gt;private const string SchemaGUID = "633FEF1C-4DF3-4C07-A812-D392C8015194";&lt;BR /&gt;private const string MinRangePropertyName = "MinRange";&lt;BR /&gt;private const string MaxRangePropertyName = "MaxRange";&lt;BR /&gt;private const string LastAssignedNumberPropertyName = "LastAssignedNumber";&lt;/P&gt;&lt;P&gt;private int currentNumber;&lt;BR /&gt;private int minRange;&lt;BR /&gt;private int maxRange;&lt;BR /&gt;private ICollection&amp;lt;ElementId&amp;gt; addedElementIds = new List&amp;lt;ElementId&amp;gt;();&lt;/P&gt;&lt;P&gt;public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)&lt;BR /&gt;{&lt;BR /&gt;UIApplication uiApp = commandData.Application;&lt;BR /&gt;UIDocument uiDoc = uiApp.ActiveUIDocument;&lt;BR /&gt;Document doc = uiDoc.Document;&lt;/P&gt;&lt;P&gt;addedElementIds = GetWallElement(doc);&lt;/P&gt;&lt;P&gt;if (!RetrieveRangeValues(doc))&lt;BR /&gt;{&lt;BR /&gt;// Range values not found, prompt the user to enter the range&lt;BR /&gt;using (Window window = new Window(doc))&lt;BR /&gt;{&lt;BR /&gt;window.ShowDialog();&lt;/P&gt;&lt;P&gt;minRange = window.minRange;&lt;BR /&gt;maxRange = window.maxRange;&lt;BR /&gt;currentNumber = minRange;&lt;/P&gt;&lt;P&gt;StoreRangeValues(doc);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;currentNumber = RetrieveLastAssignedNumber(doc);&lt;BR /&gt;if (currentNumber &amp;lt; minRange || currentNumber &amp;gt; maxRange)&lt;BR /&gt;{&lt;BR /&gt;// Handle the case where the last assigned number is outside the specified range&lt;BR /&gt;// You can display an error message or take appropriate action here&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;TaskDialog.Show("Range", "Your entered range is between: \n" + minRange.ToString() + " - " + maxRange.ToString() + "\n" +&lt;BR /&gt;"Current Number: " + currentNumber);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Subscribe to the Idling event&lt;BR /&gt;uiApp.Idling += HandleIdlingEvent;&lt;/P&gt;&lt;P&gt;return Result.Succeeded;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void HandleIdlingEvent(object sender, IdlingEventArgs e)&lt;BR /&gt;{&lt;BR /&gt;UIApplication uiApp = sender as UIApplication;&lt;BR /&gt;Document doc = uiApp.ActiveUIDocument.Document;&lt;/P&gt;&lt;P&gt;try&lt;BR /&gt;{&lt;BR /&gt;// Check for newly added walls in the document&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(doc);&lt;BR /&gt;collector.OfCategory(BuiltInCategory.OST_Walls);&lt;/P&gt;&lt;P&gt;ICollection&amp;lt;ElementId&amp;gt; currentElementIds = collector.ToElementIds();&lt;/P&gt;&lt;P&gt;// Find the added wall element ids by comparing the current element ids with the previously stored ids&lt;BR /&gt;IEnumerable&amp;lt;ElementId&amp;gt; newElementIds = currentElementIds.Except(addedElementIds);&lt;/P&gt;&lt;P&gt;if (newElementIds.Any())&lt;BR /&gt;{&lt;BR /&gt;using (Transaction trans = new Transaction(doc, "Assign Number to Walls"))&lt;BR /&gt;{&lt;BR /&gt;trans.Start();&lt;/P&gt;&lt;P&gt;foreach (ElementId elementId in newElementIds)&lt;BR /&gt;{&lt;BR /&gt;Element element = doc.GetElement(elementId);&lt;/P&gt;&lt;P&gt;if (element is Wall wall)&lt;BR /&gt;{&lt;BR /&gt;// Get the custom "Number" parameter&lt;BR /&gt;Parameter parameter = wall.LookupParameter("Number");&lt;/P&gt;&lt;P&gt;if (parameter != null &amp;amp;&amp;amp; parameter.StorageType == StorageType.String)&lt;BR /&gt;{&lt;BR /&gt;parameter.Set(currentNumber.ToString());&lt;BR /&gt;currentNumber++;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;trans.Commit();&lt;/P&gt;&lt;P&gt;// Update the added element ids for the next idling event&lt;BR /&gt;addedElementIds = currentElementIds;&lt;/P&gt;&lt;P&gt;// Store the last assigned number&lt;BR /&gt;StoreLastAssignedNumber(doc, currentNumber);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;public ICollection&amp;lt;ElementId&amp;gt; GetWallElement(Document doc)&lt;BR /&gt;{&lt;BR /&gt;FilteredElementCollector collector = new FilteredElementCollector(doc);&lt;BR /&gt;collector.OfCategory(BuiltInCategory.OST_Walls);&lt;BR /&gt;return collector.ToElementIds().ToList();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private bool RetrieveRangeValues(Document doc)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema != null)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = doc.ProjectInformation.GetEntity(schema);&lt;/P&gt;&lt;P&gt;if (entity.IsValid())&lt;BR /&gt;{&lt;BR /&gt;minRange = entity.Get&amp;lt;int&amp;gt;(schema.GetField(MinRangePropertyName));&lt;BR /&gt;maxRange = entity.Get&amp;lt;int&amp;gt;(schema.GetField(MaxRangePropertyName));&lt;BR /&gt;currentNumber = entity.Get&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName));&lt;/P&gt;&lt;P&gt;currentNumber = RetrieveLastAssignedNumber(doc); // Retrieve the last assigned number&lt;/P&gt;&lt;P&gt;return true;&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;return false;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private int RetrieveLastAssignedNumber(Document doc)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema != null)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = doc.ProjectInformation.GetEntity(schema);&lt;/P&gt;&lt;P&gt;if (entity.IsValid())&lt;BR /&gt;{&lt;BR /&gt;return entity.Get&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName));&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;// Return a default value if the last assigned number cannot be retrieved&lt;BR /&gt;return 0;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void StoreRangeValues(Document doc)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema == null)&lt;BR /&gt;{&lt;BR /&gt;SchemaBuilder schemaBuilder = new SchemaBuilder(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;schemaBuilder.SetSchemaName("NumberSchema");&lt;BR /&gt;schemaBuilder.SetReadAccessLevel(AccessLevel.Public);&lt;BR /&gt;schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);&lt;/P&gt;&lt;P&gt;FieldBuilder minRangeField = schemaBuilder.AddSimpleField(MinRangePropertyName, typeof(int));&lt;BR /&gt;FieldBuilder maxRangeField = schemaBuilder.AddSimpleField(MaxRangePropertyName, typeof(int));&lt;BR /&gt;FieldBuilder lastAssignedNumberField = schemaBuilder.AddSimpleField(LastAssignedNumberPropertyName, typeof(int));&lt;/P&gt;&lt;P&gt;schema = schemaBuilder.Finish();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;using (Transaction trans = new Transaction(doc, "Store Range Values"))&lt;BR /&gt;{&lt;BR /&gt;trans.Start();&lt;/P&gt;&lt;P&gt;Entity entity = new Entity(schema);&lt;/P&gt;&lt;P&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(MinRangePropertyName), minRange);&lt;BR /&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(MaxRangePropertyName), maxRange);&lt;/P&gt;&lt;P&gt;doc.ProjectInformation.SetEntity(entity);&lt;/P&gt;&lt;P&gt;trans.Commit();&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;private void StoreLastAssignedNumber(Document doc, int number)&lt;BR /&gt;{&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;Schema schema = Schema.Lookup(new Guid(SchemaGUID));&lt;/P&gt;&lt;P&gt;if (schema != null)&lt;BR /&gt;{&lt;BR /&gt;Entity entity = doc.ProjectInformation.GetEntity(schema);&lt;/P&gt;&lt;P&gt;if (entity.IsValid())&lt;BR /&gt;{&lt;BR /&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName), number);&lt;BR /&gt;}&lt;BR /&gt;else&lt;BR /&gt;{&lt;BR /&gt;entity = new Entity(schema);&lt;BR /&gt;entity.Set&amp;lt;int&amp;gt;(schema.GetField(LastAssignedNumberPropertyName), number);&lt;BR /&gt;doc.ProjectInformation.SetEntity(entity);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;catch (Exception ex)&lt;BR /&gt;{&lt;BR /&gt;TaskDialog.Show("Error", ex.Message);&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 15:02:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/12061176#M73931</guid>
      <dc:creator>hasan_kassem</dc:creator>
      <dc:date>2023-06-26T15:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: API c# question</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/12061345#M73932</link>
      <description>&lt;P&gt;TLDR; but:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I remember, my SetoutPoints performs some pretty nifty, persistent and customisable automatic numbering:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/SetoutPoints" target="_blank"&gt;https://github.com/jeremytammik/SetoutPoints&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Jun 2023 15:50:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/api-c-question/m-p/12061345#M73932</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2023-06-26T15:50:37Z</dc:date>
    </item>
  </channel>
</rss>

