Rod Howarth raised a question in the discussion on linked files:
Question: I'm trying to make a command to turn off the visibility of linked Revit and DWG models in the current view.
The intent is to turn off the visibility for all imported categories in the drawing, i.e. all imported CAD files. This would be like going to Visibility/Graphics > Imported Categories > Show imported categories in this view.
Is there an easy way to do this, or am I going to have to loop over each element, checking if its symbol's name ends in '.dwg' or '.rvt' or is there a certain thing I can look for, i.e. something that tells me it is an imported category, instead of just going by the name?
For DWG, I simply loop through the document settings categories and make each category whose name ends with ".dwg" invisible in the current view.
However, this does not work for RVT, so I had a look with RvtMgdDbg, and it says that my linked file on the plan is part of the OST_RvtLinks built-in category.
So I changed my code to do:
Document doc = app.ActiveDocument; Categories categories = doc.Settings.Categories; // get category for linked files Category linkedRevitCat = categories.get_Item( BuiltInCategory.OST_RvtLinks ); // loop through all categories in document foreach( Category c in categories ) { // if they end with dwg or rvt toggle // their current visibility in current view if( c.Name.ToLower().EndsWith( ".dwg" ) || c.Name.ToLower().Contains( ".rvt" ) || c.Name.ToLower().EndsWith( ".dwf" ) || c.Name.ToLower().EndsWith( ".dxf" ) || c.Name.ToLower().EndsWith( ".dwfx" ) || ( linkedRevitCat != null && c.Id.Equals( linkedRevitCat.Id ) ) ) { // toggle visibility doc.ActiveView.setVisibility( c, !c.get_Visible( doc.ActiveView ) ); } }
Unfortunately, linkedRevitCat always is null, and when I run the elements filter API sample, OST_RvtLinks doesn't come up as a category list?
Answer: First of all, thank you Rod for raising this interesting question and for pointing out the positive information on how simple it is to hide the linked DWG files.
Joe Ye discovered the following built-in category behaviour: There is no easy way to filter out those imported categories quickly. I found one hint that can make your add-in quicker, though:
- For the built-in categories, the element id is always negative.
- For imported ones, which are created after the DWG is imported, the element id is positive.
Using this rule, it is no longer necessary to extract the substring and perform a string comparison for built-in categories.
Phil Xia responded to the question on the OST_RvtLinks built-in category: indeed we cannot retrieve the OST_RvtLinks built-in category from the document settings categories. We can get it from the element category property, however:
BuiltInCategory bic = BuiltInCategory.OST_RvtLinks; ElementIterator i = doc.Elements; Element e; while( i.MoveNext() ) { e = i.Current as Element; if( e.Name.Contains( ".rvt" ) && e.Category != null && e.Category.Id.Value.Equals( (int) bic ) ) { break; } }
Unfortunately, since we cannot obtain the document category for the RVT link element, it is not possible to hide this category via the View.SetVisibility method like we do for the DWG link element. Also, unlike the DWG link elements, all the RVT ones return the same category OST_RvtLinks, so we cannot control the visibility for them individually using this method, even if we were able to obtain the appropriate document category.
I hope these various hints are of some use and will be interested in hearing whether they help resolve your issue, Rod.
Thanks alot Jeremy,
Using an iteration over the elements to find the .rvt one, and then using the category of that in View.SetVisibility works wonders.
Thanks once again for your help and another informative post.
Posted by: Rod Howarth | January 18, 2009 at 05:57
Hi Rod,
Great, I am so glad it worked, congratulations!
Cheers, Jeremy
Posted by: Jeremy Tammik | January 18, 2009 at 08:16
Is there any way in the Revit API to modify a view's annotation visibility wholesale? I know that you can toggle the visibility of individual categories for a view, but is there a way to duplicate the "Show annotated categories in this view" functionality outside of the UI?
Posted by: Justin | August 13, 2009 at 16:46
Dear Justin,
There is currently no such API function to show or hide all annotated categories in a given view. You might collect all the categories that you consider to be annotative and toggle their visibility individually. Unfortunately, there is no API method to indicate whether a given category is of annotation or model type either.
Cheers, Jeremy.
Posted by: Jeremy Tammik | August 14, 2009 at 03:10
Hi Jeremy is there a api function now on 2015 to show or hide the Imported Categories in a view through the Api?
Thank you.
Posted by: Fm2 | June 04, 2014 at 19:04
Dear Fm2,
I don't really know exactly what you mean by 'imported categories'.
Do you mean categories that are generated by importing a DWG file, for example?
Is this something you can do in the user interface?
In any case, it sounds as if it should be pretty simple, since you have various methods on the View class to hide and isolate elements and categories. Therefore, if you can identify the categories you wish to hide, it should be possible to call the hide method on them as well.
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 04, 2014 at 20:01
Thank Jeremy for your reply and your blog :)
yes i can do it using the visibility/Graphic overrides dialog.
using above example to check/uncheck the visibility on every dwg file. but if the "Show Imported Categories in this view" box is uncheck it will not be visible on the view.
but i cant find a way to check "Show Imported Categories in this view" check box using api.
Thanks
Posted by: Fm2 | June 05, 2014 at 09:33
I'm having the same problem there is a read only Boolean value "AreImportCategoriesHidden" in the View class so I can see if a user has un-checked the "Show Imported Categories in this view" box however there doesn't seem to be any way around it.
If anyone can see something I've missed it would be great.
Thanks
Posted by: James Hicks | June 18, 2014 at 07:13
Just answered my own question, the "AreImportCategoriesHidden" value is now settable in 2015 which solves this problem.
Posted by: James Hicks | June 18, 2014 at 07:46
Dear James,
Cool. Congratulations.
Thank you for letting us know!
Cheers, Jeremy.
Posted by: Jeremy Tammik | June 22, 2014 at 15:54