Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

What am I doing Wrong - FindReferencesInRevitLinks

5 REPLIES 5
Reply
Message 1 of 6
sanjaymann
438 Views, 5 Replies

What am I doing Wrong - FindReferencesInRevitLinks

Hi,

 

So here is the scenario. I have a file with a single rectangular beam[str.rvt]. Then I have another file[arch.rvt] in which I have linked the file with a single beam. I create a wall in arch.rvt in a way that the beam passes through the wall. With my main document being arch.rvt and linked model being str.rvt I try to find the elements which intersect/touches/crosses and the intersecting points with the following code which doesn't return the beam;

 

foreach (Wall wall in new FilteredElementCollector(doc).OfClass(typeof(Wall))) {

Dictionary<Reference, XYZ> dict = GetIntersectPoints(doc, wall);
}


public Dictionary<Reference, XYZ> GetIntersectPoints(
  Document doc,
  Element intersect)
        {
            // Find a 3D view to use for the 
            // ReferenceIntersector constructor.

            FilteredElementCollector collector
              = new FilteredElementCollector(doc);

            Func<View3D, bool> isNotTemplate = v3
              => !(v3.IsTemplate);

            View3D view3D = collector
              .OfClass(typeof(View3D))
              .Cast<View3D>()
              .First<View3D>(isNotTemplate);

            // Use location point as start point for intersector.

            LocationCurve lp = intersect.Location as LocationCurve;
            XYZ startPoint = lp.Curve.GetEndPoint(0) as XYZ;
            XYZ endPoint = lp.Curve.GetEndPoint(1) as XYZ;

            // Shoot intersector along element.

            XYZ rayDirection = endPoint.Subtract(
              startPoint).Normalize();

            List<BuiltInCategory> builtInCats
              = new List<BuiltInCategory>();

            builtInCats.Add(BuiltInCategory.OST_StructuralFraming);
            

            ElementMulticategoryFilter intersectFilter
              = new ElementMulticategoryFilter(builtInCats);

            ReferenceIntersector refIntersector
              = new ReferenceIntersector(intersectFilter,
                FindReferenceTarget.All, view3D);

            refIntersector.FindReferencesInRevitLinks = true;

            IList<ReferenceWithContext> referencesWithContext
              = refIntersector.Find(startPoint,
                rayDirection);

            IList<XYZ> intersectPoints = new List<XYZ>();

            IList<Reference> intersectRefs
              = new List<Reference>();

            Dictionary<Reference, XYZ> dictProvisionForVoidRefs
              = new Dictionary<Reference, XYZ>();

            foreach (ReferenceWithContext r in
              referencesWithContext)
            {

                dictProvisionForVoidRefs.Add(r.GetReference(),
                  r.GetReference().GlobalPoint);
            }
            return dictProvisionForVoidRefs;
        }

Thanks & Regards

Sanjay Pandey

5 REPLIES 5
Message 2 of 6
jeremytammik
in reply to: sanjaymann

I assume that the reference intersector view must belong to the same document as the element you are searching for.

 

If you have a linked file, you will probably have to translate the wall bounding box back into the corresponding location in the linked file coordinate system.

 

Just guessing!

 

Cheers,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 6
Revitalizer
in reply to: sanjaymann

Hi,

 

maybe you need to add

 

builtInCats.Add(BuiltInCategory.OST_RvtLinks);

 

to find also the RevitLinkInstances themselves.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 4 of 6
sanjaymann
in reply to: Revitalizer

Hi,

 

Tried but same result

 

Thanks & Regards

Sanjay Pandey

Message 5 of 6
Revitalizer
in reply to: sanjaymann

Hi,

 

the Wall's location line is on its bottom.

You will never find the beam if it does not really cross this ray.

 

So either you use a set of rays inside the wall and parallel to the wall's location curve, like a comb, like the horizontal lines in the letter E.

Or you can change the approach by using the beam's curve to find the wall(s) it hits.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Message 6 of 6
Revitalizer
in reply to: sanjaymann

Hi,

 

things may become much clearer if you display the lines as ModelCurves.

So you can easily see the Wall's location curve and the ray you use.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community