Purge Unused Images

Purge Unused Images

SONA-ARCHITECTURE
Advocate Advocate
1,861 Views
9 Replies
Message 1 of 10

Purge Unused Images

SONA-ARCHITECTURE
Advocate
Advocate

Hi,

I can't correctly purge unsed images.

I'd like to got the same result as the tool called "Manage Images"

 

When I want to purge, for example  : TextNotes, I can use this method (founded in BuildingCoder thx) :

I collect all TextNotes type

I collect all TextNote instances, and for each instance I remove the ID of the Type in my Collection of TextNotes Type.

 

FilteredElementCollector collector = new FilteredElementCollector(BIM_Extracteur._doc);
//all textNotesTypes
ICollection<ElementId> textNotesTypes = collector.OfClass(typeof(TextNoteType)).ToElementIds().ToList();
			
//all TextNotes Instances
FilteredElementCollector textNotes = new FilteredElementCollector(BIM_Extracteur._doc).OfClass(typeof(TextNote));
 			
foreach( TextNote textNote in textNotes )
{
bool removed = textNotesTypes.Remove(textNote.TextNoteType.Id);
}

But, with Images, it is more difficult and strange look :

 

For imagesType, it works fine  :the command is  :

ICollection<ElementId> ImagesTypes = collector.OfClass(typeof(ImageType)).ToElementIds().ToList();

But, for Images Instance, there is no Image type because image instance is typeof Element.

If I use this :

FilteredElementCollector ImagesCollector = new FilteredElementCollector(BIM_Extracteur._doc);
ElementCategoryFilter filter = new ElementCategoryFilter(BuiltInCategory.OST_RasterImages);	
ICollection<Element> images= collector.WherePasses(filter).ToElements();

The result is ImageType only

and when I use this :

ICollection<Element> images = new FilteredElementCollector(BIM_Extracteur._doc).OfCategory(BuiltInCategory.OST_RasterImages).ToElements();

Result is ImageType and Element for OST_RasterImage why?

 

And, if I got an image also used in Image parameter of my objets, that mean, I have to make a new filter to get all elements in all categories where image parameter containing my ImageType id?

 

Not sure to be very clear......sorry

 

 

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
0 Likes
1,862 Views
9 Replies
Replies (9)
Message 2 of 10

Yien_Chao
Advisor
Advisor

Pierre,

 

for image instance did you try to add the filter : .WhereElementIsNotElementType() ?

 

that will catch only the instances.

 

hope it will help

0 Likes
Message 3 of 10

jeremytammik
Autodesk
Autodesk

Thank you, Yien, for the very relevant hint.

 

Just what I also wanted to suggest.

 

The Building Coder has discussed a number of aspects of purging different group of elements.

 

A summary is provided here:

 

 

Two more discussions have been added since then:

 

 

I really should summarise these all in an own dedicated topic group.

 

Since then, yet a few more related discussion include:

 

 
Oliver Green ported the VB code using the performance advisor to IronPython in case anyone fancies a copy:

 

  

Mike Turpin @ThatBIMthing added:

 
Got excited when i saw your post that there was a new solution then realised it was what i was already using 😁. I used this in my purge node in “turtle” dynamo package.

 

Best regards,

 

Jeremy

 

 


Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 4 of 10

SONA-ARCHITECTURE
Advocate
Advocate

Hi

Thx Jeremy for all those links.

Thx Yien

 

So, I can get all Image Instances.

ICollection<Element> images = new FilteredElementCollector(BIM_Extracteur._doc).
WhereElementIsNotElementType().
OfCategory(BuiltInCategory.OST_RasterImages).ToElements();

I'm asking how Revit do for getting this kind ok list ?

'Cose I've got Generic models with Image property type added in those object.

I assume I have to use filter for all elements wich have an Image type parameter....

 

screenshot_291.png

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
0 Likes
Message 5 of 10

SONA-ARCHITECTURE
Advocate
Advocate

I thought make a Document.Delete and counting elements deleted in a ICollection<Autodesk.Revit.DB.ElementId> deletedIdSet but no way...

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
0 Likes
Message 6 of 10

jeremytammik
Autodesk
Autodesk

Dear Pierre,

 

I do not understand exactly what you are trying to achieve, nor what problems you are encountering.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 7 of 10

SONA-ARCHITECTURE
Advocate
Advocate

Jeremy

 

Sorry Jeremy for not being clear enough ..

In fact, I would like to know if an image is not used (as an image stuck on a view or as an image assigned to a parameter I hope it's clearer now.

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
0 Likes
Message 8 of 10

jeremytammik
Autodesk
Autodesk

Yes, that much is clear.

 

A number of different approaches and attempts to resolve very similar questions have been presented and discussed in the links listed above.

 

I am not clear on which of those you have tested, why they fail for you, and if so, how.

 

It might clarify things if you share a minimal reproducible case:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 9 of 10

SONA-ARCHITECTURE
Advocate
Advocate

Thx Jeremy

I'm going to explorer solutions and I'll give you a feedback.

Many thanks for your disponibility

Pierre NAVARRA
SONA-Architecture.
http://www.sona-architecture.com
https://fr.linkedin.com/in/pierre-navarra-62032a107
0 Likes
Message 10 of 10

scott.deascentis
Observer
Observer

I'm so curious... what are you doing in this screenshot?  I love legos!

0 Likes