Auto-join between walls and slabs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good afternoon, I found this code to join walls and slabs, but when I compile it in C # it makes an error in the code line "Document doc = this.ActiveUIDocument.Document;". I am using the code in visual studio community 2019 and the following error appears in the list of errors
Error "Class1" does not contain a definition for "ActiveUIDocument" or an accessible extension method "ActiveUIDocument" that accepts a first argument of type "Class1".
Could you please help me and know what the code is missing to be functional and to use it in revit.
PS: I found the code in an autodesk forum more or less in 2014, I don't know if it has to be updated, I'm new to this topic.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace Autojoining_floors_and_walls
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
public class Class1
{
private bool overlap1D(double a1, double a2, double b1, double b2)
{
if (a2 >= b1 && b2 >= a1) return true;
return false;
}
private bool bbIntersect(BoundingBoxXYZ A, BoundingBoxXYZ B)
{
return overlap1D(A.Min.X, A.Max.X, B.Min.X, B.Max.X) &&
overlap1D(A.Min.Y, A.Max.Y, B.Min.Y, B.Max.Y) &&
overlap1D(A.Min.Z, A.Max.Z, B.Min.Z, B.Max.Z);
}
public void joinFloorWall()
{
Document doc = this.ActiveUIDocument.Document;
UIDocument uiDoc = new UIDocument(doc);
FilteredElementCollector walls = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Walls).WhereElementIsNotElementType();
FilteredElementCollector floors = new FilteredElementCollector(doc)
.OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType();
using (Transaction t = new Transaction(doc, "Join walls to floors"))
{
t.Start();
foreach (Wall w in walls)
{
BoundingBoxXYZ wBB = w.get_BoundingBox(null);
if (wBB != null) foreach (Floor f in floors)
{
BoundingBoxXYZ fBB = f.get_BoundingBox(null);
if (fBB != null) if (bbIntersect(wBB, fBB))
{
if (!JoinGeometryUtils.AreElementsJoined(doc, w, f))
{
try
{
JoinGeometryUtils.JoinGeometry(doc, w, f);
}
catch (Autodesk.Revit.Exceptions.ApplicationException)
{
}
}
}
}
}
t.Commit();
}
}
}
}