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: 

select elements witch cut by the view

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
glenncai
2597 Views, 9 Replies

select elements witch cut by the view

HI, 

I'm looking for a way to hide all the framing members that are being cut on the section or elevation view.

currently I have to select them and hide them manually.   

Is there any methods or properties that allows me to filter out the elements that cut by the view thru the  API?

I tried to google this and search the chm file for cut line but have no luck yet. any suggestions? Thanks.

cut line.jpg

9 REPLIES 9
Message 2 of 10
glenncai
in reply to: glenncai

sorry for my funny typo. Woman Embarassed

Message 3 of 10
FAIR59
in reply to: glenncai

You can use a BoundingBoxIntersectsFilter.

 

BoundingBoxIntersectsFilter CutPlaneFilter = new BoundingBoxIntersectsFilter(_outline);

List<Element>  ElemsInCutPlane =

   new FilteredElementCollector(doc, ActiveView.Id)

      .WhereElementIsNotElementType()

      .WherePasses(CutPlaneFilter)

      .ToList<Element>();

 

 

where _outline is made from the points of a region in the cutplane , for instance the Crop Region

Message 4 of 10
desdinova
in reply to: glenncai

Hello gleencai 

Did you find solution 

I have a similar question

 

BoundingBoxIntersectsFilter CutPlaneFilter = new BoundingBoxIntersectsFilter(_outline);

List<Element>  ElemsInCutPlane =

   new FilteredElementCollector(doc, ActiveView.Id)

      .WhereElementIsNotElementType()

      .WherePasses(CutPlaneFilter)

      .ToList<Element>();

 

Didn't work for më Thanks in advance. ...

Message 5 of 10
FAIR59
in reply to: desdinova

@desdinova

 

Sorry to hear that it doesn't work for you. Before posting a did a small scale test, and it worked fine.( 1 wall in empty project)  The "code" in my previous post, is intended as a roadmap / pseudocode.

 

this is my testing code:

            StringBuilder s = new StringBuilder();
            Document doc = revit.Application.ActiveUIDocument.Document;
            Autodesk.Revit.DB.View ActView = doc.ActiveView;
            XYZ pt1 = new XYZ(0, 0, 0);
            XYZ pt2 = new XYZ(0, 0, 100);
            XYZ pt3 = new XYZ(0, 100, 100);
            XYZ pt4 = new XYZ(0, 100, 0);
            Outline _outline = new Outline(pt1, pt3);
            _outline.AddPoint(pt2);
            _outline.AddPoint(pt4);

            BoundingBoxIntersectsFilter CutPlaneFilter = new BoundingBoxIntersectsFilter(_outline);
            List<Element> ElemsInCutPlane =
                   new FilteredElementCollector(doc, doc.ActiveView.Id)
                            .WhereElementIsNotElementType()
                            .WhereElementIsViewIndependent()
                            .WherePasses(CutPlaneFilter)
                            .ToList<Element>();
            s.AppendLine(string.Format("{0} elements found",ElemsInCutPlane.Count));
            s.AppendLine();
            foreach (Element e in ElemsInCutPlane)
            {
                s.AppendLine(string.Format("{0}  <{1}>   {2}", e.Name,e.Id,e.GetType()));
            }
            TaskDialog.Show("debug", s.ToString());
            //using (Transaction t = new Transaction(doc, "test"))
            //{
            //    t.Start();
            //    SketchPlane _plane = SketchPlane.Create(doc, new Plane(XYZ.BasisX, XYZ.Zero));
            //    doc.Create.NewModelCurve(Line.CreateBound(pt1, pt3), _plane);
            //    t.Commit();
            //}
Message 6 of 10
Anonymous
in reply to: desdinova

Hi desdlinova

It works for me. The only problem I have is the outline of the crop region. I'm not able to make it under control. 

Message 7 of 10
desdinova
in reply to: FAIR59

Thanks for replies

I wonder is it possible to use section bounding box for outline

I try

 

ViewSection viewSection = doc.GetElement(uidoc.Selection.PickObject(ObjectType.Element)) as ViewSection;
BoundingBoxXYZ bb = viewSection.get_BoundingBox(null);

XYZ pt1 = bb.Max;
XYZ pt2 =bb.Min;

Outline _outline = new Outline(pt1, pt2);
BoundingBoxIntersectsFilter CutPlaneFilter = new BoundingBoxIntersectsFilter(_outline);
List<Element> ElemsInCutPlane = new FilteredElementCollector(doc, doc.ActiveView.Id)
.WhereElementIsNotElementType()
.WhereElementIsViewIndependent()
.WherePasses(CutPlaneFilter)
.ToList<Element>();

 

but it returns null.

Thanks again.

Message 8 of 10
FAIR59
in reply to: desdinova

It might work, but you'd have to project the 3D bounderies unto the cutPlane, while remembering / realising that BounderyBox.Min and Max are coordinates local to the bounderybox.  Furthermore I suspect that an Outline needs at least 3 points.

 

