Author Topic: Revit Selection  (Read 2809 times)

0 Members and 1 Guest are viewing this topic.

MexicanCustard

  • Swamp Rat
  • Posts: 705
Revit Selection
« on: February 25, 2016, 04:04:23 PM »
Disclaimer, we've just started using Revit.  In MEP we divide the floor up into areas for our spool drawings.  So in Revit I'm trying to use Areas for this same division.

Firstly,  how can I get all the elements within an Area?  Since Area isn't a parameter on elements I'm assuming there isn't a way to use a FilteredElementCollector.

Secondly, is there a better way to divide a drawing up into "Areas" and then query all the pipe, pipe fittings, and pipe accessories?
Revit 2019, AMEP 2019 64bit Win 10

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Revit Selection
« Reply #1 on: February 27, 2016, 10:04:37 AM »
Not sure if this will help but couldn't you set a property on the pipe itself that reads the area name and then just select the pipe that has the correct area name?  I have done zero programming in Revit but that is how I do it in AutoCAD MEP.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Revit Selection
« Reply #2 on: February 27, 2016, 05:32:16 PM »
Cough Cough *Revit Sucks* Cough Cough.
Excuse me.

MEP uses spaces but I backed of Revit because for some reason where I work they give Revit jobs to people with no experience and end up with nightmare(wonder why), and they try to avoid it now.

I could go back and check but each element has parameters which ends up really just being like dynamic object where you can properties that are just a dictionary of name and value. If you snoop can you find area property in parameter dictionary?


 

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Revit Selection
« Reply #3 on: February 27, 2016, 05:37:32 PM »
The right side of form shows parameters of element.
https://www.theswamp.org/index.php?topic=49784.msg549527#msg549527

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Revit Selection
« Reply #4 on: February 29, 2016, 08:10:06 AM »
If you snoop can you find area property in parameter dictionary?

No, and I don't have enough Revit experience to know if and how to add a parameter that would automatically pick up the area.  I'll dig into that.

I did start making progress letting the user pick an Area then using BoundingBoxInsideFilter to grab FamilyInstances inside the bounding box.  Just have to figure out how to filter out everything but the family I want.  Starting with OmniClass we'll see how far that gets me.

Here's some of my experimental code.
Code - C#: [Select]
  1. public Result Execute(
  2.           ExternalCommandData commandData,
  3.           ref string message,
  4.           ElementSet elements)
  5.         {
  6.             var uiapp = commandData.Application;
  7.             var uidoc = uiapp.ActiveUIDocument;
  8.             var app = uiapp.Application;
  9.             var doc = uidoc.Document;
  10.  
  11.             var r = uidoc.Selection.PickObject(ObjectType.Element,"Select Area: ");
  12.  
  13.             var element = doc.GetElement(r.ElementId);
  14.  
  15.             var bbox = element.get_BoundingBox(doc.ActiveView);
  16.             var outline = new Outline(bbox.Min, bbox.Max);
  17.             var bbFilter = new BoundingBoxIsInsideFilter(outline);
  18.  
  19.             var pvp = new ParameterValueProvider(new ElementId((int)BuiltInParameter.OMNICLASS_CODE));
  20.  
  21.             var collector = new FilteredElementCollector(doc, doc.ActiveView.Id)
  22.             .OfClass(typeof (FamilyInstance))
  23.             .OfCategory(BuiltInCategory.OST_PipeAccessory)
  24.             .WherePasses(bbFilter);
  25.  
  26.             foreach (var e in collector)
  27.             {
  28.                 var parameters = e.Parameters;
  29.             }
  30.  
  31.             return Result.Succeeded;
  32.         }
Revit 2019, AMEP 2019 64bit Win 10

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Revit Selection
« Reply #5 on: February 29, 2016, 08:39:32 AM »
This course is expensive but I believe it is by one of the guys at Autodesk that works on the Revit API.  Maybe you can get your company to pay for it.


https://www.udemy.com/revitapi/


This is is Revit API blog.


https://boostyourbim.wordpress.com/
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

Jeff H

  • Needs a day job
  • Posts: 6150
Re: Revit Selection
« Reply #6 on: February 29, 2016, 09:22:16 AM »
can u load a sample model to see and maybe find a way

khoa

  • Guest
Re: Revit Selection
« Reply #7 on: February 29, 2016, 11:41:28 AM »
Revit supports to get elements inside a document or a view, so we need to calculate to get elements inside a region (Area).

Inside the loop of the collector, get each element then its bounding box. Then compare the bounding box of this element to be inside the area bounding box:
outline.Min < elementBox.Min && outline.Max > elementBox.Max
« Last Edit: February 29, 2016, 12:09:32 PM by Khoa Ho »

Keith Brown

  • Swamp Rat
  • Posts: 601
Re: Revit Selection
« Reply #8 on: February 29, 2016, 11:48:41 AM »
Excellent idea Khoa.  You will just have to take into account the special cases when the piping spans more than one area which probably happens quite a bit.
Keith Brown | AutoCAD MEP Blog | RSS Feed
AutoCAD MEP 2014 / Revit MEP 2014 / EastCoast CAD/CAM addon / Visual Studio 2013

khoa

  • Guest
Re: Revit Selection
« Reply #9 on: February 29, 2016, 12:08:17 PM »
The spanning elements which run across the region boundary will have their bounding boxes to overlap with the region (Area) outline. We will need to count them with the special case depending how we want to deal with them.

Here is the revised code:
Code: [Select]
if (outline.Min < elementBox.Min || outline.Max > elementBox.Max)
{
// Element inside the outline
if (outline.Min < elementBox.Min && outline.Max > elementBox.Max)
{

}
else // Element crosses the outline
{

}
}

MexicanCustard

  • Swamp Rat
  • Posts: 705
Re: Revit Selection
« Reply #10 on: February 29, 2016, 03:21:23 PM »
Revit supports to get elements inside a document or a view, so we need to calculate to get elements inside a region (Area).

Inside the loop of the collector, get each element then its bounding box. Then compare the bounding box of this element to be inside the area bounding box:
outline.Min < elementBox.Min && outline.Max > elementBox.Max


Revit has a built in filter for this, BoundingBoxIsInsideFilter.  You can see my use of it in the code I posted.  I was just wanting to know if there was a quicker way.  Like adding an Area parameter to the family that automatically populates.  Where piping spans more than one Area we're okay with just taking the first one it finds.

Keith, thanks for the links.  I knew of the blog and I've been browsing through old post on there and Jeremy's blog.  Sucks to feel so proficient with AutoCAD and AutoCAD MEP APIs then have to switch to Revit.  At least the Revit API documentation is 10 times better than AutoCAD's.
Revit 2019, AMEP 2019 64bit Win 10

khoa

  • Guest
Re: Revit Selection
« Reply #11 on: February 29, 2016, 04:14:20 PM »
I think you are good to use the native Revit API that is better than extra calculation to find elements inside a bounding box. See the Revit help:
http://revitapisearch.com/html/eb8735d7-28fc-379d-9de9-1e02326851f5.htm

Bobby C. Jones

  • Swamp Rat
  • Posts: 516
  • Cry havoc and let loose the dogs of war.
Re: Revit Selection
« Reply #12 on: May 03, 2016, 10:35:03 AM »
Sorry to dredge up an old post, but did you find an acceptable solution?  Have you looked at using Room elements?  Most families have a Room parameter that auto-populates.
Bobby C. Jones