ReferenceIntersector working weird

ReferenceIntersector working weird

Anonymous
Not applicable
1,977 Views
11 Replies
Message 1 of 12

ReferenceIntersector working weird

Anonymous
Not applicable

Hi,

 

The following code works doesn't works for walls but not for pipes and ducts:

 

    public Dictionary<Reference, XYZ> GetIntersectPoints(
  Document doc,
  XYZ  ff,XYZ ff1)
        {
            // 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.

           
            XYZ startPoint = ff;
            XYZ endPoint = ff1;

            // Shoot intersector along element.

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

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

           
            builtInCats.Add(BuiltInCategory.OST_Walls);
           
            builtInCats.Add(BuiltInCategory.OST_PipeCurves);
            
            builtInCats.Add(BuiltInCategory.OST_DuctSystem);



            ElementClassFilter filter = new ElementClassFilter(typeof(PipeSegment));
            
            ElementMulticategoryFilter intersectFilter
              = new ElementMulticategoryFilter(builtInCats);

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

            //ReferenceIntersector refIntersector = new ReferenceIntersector(view3D);
            //refIntersector.TargetType = FindReferenceTarget.Face;
            //ReferenceIntersector refIntersector = new ReferenceIntersector(filter, FindReferenceTarget.Element, doc.ActiveView);

          
          

            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)
            {
                TaskDialog.Show("iipl", doc.GetElement(r.GetReference().ElementId).Name);
                dictProvisionForVoidRefs.Add(r.GetReference(),
                  r.GetReference().GlobalPoint);
            }
            return dictProvisionForVoidRefs;
        }

 

Thanks & Regards

Sanjay Pandey

0 Likes
Accepted solutions (1)
1,978 Views
11 Replies
Replies (11)
Message 2 of 12

aignatovich
Advisor
Advisor

Hi!

 

The first problem could be that the elements, you expect to find with ReferenceIntersector are not visible in the 3D view you've founded in the model, the second problem is just for ducts, you should use BuiltInCategory.OST_DuctCurves instead of BuiltInCategory.OST_DuctSystem.

 

I've played with Revit Python shell:

pipe = selection[0]

point = pipe.Location.Curve.Evaluate(0.5, True)

direction = XYZ.BasisZ

rayOrigin = point - 5 * direction

filter = ElementCategoryFilter(BuiltInCategory.OST_PipeCurves)

refIntersector = ReferenceIntersector(filter, FindReferenceTarget.Element, doc.ActiveView);

elemRef = refIntersector.FindNearest(rayOrigin, direction)

print elemRef

it works as expected

 

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi,

 

Tried BuiltInCategory.OST_DuctCurves but in vain.

 

The elements are surely visible. I have wall , duct and pipes in main file and also in linked revit file,

 

The code works fine if it intersects wall but not in case of ducts or pipes even if the elements are in main file still no result is retutned.

 

Result is returned if its a wall

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 4 of 12

Revitalizer
Advisor
Advisor

Hi,

 

may it be that the View3D doesn't show Pipe or Duct Elements?

According to your code, you take the first one you can get.

It its DetailLevel is Coarse, may it be that there is no 3D Duct/Pipe geometry to be hit at all?

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 12

aignatovich
Advisor
Advisor

Hi again!

 

You should check:

 

a) elements visibility. Are you sure, that elements are visible? According to your code, you just find first 3d View

 

b) view detail level

 

I created family to setup ray direction, and again, it works perfect (look at the attached picture):

 

targetFamily = selection[0]
transform = targetFamily.GetTotalTransform()

direction = transform.BasisZ

rayOrigin = transform.Origin

filter = ElementCategoryFilter(BuiltInCategory.OST_DuctCurves)

refIntersector = ReferenceIntersector(filter, FindReferenceTarget.Element, doc.ActiveView);

elemRef = refIntersector.FindNearest(rayOrigin, direction)

print elemRef

 

But, if view detail level is set to coarse, nothing found.

0 Likes
Message 6 of 12

Anonymous
Not applicable

Pipe or Duct Elements is clearly visible in 3d view. and details level is Fine too.

 

I think issue is something else because how come its find the wall if its intersecting

 

Thanks & Regards

Sanjay Pandey

 

0 Likes
Message 7 of 12

aignatovich
Advisor
Advisor

May be something wrong with your ray origin and direction?

0 Likes
Message 8 of 12

Anonymous
Not applicable

I think I am getting in right direction.

 

Did some R&D.

 

I changed the offset of the  pipes and ducts to 0 and now the code works.

 

In my function

public Dictionary<Reference, XYZ> GetIntersectPoints(
  Document doc,
  XYZ  ff,XYZ ff1)

for XYZ ff and XYZ ff1 I am prompting user to pick point

 

 XYZ l1 = uidoc.Selection.PickPoint();
  XYZ l2 = uidoc.Selection.PickPoint();

 

and in both the points z values are zero.

 

so this is the culprit. 

 

Now I need to think how do I get both points which includes Z value also.

 

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 9 of 12

aignatovich
Advisor
Advisor

PickPoint prompts the user to pick a point on the active work plane.

 

Perhaps you should prompt user to select model line instead

0 Likes
Message 10 of 12

Anonymous
Not applicable

But I fail to understand why PickPoint is not returning the Z value.

 

It is bound to do so.

 

Thanks & Regards

Sanjay Pandey

0 Likes
Message 11 of 12

aignatovich
Advisor
Advisor

Turn on active workplane on 3D viewactive workplane.PNG

0 Likes
Message 12 of 12

Anonymous
Not applicable
Accepted solution

Hi,

 

Thanks for all the time and effort.

 

I have now modified the code so that its prompts the user to select the element and that worked.

 

Thanks & Regards

Sanjay Pandey

0 Likes