Pleas try this code and tell me if it works the way you want
#region Namespaces
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Architecture;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.DB.Electrical;
using Autodesk.Revit.DB.Plumbing;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.UI.Events;
using Autodesk.Revit.Exceptions;
using Autodesk.Revit.Utility;
using RvtApplication = Autodesk.Revit.ApplicationServices.Application;
using RvtDocument = Autodesk.Revit.DB.Document;
#endregion
namespace RevitAddinCS2
{
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class ExtCmd : IExternalCommand
{
#region Cached Variables
private static ExternalCommandData _cachedCmdData;
public static UIApplication CachedUiApp
{
get
{
return _cachedCmdData.Application;
}
}
public static RvtApplication CachedApp
{
get
{
return CachedUiApp.Application;
}
}
public static RvtDocument CachedDoc
{
get
{
return CachedUiApp.ActiveUIDocument.Document;
}
}
#endregion
#region IExternalCommand Members
public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elemSet)
{
_cachedCmdData = cmdData;
try
{
FilteredElementCollector WallCollector = new FilteredElementCollector(CachedDoc);
WallCollector.OfClass(typeof(Wall)).WhereElementIsNotElementType();
List<Wall> walls = WallCollector.Cast<Wall>().ToList();
StringBuilder sb = new StringBuilder();
foreach (Element wall in walls)
{
GeometryElement geomElement = wall.get_Geometry(new Options());
Solid solid = null;
foreach (GeometryObject geomObj in geomElement)
{
solid = geomObj as Solid;
if (solid != null)
{
FilteredElementCollector BeamCollector = new FilteredElementCollector(CachedDoc);
BeamCollector.OfCategory(BuiltInCategory.OST_StructuralFraming).WhereElementIsNotElementType();
BeamCollector.WherePasses(new ElementIntersectsSolidFilter(solid)); // Apply intersection filter to find matches
List<Element> beams = BeamCollector.Cast<Element>().ToList();
if (beams.Count > 0)
{
foreach (Element beam in beams)
{
sb.AppendLine(string.Format("Wall: {0} with Id: {1} intersects with Beam: {2} with Id: {3}", wall.Name, wall.Id.ToString(), beam.Name, beam.Id.ToString()));
}
}
break;
}
}
}
TaskDialog.Show("Revit", sb.ToString());
return Result.Succeeded;
}
catch (Exception ex)
{
msg = ex.ToString();
return Result.Failed;
}
}
#endregion
}
}
Please don't forget to mark this reply as an answer if it satisfies your needs.
¯\_(ツ)_/¯
Let it work like a charm.
Mustafa Salaheldin


Digital Integration Manager, DuPod
Facebook |
Twitter |
LinkedIn