I have a solution following a different path, using the CropRegionShapeManager of the view.

 

    public class Cmd_SelectElemsInCutPlane : IExternalCommand
    {

        public Autodesk.Revit.UI.Result Execute(ExternalCommandData revit,
        ref string message, ElementSet elements)
        {
            Document doc = revit.Application.ActiveUIDocument.Document;
            Autodesk.Revit.DB.View ActView = doc.ActiveView;

            List<CurveLoop>  _crop = ActView.GetCropRegionShapeManager().GetCropShape().ToList<CurveLoop>();
            CurveLoop cvLoop = _crop.First();
            List<XYZ> _cropPoints = new List<XYZ>();
            foreach( Curve cv in cvLoop)
            {
                if (cv is Line)
                {
                    _cropPoints.Add(cv.GetEndPoint(0));
                }
                else
                {
                    // redundant all curves in crop region are straight lines
                    List<XYZ> temp = cv.Tessellate().ToList<XYZ>();
                    temp.RemoveAt(temp.Count - 1);
                    _cropPoints.AddRange(temp );
                }
            }
            if (_cropPoints.Count < 3) return Result.Failed;
            Outline _outline = new Outline(_cropPoints[0], _cropPoints[1]);
            for (int i = 2; i < _cropPoints.Count; i++)
            {
                _outline.AddPoint(_cropPoints[i]);
            }
// if you need a bigger region just scale 
//            _outline.Scale(100);

            BoundingBoxIntersectsFilter CutPlaneFilter = new BoundingBoxIntersectsFilter(_outline);
// simplefy the result using OfClass or OfCategory
            List<Element> ElemsInCutPlane =
                   new FilteredElementCollector(doc, doc.ActiveView.Id)
                            .WhereElementIsNotElementType()
                            .WhereElementIsViewIndependent()
                            .WherePasses(CutPlaneFilter)
                            .ToList<Element>();
            List<ElementId> IdsInCutPlane = new List<ElementId>();
            foreach (Element e in ElemsInCutPlane)
            {
// "postprocessing" here if needed 
                IdsInCutPlane.Add(e.Id);
            }
            revit.Application.ActiveUIDocument.Selection.SetElementIds ( IdsInCutPlane);
            return Result.Succeeded;
        }
    }

  

 

Message 9 of 10
desdinova
in reply to: FAIR59

Thanks FAIR59;

It works like a charm....

Message 10 of 10
glenncai
in reply to: FAIR59

FAIR59

Sorry for the late reply guys. It is hard to squeeze time when deadline is approaching. The solution that you provided is awesome. but for me I just have to modify it a little bit since I'm using Macro for testing. and It looks like List<CurveLoop> not working in Revit 2015. but is fine on company's Revit 2016. Thanks for your help. 

 

   

		public void SelectCutElement()
		{
			Document doc = this.ActiveUIDocument.Document;
			UIDocument uidoc = this.ActiveUIDocument;
			Autodesk.Revit.DB.View ActView = doc.ActiveView;

			List<CurveLoop>  _crop = ActView.GetCropRegionShapeManager().GetCropShape().ToList<CurveLoop>();
			CurveLoop cvLoop = _crop.First();
			List<XYZ> _cropPoints = new List<XYZ>();
			foreach( Curve cv in cvLoop)
			{
				if (cv is Line)
				{
					_cropPoints.Add(cv.GetEndPoint(0));
				}
				else
				{
					// redundant all curves in crop region are straight lines
					List<XYZ> temp = cv.Tessellate().ToList<XYZ>();
					temp.RemoveAt(temp.Count - 1);
					_cropPoints.AddRange(temp );
				}
			}
			
			string info = "";
			if (_cropPoints.Count > 3)
			{
				Outline _outline = new Outline(_cropPoints[0], _cropPoints[1]);
				
				for (int i = 2; i < _cropPoints.Count; i++)
				{
					_outline.AddPoint(_cropPoints[i]);
				}
				// if you need a bigger region just scale
				//            _outline.Scale(100);

				BoundingBoxIntersectsFilter CutPlaneFilter = new BoundingBoxIntersectsFilter(_outline);
				// simplefy the result using OfClass or OfCategory
				List<Element> ElemsInCutPlane =	new FilteredElementCollector(doc, doc.ActiveView.Id).WhereElementIsNotElementType().WhereElementIsViewIndependent().WherePasses(CutPlaneFilter).ToList<Element>();
				
				List<ElementId> IdsInCutPlane = new List<ElementId>();
				foreach (Element e in ElemsInCutPlane)
				{
					// "postprocessing" here if needed
					IdsInCutPlane.Add(e.Id);
					info += e.Name;
					info += Environment.NewLine;
				}

				uidoc.Selection.SetElementIds (IdsInCutPlane);
			}
			
			TaskDialog.Show("info",info);

		}

 

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

Post to forums  

Autodesk Design & Make Report