Document.AutoJoinElements

Document.AutoJoinElements

AdvancedBIMSystems
Enthusiast Enthusiast
1,235 Views
5 Replies
Message 1 of 6

Document.AutoJoinElements

AdvancedBIMSystems
Enthusiast
Enthusiast

I'm looking for a solution to automatically join multiple neighboring families (non-system) of the same type.

 

I'm not sure how to implement doc.AutoJoinElements() as I can't find any examples online at all.

 

From what I can tell JoinGeometryUtils only works on joining two different system family types such as walls / columns / floors (but I'm happy to be wrong about this 🙂

 

Thanks in advance

 

 

 

 

0 Likes
1,236 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

Afaik, AutoJoinElements is always called automatically every time you commit a transaction. A decade ago, there was use in calling it manually. It might still be useful to regenerate the model midd-transaction. To use it explicitly, just invoke it as is:

 

  doc.AutoJoinElement();

 

By the way, have you ever taken a peek at the documentation? It says the same thing:
 
Forces the elements in the Revit document to automatically join to their neighbors where appropriate.

Syntax

C#
public void AutoJoinElements()
Visual Basic
Public Sub AutoJoinElements
Visual C++
public:
void AutoJoinElements()

Remarks

Use this method to force elements in the document to automatically join to their neighbors. Note that when a transaction is committed there is an automatic call to automatically join elements.


Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 6

AdvancedBIMSystems
Enthusiast
Enthusiast

Thanks for the quick reply Jeremy, much appreciated.

 

I have multiple adjacent instances of a generic model family which contains a nested shared generic model. I can easily manually join the shared nested components in Revit with the Join Geometry tool by mousing over & pressing the Tab key to select etc. but I'm trying to automate this task via the api.

 

I've tried JoinGeometryUtils as follows in a (futile) attempt to join the same family to it's neighbors :

 

using (Transaction tx = new Transaction(doc, "Autojoin"))
{
   tx.Start();
   foreach (FamilyInstance box in family)
   {
    if (!JoinGeometryUtils.AreElementsJoined(doc, box, box))
       {
        JoinGeometryUtils.JoinGeometry(doc, box, box);
       }
    }
tx.Commit();

 

I've applied a single FilteredElementCollector prior to the transaction to grab the families.

 

JoinGeometryUtils wants to join element A to element B but can they be the same element type?

 

(p.s. my C# is little blunt)

 

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Analyse the model in detail to discover exactly what changes were caused by your successful manual joining operation and how they are reflected via the API-accessible properties and relationships:

 

https://thebuildingcoder.typepad.com/blog/2017/01/virtues-of-reproduction-research-mep-settings-onto...

 

The API provides several different joining operations and options. Search for 'join' and see for yourself. Maybe this other option will suit your needs:

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 6

maciekglowka
Participant
Participant

Hi,

 

you can join two elements of the same type, a floor with a floor for example, using this API method.

 

Do you get any error/warning message?

Maybe you can wrap your code into try / catch and see what exception is thrown.

 

If you need some sample code for auto-joining elements, take a look here. It is a node library for Dynamo, but I am writing in C# and Revit API is the same:

https://github.com/maciekglowka/Onion/blob/master/Onion/AutoJoin.cs

0 Likes
Message 6 of 6

AdvancedBIMSystems
Enthusiast
Enthusiast

Thanks for the link, very much appreciated 🙂

 

I'll pick through the code & see if anything sticks, it looks promising.

 

I'll post the solution if I can get something working.

 

All the best.