@marcellosgamb suggested an API that runs thru every error in a model turns element w/error red then as u fix each error turn normal
There is no API access to the Revit “Review Warnings” data, so this implementation requires the user to export the warning data. The program then imports this HTML, parses it to find the element IDs, and then isolates and colors the elements in two 3D views.
public void ShowWarningElements()
{
Document doc = this.ActiveUIDocument.Document;
string filename = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "warnings.html");
IList<ElementId> ids = new List<ElementId>();
using (StreamReader sr = new StreamReader(filename))
{
string line = "";
while ((line = sr.ReadLine()) != null)
{
string[] row = System.Text.RegularExpressions.Regex.Split(line,"id ");
if (row.Length != 3)
{
continue;
}
string id1 = row[1].Split(' ')[0];
string id2 = row[2].Split(' ')[0];
ids.Add(new ElementId(int.Parse(id1)));
ids.Add(new ElementId(int.Parse(id2)));
}
}
View isolateView = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>().Where(q => q.Name == "IsolateWarningElements").FirstOrDefault();
View overrideView = new FilteredElementCollector(doc).OfClass(typeof(View)).Cast<View>().Where(q => q.Name == "OverrideWarningElements").FirstOrDefault();
OverrideGraphicSettings ogs = new OverrideGraphicSettings();
Color red = new Color(255, 0, 0);
ogs.SetProjectionLineColor(red);
ogs.SetProjectionLineWeight(8);
Element solidFill = new FilteredElementCollector(doc).OfClass(typeof(FillPatternElement)).Where(q => q.Name.Contains("Solid")).First();
ogs.SetProjectionFillPatternId(solidFill.Id);
ogs.SetProjectionFillColor(new Color(0, 255,0));
using (Transaction t = new Transaction(doc, "Isolate/Override Warnings"))
{
t.Start();
isolateView.IsolateElementsTemporary(ids);
foreach (ElementId id in ids)
{
overrideView.SetElementOverrides(id, ogs);
}
t.Commit();
}
}
A nice solution Harry. Its easy to get so focused on what the API can or can’t do that we forget about going out the door and coming back in another. I do hope that someone in the API group monitors these feeds and is making a list…
– Brian –
Very handy, thank you. Is there no way to export the error report auto-magically? Can the Warnings dialog not be driven by the API? Keep up the good work. Dale
Is it possible to export through the API with the method outlined in this discussion on the Revit forum?
http://forums.autodesk.com/t5/Autodesk-Revit-API/Accessing-Warning-List/td-p/3925178
Interesting idea, but Revit seems pretty unhappy after I try to post this command.
public void postCommand()
{
Application app = this.Application;
UIApplication uiapp = new UIApplication(app);
uiapp.PostCommand(RevitCommandId.LookupCommandId(“ID_REVIEW_WARNINGS”));
}
Big newbie to API’s…..
When creating the new API in C++ or whatever language that is.. All I need to do is post that code in?
Hi,
These macros are written in C#, and this post might help explain how to use this code.
This is great Harry. Would it be possible to create something similar for interference check? Any tips you can give for that would be much appreciated.
Hi Andrew,
Sure, the same approach could be used with exported data from an Interference Report. The HTML parsing would be different to account for the formatting that Revit provides. I’d be happy to discuss it more with you via boostyourbim.wordpress.com/contact if you’d like.
Regards
Harry
hmmm i have troubles getting this here..
“sequence contains no elements system.core
at
system.linq.enumerable.first (sources)(IEnumsources)
at
ARCHISOFT_warnings.Warnings.showwarnings…
can you help me?
have you stepped through the code to see what line gives the error?
i got this message :
Erreur CS1061: ‘ee.ThisDocument’ ne contient pas une définition pour ‘ActiveUIDocument’ et aucune méthode d’extension ‘ActiveUIDocument’ acceptant un premier argument de type ‘ee.ThisDocument’ n’a été trouvée (une directive using ou une référence d’assembly est-elle manquante ?)
Construction échouée. (00:00:00.4606258)
My French isn’t so good, but did you make a Document macro instead of an Application macro? All the sample code that I post is for Application macros.
It’s a project macro not a application.
ok i did with Application macros .. then this message appears :
a problem has bees dectected.
system.invalidoperationexception:sequence contains no elements at macromodule.executemacro_(macromodule*, Astring*)
at
uimacrogeneralmanager.runmacro(uimacrogeneralmanager*,
Macromodule* pmodule, astring* macroname)
Step through the macro to see what line gives that error