Greetings from Revit Technology Conference NA in beautiful Vancouver! This is my first trip to RTC and it is great! Yesterday I gave a presentation titled “Raise the IQ of Your Revit model with the API” and then a fun and wide-ranging late-night API Q&A session with 20+ people.
Here’s a good question that I was asked this morning…
Q. Is it possible to change the transparency of a category in a view in API? Basically the visibility/graphics dialog?
A. Yes, this is a new addition in the 2014 API. Below is a code sample and screenshot showing the result of this macro.
From the “2014 What’s New”:
Category override
Display of categories can be overridden. This can be done with the new class OverrideGraphicSettings and the new View methods:
- SetCategoryOverrides
- GetCategoryOverrides
- IsOverrideValidForCategory
- IsCategoryOverridable
public void setCatVis()
{
UIDocument uidoc = this.ActiveUIDocument;
Document doc = uidoc.Document;
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
ogs.SetSurfaceTransparency(50);
Category wallCat = doc.Settings.Categories.get_Item("Walls");
using (Transaction t = new Transaction(doc,"Set Overrides"))
{
t.Start();
doc.ActiveView.SetCategoryOverrides(wallCat.Id,ogs);
t.Commit();
}
}
This is great! It inspires me to create a UI with check boxes for categories and a slider to control view graphics dynamically before applying.
can this be done per instance or element?
I am trying to list only categories that have overrides (as a way to do some quality control on projects) but am not seeing any way to test this in the API. I loop through views and test to see if it is a template. If it is, I then want to see what categories (just for architectural model) have overrides here is what I am doing:
foreach (Autodesk.Revit.DB.View v in views)
{
string line = “”;
if (v.IsTemplate)
{
line += v.Name;
line += “\t”;
line += v.Scale.ToString();
line += “\t”;
line += v.ViewType.ToString();
foreach (Category c in cCats)
{
if(c.get_AllowsVisibilityControl(v))
{
OverrideGraphicSettings ogs = v.GetCategoryOverrides(c.Id);
line += “\t”;
line += c.Name;
line += “\t”;
line += ogs.CutFillColor.ToString();
}
}
sw.WriteLine(line);
}
}
sw.Close();
where sw is a StreamWriter declared previously, and cCats is doc.Settings.Categories. I was hoping for something like IsOverridden . . . what can I do?
Hi Paul,
Did you try View..::..GetCategoryOverrides Method?
Yes . . . in fact that is what I have, and perhaps it is working as intended but I seem to get the same categories for every view template (which seems unlikely) but perhaps it is correct. But I was hoping to be able to constrict it to only the Architectural model categories. I’ll keep working at it and thanks for your quick reply. Cheers!
Paul
Just a guess, but maybe Revit is doing something strange with the view templates. What happens if you try with a non-template view?