Turning Off Imported Categories with the exception for the Imports in Families

Turning Off Imported Categories with the exception for the Imports in Families

jagostinho74
Collaborator Collaborator
243 Views
2 Replies
Message 1 of 3

Turning Off Imported Categories with the exception for the Imports in Families

jagostinho74
Collaborator
Collaborator

Hello,

 

How can I set a view (that is not using a View Template) so that its Imported Categories are all turned off with the exception for the Imports in Families? See image below as an example. Views could hold several different imported categories.

 

I know I can use "AreImportCategoriesHidden = false;" to turn them all off in the main box using the Views' properties but having problems finding what to use to do this selectively.

 

Thanks in advance for your help

 

jagostinhoCT_0-1700499231697.png

 

Assistant BIM/CAD Manager

Manchester, UK


0 Likes
Accepted solutions (1)
244 Views
2 Replies
Replies (2)
Message 2 of 3

GaryOrrMBI
Collaborator
Collaborator
Accepted solution
Each drawing file is treated as it's own model category with each layer therein being treated as a sub-category.

so approach it that way: view.SetCategoryHidden(DrawingElementId)
Gary J. Orr
GaryOrrMBI (MBI Companies 2014-Current)
aka (past user names):
Gary_J_Orr (GOMO Stuff 2008-2014);
OrrG (Forum Studio 2005-2008);
Gary J. Orr (LHB Inc 2002-2005);
Orr, Gary J. (Gossen Livingston 1997-2002)
Message 3 of 3

jagostinho74
Collaborator
Collaborator

Thank you very much for your reply.

 

The challenge was on finding the correct BuiltInCategory, which we were able to find by listing the hidden categories for a test view and retrieving their enum info.

 

The code below successfully sets the Imports in Families visibility for a given list of view names.

private void SetImportsInFamilies(Dictionary<string, List<string>> viewNames, bool flag)
		{
			// Get the current document
			Document doc = this.ActiveUIDocument.Document;

			// Start a transaction
			using (Transaction t = new Transaction(doc, "Control View Categories"))
			{
				t.Start();
				
				// Iterate through the views in the first dictionary
				foreach (string viewName in viewNames.Keys)
				{
					// Get the view by name
					View view = GetViewByName(doc, viewName);

					if (view != null)
					{
						// Turn on Imports in Families category
						view.SetCategoryHidden(new ElementId(BuiltInCategory.OST_ImportObjectStyles), flag);
					}
				}
				t.Commit();
			}
		}

 

Assistant BIM/CAD Manager

Manchester, UK


0 Likes