The contents has been relocated. Please visit below blog:
https://hojoongchung.blogspot.com/2020/02/revit-api-issue-spheres-generator.html
Tag: clash management
Issue spheres creation with Revit macro
My current work place uses Dynamo to generate issue spheres to visualize clash location. However, it requires a lot of user’s effort, from installing Dynamo to the system, to opening Dynamo file, etc. In this respect, using Revit API or macro to generate the spheres makes more sense. Below is a macro code written in C# that reads .csv file generated from Navisworks and place sphere family in Revit.
/*
* Created by SharpDevelop.
* User: ChungHo
* Date: 16.03.2016
* Time: 10:50
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.IO;
using System.Text;namespace Test
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId(“B3D4E66D-7664-4199-BA14-AD9E63904275″)]
public partial class ThisApplication
{
FamilySymbol symbol1;private void Module_Startup(object sender, EventArgs e)
{}
private void Module_Shutdown(object sender, EventArgs e)
{}
#region Revit Macros generated code
private void InternalStartup()
{
this.Startup += new System.EventHandler(Module_Startup);
this.Shutdown += new System.EventHandler(Module_Shutdown);
}
#endregion//to ignore the warning message when the spheres are placed.
public class WarningSwallower : IFailuresPreprocessor
{
public FailureProcessingResult PreprocessFailures(FailuresAccessor failuresAccessor)
{
IList<FailureMessageAccessor> failList = new List<FailureMessageAccessor>(); // Inside event handler, get all warnings
failList = failuresAccessor.GetFailureMessages();
foreach (FailureMessageAccessor failure in failList)
{
FailureDefinitionId failID = failure.GetFailureDefinitionId(); // check FailureDefinitionIds against ones that you want to dismiss
if (failID == BuiltInFailures.OverlapFailures.DuplicateInstances) // prevent Revit from showing Unenclosed room warnings
{
failuresAccessor.DeleteWarning(failure);
}
}
return FailureProcessingResult.Continue;
}
}public void test()
{
Document doc = this.ActiveUIDocument.Document;var reader = new StreamReader(File.OpenRead(@”C:\Users\ChungHo\Desktop\test4.csv”));
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(‘;’);if (values.Length > 1)
{
double X = Double.Parse(values[7]);
double Y = Double.Parse(values[8]);
double Z = Double.Parse(values[9]);
XYZ origin = new XYZ(X,Y,Z);using(Transaction t = new Transaction(doc))
{
if (t.Start(“Create issue spheres”) == TransactionStatus.Started)
{
string FamilyName = “sphere_active”;FilteredElementCollector a = new FilteredElementCollector(doc).OfClass(typeof(Family));
Family family = a.FirstOrDefault<Element>(e => e.Name.Equals(FamilyName)) as Family;
ISet<ElementId> symbolIds = family.GetFamilySymbolIds();FailureHandlingOptions failOpt = t.GetFailureHandlingOptions();
failOpt.SetFailuresPreprocessor(new WarningSwallower());
t.SetFailureHandlingOptions(failOpt);foreach( ElementId id in symbolIds )
{
symbol1 = doc.GetElement( id ) as FamilySymbol;
break;
}FamilyInstance familyInstance = doc.Create.NewFamilyInstance(origin, symbol1, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
foreach (Parameter parameter in familyInstance.Parameters)
{
if (parameter.Definition.Name == “Smartsheet ID”){parameter.Set(values[0]);}
if (parameter.Definition.Name == “Clash”){parameter.Set(values[1]);}
if (parameter.Definition.Name == “Status”){parameter.Set(values[2]);}
if (parameter.Definition.Name == “Date”){parameter.Set(values[5]);}
if (parameter.Definition.Name == “Assigned to”){parameter.Set(values[6]);}
if (parameter.Definition.Name == “System1”){parameter.Set(values[11]);}
if (parameter.Definition.Name == “System2”){parameter.Set(values[12]);}
if (parameter.Definition.Name == “Comment”){parameter.Set(values[13]);}
}t.Commit();
}
}
}else{continue;}
}
}
}
}