<?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 Set Parameter Value Based on Sorting of Family Instance X and Y Coordinates in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9429045#M35323</link>
    <description>&lt;P&gt;I'm trying to set a text instance parameter for a detail component based on the instance's location in the active view. I use this for numbering my beams from bottom left to top right, but the starting number will vary based on the view I'm currently in. For example, on the first floor ten beams will have the parameter B-1 through B-10 (this is why the parameter is text and not a number/integer); on the second floor six beams will be B-11 through B-16. I've got this working perfectly in Dynamo without issue but I'd like for my team to be able to run it as a button on our custom ribbon tab. I'd like the button to function as: the user selects instances to number &amp;gt; user sets starting number &amp;gt; parameter is set. The part of the coding that I'm stuck on is how to get the X and Y coordinates of the selected instances, sort them bottom left to top right, then apply the user-set starting number to the first instance in the sorted list. I've seen some code very close to parts of what I'm looking to achieve posted by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;, but I'm still very new to the Revit API side of things so I'm unable to put the pieces together on my own.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key Information: Revit 2018, Visual Studio 2019, C#, Detail Component family with text instance parameter called #, order from bottom left to top right, user sets the start value&lt;/P&gt;</description>
    <pubDate>Tue, 07 Apr 2020 23:25:50 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-04-07T23:25:50Z</dc:date>
    <item>
      <title>Set Parameter Value Based on Sorting of Family Instance X and Y Coordinates</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9429045#M35323</link>
      <description>&lt;P&gt;I'm trying to set a text instance parameter for a detail component based on the instance's location in the active view. I use this for numbering my beams from bottom left to top right, but the starting number will vary based on the view I'm currently in. For example, on the first floor ten beams will have the parameter B-1 through B-10 (this is why the parameter is text and not a number/integer); on the second floor six beams will be B-11 through B-16. I've got this working perfectly in Dynamo without issue but I'd like for my team to be able to run it as a button on our custom ribbon tab. I'd like the button to function as: the user selects instances to number &amp;gt; user sets starting number &amp;gt; parameter is set. The part of the coding that I'm stuck on is how to get the X and Y coordinates of the selected instances, sort them bottom left to top right, then apply the user-set starting number to the first instance in the sorted list. I've seen some code very close to parts of what I'm looking to achieve posted by &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/413917"&gt;@jeremytammik&lt;/a&gt;, but I'm still very new to the Revit API side of things so I'm unable to put the pieces together on my own.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key Information: Revit 2018, Visual Studio 2019, C#, Detail Component family with text instance parameter called #, order from bottom left to top right, user sets the start value&lt;/P&gt;</description>
      <pubDate>Tue, 07 Apr 2020 23:25:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9429045#M35323</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-07T23:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Set Parameter Value Based on Sorting of Family Instance X and Y Coordinates</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9429404#M35324</link>
      <description>&lt;P&gt;Getting the coordinates sorted by X and Y in the order you describe is a very simple matter of implementing an appropriate comparison function for them, and then calling the generic .NET Sort method using that comparison function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my standard XYZ comparison method from The Building Coder samples:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;    public static int Compare(
      double a,
      double b,
      double tolerance = _eps )
    {
      return IsEqual( a, b, tolerance )
        ? 0
        : (a &amp;lt; b ? -1 : 1);
    }

    public static int Compare(
      XYZ p,
      XYZ q,
      double tolerance = _eps )
    {
      int d = Compare( p.X, q.X, tolerance );

      if( 0 == d )
      {
        d = Compare( p.Y, q.Y, tolerance );

        if( 0 == d )
        {
          d = Compare( p.Z, q.Z, tolerance );
        }
      }
      return d;
    }&lt;/LI-CODE&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Apr 2020 06:30:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9429404#M35324</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2020-04-08T06:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Set Parameter Value Based on Sorting of Family Instance X and Y Coordinates</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9438025#M35325</link>
      <description>&lt;P&gt;So I think I've got it to: user PickBox area of view, filter by my family type "Framing- Beam Number", get the X and Y coordinates of the selected family instances. But then I get to the point where I order the X then Y with a LocationPoint list with OrderByDecending, and I don't think I'm doing this correctly. How do I get from the list of family instances ordered by X then Y to assigning their instance parameter "#" with a number sequence?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's what I have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;namespace BeamNumbers&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;[Transaction(TransactionMode.Manual)]&lt;/P&gt;&lt;P&gt;[Regeneration(RegenerationOption.Manual)]&lt;/P&gt;&lt;P&gt;public class Class1 : IExternalCommand&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;//Get application and document objects&lt;/P&gt;&lt;P&gt;UIApplication uiapp = commandData.Application;&lt;BR /&gt;Document doc = uiapp.ActiveUIDocument.Document;&lt;/P&gt;&lt;P&gt;//Select elements in the active view by box&lt;/P&gt;&lt;P&gt;Selection sel = uiapp.ActiveUIDocument.Selection;&lt;/P&gt;&lt;P&gt;PickedBox box;&lt;BR /&gt;try&lt;BR /&gt;{&lt;BR /&gt;box = sel.PickBox(PickBoxStyle.Enclosing, "Select Beam Numbers");&lt;BR /&gt;}&lt;BR /&gt;catch (Autodesk.Revit.Exceptions.OperationCanceledException)&lt;BR /&gt;{&lt;BR /&gt;return Result.Cancelled;&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//Select only Beam Numbers&lt;/P&gt;&lt;P&gt;IList&amp;lt;FamilyInstance&amp;gt; GetBNs(Document document)&lt;BR /&gt;{&lt;BR /&gt;List&amp;lt;FamilyInstance&amp;gt; BNS = new FilteredElementCollector(doc, doc.ActiveView.Id)&lt;BR /&gt;.OfClass(typeof(FamilyInstance))&lt;BR /&gt;.Cast&amp;lt;FamilyInstance&amp;gt;()&lt;BR /&gt;.Where(xx =&amp;gt; xx.Name.Equals("Framing- Beam Number"))&lt;BR /&gt;.ToList();&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//Get coordinates for elements and sort by X then Y&lt;/P&gt;&lt;P&gt;foreach (var xx in BNS)&lt;BR /&gt;{&lt;BR /&gt;LocationPoint LP = xx.Location as LocationPoint;&lt;BR /&gt;string x = LP.Point.X.ToString();&lt;BR /&gt;string y = LP.Point.Y.ToString();&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;List&amp;lt;LocationPoint&amp;gt; sortedLP = new List&amp;lt;LocationPoint&amp;gt;();&lt;BR /&gt;sortedLP&lt;BR /&gt;.OrderByDescending(p =&amp;gt; p.Point.X)&lt;BR /&gt;.ThenBy(p =&amp;gt; p.Point.Y)&lt;BR /&gt;.ToList();&lt;/P&gt;&lt;P&gt;//Create sequence in "#" instance parameter&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Get start number from user (output USN : User Start Number)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Sun, 12 Apr 2020 19:49:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/set-parameter-value-based-on-sorting-of-family-instance-x-and-y/m-p/9438025#M35325</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-04-12T19:49:28Z</dc:date>
    </item>
  </channel>
</rss>

