Join only selected wall and column

Join only selected wall and column

Anonymous
Not applicable
541 Views
3 Replies
Message 1 of 4

Join only selected wall and column

Anonymous
Not applicable

Hello,

 

I create a simple addin for joining wall and column but it join all wall and column in the active view. I want to join only selected wall and column.It is possible without using inbuilt join button which is in revit?

 

what changes I want to make in this code?

 

 

I using this code: for joining all wall and column

 

 

UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;

FilteredElementCollector collWalls = new FilteredElementCollector(doc, doc.ActiveView.Id);
collWalls.OfClass(typeof(Wall));

foreach (Wall w in collWalls)
{

FilteredElementCollector collColumnsOnThisWall = new FilteredElementCollector(doc, doc.ActiveView.Id);

collColumnsOnThisWall.OfClass(typeof(FamilyInstance));
collColumnsOnThisWall.OfCategory(BuiltInCategory.OST_StructuralColumns);

BoundingBoxXYZ bb = w.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(bb.Min, bb.Max);
BoundingBoxIntersectsFilter bbfilter =
new BoundingBoxIntersectsFilter(outline);
collColumnsOnThisWall.WherePasses(bbfilter);

foreach (FamilyInstance column in collColumnsOnThisWall)
{
using (Transaction t = new Transaction(doc, "Join All Walls/Column"))
{
t.Start();

check = JoinGeometryUtils.AreElementsJoined(doc, w, column);
if (check == true)
{

}
else
{
JoinGeometryUtils.JoinGeometry(doc, w, column);

}

t.Commit();
}

}

}

0 Likes
542 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

It looks like you're using a FilteredElementCollector to collect all the walls and columns and join them all. If you want to join just the selected elements use something like:

 

 

ICollection<ElementId> ids = uidoc.Selection.GetElementIds();
ElementSet wallscoll = new ElementSet();
ElementSet colcollection = new ElementSet();
foreach (ElementId id in ids)
{
Element ele = doc.GetElement(id);
if (ele.GetType().Name == "Wall") wallscoll.Insert(ele);
if (ele.GetType().Name == "Column") colcollection.Insert(ele);
}

 

 

0 Likes
Message 3 of 4

Anonymous
Not applicable

I tried this code but it not working.What changes I want to make in this code and where?

 

 

 

 

Here is the code:

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace selection
{
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{

UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;
using (Transaction t = new Transaction(doc, "Join Walls/Column"))
{
t.Start();

ICollection<ElementId> ids = uidoc.Selection.GetElementIds();
ElementSet wallscoll = new ElementSet();
ElementSet colcollection = new ElementSet();
foreach (ElementId id in ids)
{
Element ele = doc.GetElement(id);
if (ele.GetType().Name == "Wall") wallscoll.Insert(ele);
if (ele.GetType().Name == "Column") colcollection.Insert(ele);

}


foreach(Wall w in wallscoll)
{
foreach(FamilyInstance column in colcollection)
{
JoinGeometryUtils.JoinGeometry(doc, column,w);
}
}
t.Commit();
}

return Result.Succeeded;
}
}
}

0 Likes
Message 4 of 4

Anonymous
Not applicable

Try changing this:

if (ele.GetType().Name == "Column") colcollection.Insert(ele);

to this

if (ele.Category.Name == "Columns") colcollection.Insert(ele);

 

Otherwise can you be more specific about what doesn't work? The code compiles and runs just fine for me on a quick sample project. Have you stepped through the code line by line as it runs to find your specific issue? 

0 Likes