PickElementsByRectangle

PickElementsByRectangle

MONTECINOS
Advocate Advocate
824 Views
9 Replies
Message 1 of 10

PickElementsByRectangle

MONTECINOS
Advocate
Advocate

Good morning,

 

My name is Nicolás,

 

This is a code that i found in internet, this code is made in C# for selecting elements and get information of them, i modified a line of code to make this macro let me get information of pipes, but it doesn´t work, and don´t know why:

 

public void SeElInformation()
        {
    
                UIDocument uidoc = this.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            
            var informacion = "Los ids y los nombres de los elementos son : \n\n";
                           
            var referencias =uidoc.Selection.PickElementsByRectangle(ElementTypeGroup.PipeType);

           foreach(var REF in referencias)
            {
               Element elem = uidoc.Document.GetElement(REF); 
               informacion += elem.Id + "," +elem.Name + "\n";
               informacion += elem.Document.SiteLocation.Latitude + "," +elem.Name + "\n";
 
                   informacion += elem.Category.Material.MaterialClass;
                   informacion += elem.Parameters.Size;      
            }
                      
            TaskDialog.Show("informacion elemento" , informacion);

 

 

I attached 3 screenshots to explain detailed my problem.

I would like anybody could help me,

Thanks.

0 Likes
825 Views
9 Replies
Replies (9)
Message 2 of 10

RPTHOMAS108
Mentor
Mentor

The method UIDocument.Selection.PickElementsByRectangle takes an ISelectionFilter not a value from ElementTypeGroup

 

If the object is a Pipe/DirectShape/FabricationPart then it is still an Element so the original code with PickObject(ObjectType.Element) should work, ISelectionFilter can be implemented to limit selection to pipes or other specific things (see ISelectionFilter).

 

The line Element.Document.SiteLocation.Latitude is not for the purpose you are using it for i.e. Document is the Document that the pipe resides in and therefore SiteLocation holds no information specific to the pipe.

 

If it isn't a pipe then you'll have to use RevitLookup to determine what if anything you can use for it in terms of location. To get pipe location you need to use Pipe.Location this will usually return a LocationCurve object then LocationCurve.Curve.GetEndPoint will return each end by end index. This will be in relation to the internal co-ordinate system so needs to be transformed to the coordinate system of the site. 

0 Likes
Message 3 of 10

MONTECINOS
Advocate
Advocate

Good morning RPTHPOMAS108,

 

Thank you for taking time to answer my doubts.

 

So far, the only way i know to get access to any method or property of fabrication parts or plumbing to search into is;

 

PLUMBING

Autodesk.Revit.DB.Plumbing.PipeSystemType.OtherPipe();

 

FABRICATION PART

 Autodesk.Revit.DB.Fabrication.FabricationUtils();

(For example, this method allows me to export fabrication pipes to PFC)

 

 

If i try to dive into those two method i can´t to put any foreach(), macro sends me an alert.

 

How is the process to use correctly the line you told me previously: 

 

Pipe/DirectShape/FabricationPart.

 

 

Thanks again

 

 

 

 

 

0 Likes
Message 4 of 10

RPTHOMAS108
Mentor
Mentor

If you attach a project file containing a single object of what you are trying to select and get information from then I may be able to advise. Currently I'm unsure what objects you are working with and for certain objects without location information there with be no convenient way to obtain it, other than looking at solid geometry etc.

0 Likes
Message 5 of 10

jeremy_tammik
Alumni
Alumni

Welcome to the Revit API.

 

The most efficient way for you to resolve this question and many others besides would be for you to work through the getting started material, especially the DevTV and My First Revit Plugin tutorials:

 

 

That would resolve this issue, and many others as well that you may run into very soon.

 

However, to address your question directly:

 

You are using the PickElementsByRectangle method, and that makes perfect sense.

 

It does not take an argument of type ElementTypeGroup, so you cannot use it in the way you do.

 

PickElementsByRectangle has several overloads taking different sets of arguments:

 

 

pickelementsbyrectangle_overloads.png

   

You could use the overload taking a selection filter.

 

For that, you can implement a selection filter that accepts only pipe types:

  

  /// <summary>
  /// Allow selection of pipe elements only.
  /// </summary>
  class PipeSelectionFilter : ISelectionFilter
  {
    public bool AllowElement( Element e )
    {
      return e is Pipe;
    }
 
    public bool AllowReference( Reference r, XYZ p )
    {
      return true;
    }
  }

  

You can use it in PickElementsByRectangle like this:

  

  Reference r = sel.PickElementsByRectangle(
    new PipeSelectionFilter(),
    "Please select pipes." );

  

Good luck and have fun,

 

Jeremy

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 6 of 10

MONTECINOS
Advocate
Advocate

Good morning RPTHOMAS108,

 

Thanks again for helping me.

 

Firstable, i´m going to solve howt to get information such a diameter, material by clicking an elbow or a piece of pipe.

About getting information of location of those elements, i´m gonna leave it for later.

 

Once again, thank you

0 Likes
Message 7 of 10

MONTECINOS
Advocate
Advocate

Good morning jeremy.tammik,

 

Thanks for answer my question.

 

I´m going to take a look to the link what you sent me, to see the API tutorial. I´m new on coding with API of Revit, there is a lot of things that i don´t know about.

 

I´m going to try to implement the solution that you have proposed me.

Probably i´m going to write back later, because the more keep writing code, the more doubts are going to appear.

 

Once again thank you

0 Likes
Message 8 of 10

MONTECINOS
Advocate
Advocate

Hi jeremy.tammik,

 

Sorry for bother again.

I added the example code that you previously gave me into my code, but something is going wrong, and i don´t know exactly how to fix it.

 

I woul appreciate if you could help me,

 

Thanks.

 

0 Likes
Message 9 of 10

jeremy_tammik
Alumni
Alumni

From your screen snapshots, you seem to be working in the Revit macro editor IDE.

 

That is good. The code I shared was taken from an add-in, not a macro, so there may be slight differences.

 

They are trivial, and have to do with how you access the Revit application and active document.

 

I would suggest that the best next step for you is to dive a little bit deeper into macro programming fundamentals, and maybe a little bit of .NET and C# programming fundamentals, e.g., by working through a tutorial or two.

 

Search for Revit macro and C# .NET programming tutorials on YouTube or elsewhere in your preferred platforms, get you feet wet with things that DO work, and then you will be ready to tackle your own main task.

  

Don't struggle with things that don't work. Just follow a couple of tutorials that show the proper way of doing things and rapidly all will become clear.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 10 of 10

MONTECINOS
Advocate
Advocate

Ok, thanks

0 Likes