Count Inserted images with Revit API

Count Inserted images with Revit API

Anonymous
Not applicable
858 Views
4 Replies
Message 1 of 5

Count Inserted images with Revit API

Anonymous
Not applicable

I am trying to write a simple macro to count all inserted images in a project and return the count back to me, as well as the names and image types of each file.  I am relatively new to the Revit API and I am not entirely sure how to structure the script.  I've tried to run a foreach with a filteredElementCollect for  .OfClass(typeof(ImageView))  however, I do not believe that ImageView is the proper name of what I am looking for.  If anyone has any advice on this please let me know.  Thanks.

0 Likes
Accepted solutions (1)
859 Views
4 Replies
Replies (4)
Message 2 of 5

PhillipM
Advocate
Advocate

Try setting up your collector as this.

 

New FilteredElementCollector(app.ActiveUIDocument.Document).OfCategory(BuiltInCategory.OST_RasterImages)

 

Good luck.

 

Phillip

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks Phillip,

 

This is what I have compiled so far:

 

                public void findImports()
        {
            Document doc = this.ActiveUIDocument.Document;
            string info = "";
                
            foreach (Element e in new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_RasterImages))
            {
                BuiltInCategory.OST_RasterImages fi = e as BuiltInCategory.OST_RasterImages;
                info += fi.Name + Environment.NewLine;
            }
            TaskDialog.Show("elements",info);
        }

 

 

 

However, when I try to compile this I wind up with an error the for the line:

 

BuiltInCategory.OST_RasterImages fi = e as BuiltInCategory.OST_RasterImages;

 

the error being: 'Autodesk.Revit.DB.BuiltInCategory.OST_RasterImages' is a 'field' but is used like a 'type'

 

Any Idea what I might want to put in its place?

 

 

 

 

 

 

0 Likes
Message 4 of 5

PhillipM
Advocate
Advocate
Accepted solution

Try This

 

public void findImports()
        {
            Document doc = this.ActiveUIDocument.Document;
            string info = "";
           

FilteredElementCollector Col = new FilteredElementCollector(app.ActiveUIDocument.Document).OfCategory(BuiltInCategory.OST_RasterImages);

     
            foreach (Element e in Col)
            {
                              info += e.Name + Environment.NewLine;
            }
            TaskDialog.Show("elements",info);
        }

 

 

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks! This works great, I guess I was over complicating it a bit with mine.

0 Likes