<?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: Using ReferenceIntersector in Linked Files in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9519573#M34248</link>
    <description>&lt;P&gt;If there is a reason - here is code to get StableRepresentation of linked wall exterior face&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public string GetFaceRefRepresentation(Wall wall, Document doc, RevitLinkInstance instance)
{
 Reference faceRef = HostObjectUtils.GetSideFaces(wall, 
 ShellLayerType.Exterior).FirstOrDefault();
 Reference stRef = faceRef.CreateLinkReference(instance);
 string stable = stRef.ConvertToStableRepresentation(doc);
 return stable;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 15 May 2020 18:14:25 GMT</pubDate>
    <dc:creator>IliaIvanov</dc:creator>
    <dc:date>2020-05-15T18:14:25Z</dc:date>
    <item>
      <title>Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9516302#M34244</link>
      <description>&lt;P&gt;I have faced the problem - How to use ReferenceIntersector with elements of RevitLinkInstance. I have achieved some results using filters and etc - another words it works rather good, Below my solution&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 14:46:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9516302#M34244</guid>
      <dc:creator>IliaIvanov</dc:creator>
      <dc:date>2020-05-14T14:46:28Z</dc:date>
    </item>
    <item>
      <title>Re: Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9516381#M34245</link>
      <description>&lt;P&gt;Here is some method&amp;nbsp;for finding walls crossed by a pipe&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public IList&amp;lt;Element&amp;gt; GetElementsFromIntersector (Document doc, Element pipe)
{
 IList&amp;lt;Element&amp;gt; walls = new List&amp;lt;Element&amp;gt;();
//Get Curve to provide start of reference Ray and direction
 LocationCurve lc = pipe.Location as LocationCurve;
 Curve curve = lc.Curve;
//Add custom equalityComparer to distinct List
 ReferenceComparer reference1 = new ReferenceComparer();
//Add Filter to find walls in linked project
 ElementFilter filter = new 
 ElementCategoryFilter(BuiltInCategory.OST_Walls);
//Find 3d view for ReferenceIntersector
 FilteredElementCollector collector = new FilteredElementCollector(doc);
 Func&amp;lt;View3D, bool&amp;gt; isNotTemplate = v3 =&amp;gt; !(v3.IsTemplate);
 View3D view3D = collector.OfClass(typeof(View3D)).Cast&amp;lt;View3D&amp;gt;() 
 .First&amp;lt;View3D&amp;gt;(isNotTemplate);
//Set property of referenceIntersector to work with Links
 refIntersector.FindReferencesInRevitLinks = true;

 IList&amp;lt;ReferenceWithContext&amp;gt; referenceWithContext = 
 refIntersector.Find(curve.GetEndPoint(0), (curve as Line).Direction);
//Select uniq references from referenceWithContext
 IList&amp;lt;Reference&amp;gt; references = referenceWithContext.Select(p =&amp;gt; 
 p.GetReference()).Distinct(reference1).ToList();    
 foreach(Reference reference in references)     
 {
  RevitLinkInstance instance = doc.GetElement(reference) as 
  RevitLinkInstance;
  Document linkDoc = instance.GetLinkDocument();
  Element wall = 
  linkDoc.GetElement(reference.LinkedElementId);
 }    

}

//Custom EqualityComparer
public class ReferenceComparer : IEqualityComparer&amp;lt;Reference&amp;gt;
 {
   public bool Equals(Reference x, Reference y)
    {              
      if (x.ElementId == y.ElementId)
      {                  
        if (x.LinkedElementId == y.LinkedElementId)         
        {
          return true;
        }               
          return false;            
      }             
     return false;
    }  
  public int GetHashCode(Reference obj)
    {
     int hashName = obj.ElementId.GetHashCode();
     int hashId = obj.LinkedElementId.GetHashCode();
     return hashId ^ hashId;
     }
    }          
                
               
           

          &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 May 2020 15:09:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9516381#M34245</guid>
      <dc:creator>IliaIvanov</dc:creator>
      <dc:date>2020-05-14T15:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9518502#M34246</link>
      <description>&lt;P&gt;Thank you very much for sharing your solution and code!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please add a short description?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Optimally, describe the context, the problem, the solution, add an image and screen snapshot or two illustrating the situation and how the solution works, add a minimal sample model to run a test in, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That would help a lot to understand what it is about and how useful it is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 11:26:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9518502#M34246</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2020-05-15T11:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9519467#M34247</link>
      <description>&lt;P&gt;Sure!&lt;BR /&gt;My task was -&amp;nbsp; add opening family to the wall crossing pipe.&amp;nbsp; I decided to achieve it using IUpdater. My solution worked good with non linked walls, I used filters to make ReferenceIntersector find only walls. But when I started preparing solution for link walls I faced problem - References from ReferenceWithContext List contains id of RevitLinkInstance, but not the id of target walls,&amp;nbsp; it means I could`t gather linked walls.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ilia77554046FJED_0-1589559811711.png" style="width: 400px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/771113i4DFD97DD0DCF1B61/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ilia77554046FJED_0-1589559811711.png" alt="ilia77554046FJED_0-1589559811711.png" /&gt;&lt;/span&gt;&lt;BR /&gt;I have looked throw this post&amp;nbsp;&lt;A href="https://thebuildingcoder.typepad.com/blog/2015/07/using-referenceintersector-in-linked-files.html" target="_blank" rel="noopener"&gt;https://thebuildingcoder.typepad.com/blog/2015/07/using-referenceintersector-in-linked-files.html&lt;/A&gt; and found that we can`t get references from linked file.&amp;nbsp;&lt;BR /&gt;I started doing debug of my code and realized solution. The Reference class has property "LinkedElementId", if we have RevitLinkInstance and property of element in linked file - we can get the element in linked file. But when my pipe crosses the linked wall - in&amp;nbsp;ReferenceWithContext &amp;nbsp;list&amp;nbsp; &amp;nbsp;I have some amount of elements with the same ids("LinkedElementId","Id"), maybe because it also gather geometry&amp;nbsp; like faces and etc. To dictinct this list I had to create custom&amp;nbsp;EqualityCompare. Finally the code started working perfect . Found some bugs in code above. Here is method to gather count of intersected walls. (Note to achieve good results - need to set 3d view without section boxes). Unfortunately no time to add comments to the code. Hope it may help somebody.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bellow Project with macro to test&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;LI-CODE lang="general"&gt;public void GetWalls()
	{
	Reference pipeRef = this.Selection.PickObject(ObjectType.Element);
	Element pipeElem = this.Document.GetElement(pipeRef);

	LocationCurve lc = pipeElem.Location as LocationCurve;
	Curve curve = lc.Curve;
	   	    
	ReferenceComparer reference1 = new ReferenceComparer();
			 
	ElementFilter filter = new 
        ElementCategoryFilter(BuiltInCategory.OST_Walls);
			 
	 FilteredElementCollector collector = new 
         FilteredElementCollector(this.Document);
         Func&amp;lt;View3D, bool&amp;gt; isNotTemplate = v3 =&amp;gt; !(v3.IsTemplate);
         View3D view3D = collector.OfClass(typeof(View3D)).Cast&amp;lt;View3D&amp;gt;() 
         .First&amp;lt;View3D&amp;gt;(isNotTemplate);
        
          ReferenceIntersector refIntersector = new 
          ReferenceIntersector(filter, FindReferenceTarget.Element, 
          view3D);
          refIntersector.FindReferencesInRevitLinks = true;
          IList&amp;lt;ReferenceWithContext&amp;gt; referenceWithContext = 
          refIntersector.Find(curve.GetEndPoint(0), (curve as 
          Line).Direction);
          IList&amp;lt;Reference&amp;gt; references = referenceWithContext.Select(p =&amp;gt; p.GetReference()).Distinct(reference1).Where(p=&amp;gt;p.GlobalPoint.DistanceTo(curve.GetEndPoint(0))&amp;lt;curve.Length).ToList();
          IList&amp;lt;Element&amp;gt;walls = new List&amp;lt;Element&amp;gt;();
          foreach (Reference reference in references)
          {
           RevitLinkInstance instance = this.Document.GetElement(reference) 
           as RevitLinkInstance;
           Document linkDoc = instance.GetLinkDocument();
           Element element = linkDoc.GetElement(reference.LinkedElementId);
           walls.Add(element);
           }
              TaskDialog.Show("Count of wall",walls.Count.ToString());
	}
public class ReferenceComparer : IEqualityComparer&amp;lt;Reference&amp;gt;
{
 public bool Equals(Reference x, Reference y)
 {              
  if (x.ElementId == y.ElementId)
  {                  
   if (x.LinkedElementId == y.LinkedElementId)         
   {
    return true;
   }               
    return false;            
   }             
   return false;
  }  
  public int GetHashCode(Reference obj)
  {
   int hashName = obj.ElementId.GetHashCode();
   int hashId = obj.LinkedElementId.GetHashCode();
   return hashId ^ hashId;
  }
}          &lt;/LI-CODE&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;</description>
      <pubDate>Fri, 15 May 2020 17:44:41 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9519467#M34247</guid>
      <dc:creator>IliaIvanov</dc:creator>
      <dc:date>2020-05-15T17:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9519573#M34248</link>
      <description>&lt;P&gt;If there is a reason - here is code to get StableRepresentation of linked wall exterior face&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;public string GetFaceRefRepresentation(Wall wall, Document doc, RevitLinkInstance instance)
{
 Reference faceRef = HostObjectUtils.GetSideFaces(wall, 
 ShellLayerType.Exterior).FirstOrDefault();
 Reference stRef = faceRef.CreateLinkReference(instance);
 string stable = stRef.ConvertToStableRepresentation(doc);
 return stable;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 May 2020 18:14:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9519573#M34248</guid>
      <dc:creator>IliaIvanov</dc:creator>
      <dc:date>2020-05-15T18:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9526176#M34249</link>
      <description>&lt;P&gt;Thank you very much for sharing and documenting this!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I published it for posterity in The Building Coder:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://thebuildingcoder.typepad.com/blog/2020/05/using-referenceintersector-with-a-linked-file.html" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2020/05/using-referenceintersector-with-a-linked-file.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&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>Tue, 19 May 2020 10:31:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9526176#M34249</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2020-05-19T10:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Using ReferenceIntersector in Linked Files</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9526186#M34250</link>
      <description>&lt;P&gt;You are welcome&lt;span class="lia-unicode-emoji" title=":grinning_face_with_big_eyes:"&gt;😃&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 10:34:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/using-referenceintersector-in-linked-files/m-p/9526186#M34250</guid>
      <dc:creator>IliaIvanov</dc:creator>
      <dc:date>2020-05-19T10:34:56Z</dc:date>
    </item>
  </channel>
</rss>

