How to Join two structural framings

How to Join two structural framings

Anonymous
Not applicable
1,838 Views
9 Replies
Message 1 of 10

How to Join two structural framings

Anonymous
Not applicable

 

I am trying to join two structural framing..This is the code I had written below but its show error.I attached some screen shoot for this.

plz tell me what mistake that I had done.If possible plz tell the code

 

 

 

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

namespace JoinGeometry
{
[Transaction(TransactionMode.Manual)]

class BBunjoin:IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;

 

//--get walls on the active view-----------

FilteredElementCollector beam1 = new FilteredElementCollector(doc, doc.ActiveView.Id);
beam1.OfClass(typeof(FamilyInstance));
beam1.OfCategory(BuiltInCategory.OST_StructuralFraming);

 

foreach (FamilyInstance bem1 in beam1)
{
FilteredElementCollector beam2 = new FilteredElementCollector(doc, doc.ActiveView.Id);

beam2.OfClass(typeof(FamilyInstance));
beam2.OfCategory(BuiltInCategory.OST_StructuralFraming);
/* BoundingBoxXYZ bb = bem1.get_BoundingBox(doc.ActiveView);
Outline outline = new Outline(bb.Min, bb.Max);
BoundingBoxIntersectsFilter bbfilter =
new BoundingBoxIntersectsFilter(outline);
beam2.WherePasses(bbfilter);*/

foreach (FamilyInstance bem2 in beam2)
{
using (Transaction t = new Transaction(doc, "Join All beam/beam"))
{
t.Start();
JoinGeometryUtils.JoinGeometry(doc, bem1, bem2);

t.Commit();
}

}

}
return Result.Succeeded;
}
}
}

 

 

0 Likes
1,839 Views
9 Replies
Replies (9)
Message 2 of 10

Moustafa_K
Advisor
Advisor

can you click on the arrow next to show more detail in the error message and post it?

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 3 of 10

Anonymous
Not applicable

This error message 

0 Likes
Message 4 of 10

Moustafa_K
Advisor
Advisor

I thing your code is trying to Join Beam 1 with Beam 2 , it appears that Beam1 is exactly the same as beam2. which means you are asking revit toin a beam with it self.

 

just add this line after

 

  foreach (FamilyInstance bem2 in beam2)
                {
if(bem2.Id == bem1.Id) continue;
 using (Transaction t = new Transaction(doc, "Join All beam/beam"))
 {
 t.Start();
 JoinGeometryUtils.JoinGeometry(doc, bem1, bem2);
 t.Commit();
 }

however this might get you to another error:

if you have 3 beams and you are looping around each to join them, it will come at a time that you are joing an element which is already joined which also will raise an error by Revit "Element is already Joined"

 

a work around this, is add try and catch to your code should be 

                foreach (FamilyInstance bem2 in beam2)
                {
                    if (bem2.Id == bem1.Id) continue;
                    using (Transaction t = new Transaction(doc, "Join All beam/beam"))
                    {

                        t.Start();
                        try
                        {
                            JoinGeometryUtils.JoinGeometry(doc, bem1, bem2);
                        }
                        catch (Autodesk.Revit.Exceptions.ArgumentException)
                        {


                        }
                        t.Commit();
                    }

                }

Give it a try and let us know the results

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 5 of 10

Anonymous
Not applicable

Thank u for reply, you are right, I added the code which you have given from that the beam has been joined.

0 Likes
Message 6 of 10

Anonymous
Not applicable

One more problem occured when I want to SwitchJoin two structural framing it do not switchjoin  the structural framing and it does not occur any error.

plz tell me what should I do.

 

THIS IS THE CODE FOR SWITCHJOIN

 

 

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

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

namespace JoinGeometry
{

[Transaction(TransactionMode.Manual)]

class BBswitchjoin:IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uidoc = uiApp.ActiveUIDocument;
Document doc = uidoc.Document;

 

//--get beam on the active view-----------

FilteredElementCollector beam1 = new FilteredElementCollector(doc, doc.ActiveView.Id);
beam1.OfClass(typeof(FamilyInstance));
beam1.OfCategory(BuiltInCategory.OST_StructuralFraming);

foreach (FamilyInstance bem1 in beam1)
{
FilteredElementCollector beam2 = new FilteredElementCollector(doc, doc.ActiveView.Id);
beam2.OfClass(typeof(FamilyInstance));
beam2.OfCategory(BuiltInCategory.OST_StructuralFraming);

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


foreach (FamilyInstance bem2 in beam2)
{

if (bem1.Id == bem2.Id) continue;


using (Transaction t = new Transaction(doc, "Join All beam/beam"))
{
t.Start();
try
{
JoinGeometryUtils.SwitchJoinOrder(doc,bem2,bem1);
}
catch (Autodesk.Revit.Exceptions.ArgumentException)
{


}

t.Commit();
}

}

}
return Result.Succeeded;
}
}
}

0 Likes
Message 7 of 10

Moustafa_K
Advisor
Advisor

I am not exactly sure. but try first unjoining then commit transaction and then join

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes
Message 8 of 10

Anonymous
Not applicable

It not work.

0 Likes
Message 9 of 10

Shai.Nguyen
Advocate
Advocate

How can I control if there is a warning if 2 elements are not intersected. It can be ignored and continue to the loop with the others?Capture.JPG

Message 10 of 10

thannaingoo.api
Advocate
Advocate

I got these issue, How should be do?

0 Likes