InvalidOperationException: Wall set_ElementsAtJoin

InvalidOperationException: Wall set_ElementsAtJoin

Anonymous
Not applicable
1,826 Views
8 Replies
Message 1 of 9

InvalidOperationException: Wall set_ElementsAtJoin

Anonymous
Not applicable

Hello everyone,

 

无标题.png

Choose the No.1 wall:

ElementArray arr = (wall1.Location as LocationCurve).get_ElementsAtJoin(0);

arr values :[wall1,wall2]

__________________________________________

I want to add the No.3 wall to the ElementArray .

elementArray = [wall1,wall2,wall3]

(wall1.Location as LocationCurve).set_ElementsAtJoin(0, elementArray);

 

 

The error information is as follows:

Autodesk.Revit.Exceptions.InvalidOperationException
at Autodesk.Revit.DB.LocationCurve.set_ElementsAtJoinInternal(Int32 end, List`1 elements)
at Autodesk.Revit.DB.LocationCurve.set_ElementsAtJoin(Int32 end, ElementArray elements)
at Revit.numWall.Execute(ExternalCommandData commandData, String& message, ElementSet elements)

 

0 Likes
Accepted solutions (1)
1,827 Views
8 Replies
Replies (8)
Message 2 of 9

aignatovich
Advisor
Advisor

Hi!

 

There is a remark in description of LocationCurve.ElementsAtJoin Property in Revit SDK:

ElementsAtJoin Property

The list of elements is expected to be a permutation of the elements already in the join at the end. It is expected that no new elements will be introduced, and existing ones will not be removed.
 
If you want to join walls, you should allow joins at specific wall end and Revit will join walls to you automatically. Look at WallUtils static class. It has AllowWallJoinAtEnd, DisallowWallJoinAtEnd and IsWallJoinAllowedAtEnd methods.
 
 
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi, this method has been used.

WallUtils.AllowWallJoinAtEnd(wall1, 0);
WallUtils.AllowWallJoinAtEnd(wall1, 1);
WallUtils.AllowWallJoinAtEnd(wall2, 0);
WallUtils.AllowWallJoinAtEnd(wall2, 1);
WallUtils.AllowWallJoinAtEnd(wall3, 0);
WallUtils.AllowWallJoinAtEnd(wall3, 1);

0 Likes
Message 4 of 9

aignatovich
Advisor
Advisor

Can you join all 3 walls via UI? May be they are already joined? Or may be there is something, that prevents Revit to join them?

0 Likes
Message 5 of 9

Anonymous
Not applicable

Can you join all 3 walls via UI?
yes!

 

may be "set_ElementsAtJoin" is not allowed to add elements.

 

 

Attachments are model files.

Thank you very much for your help!

0 Likes
Message 6 of 9

aignatovich
Advisor
Advisor

Yes, you can't add or remove joins via set_ElementsAtJoin.

I explored a bit your model. These walls are already joined:

walls joins.png

 

0 Likes
Message 7 of 9

Anonymous
Not applicable

Looking at the  already joined from UI.

But using "wall1.get_ElementsAtJoin(0)" method, the result do not contain  wall3.

 

Wall wall1 = doc.GetElement(uiDoc.Selection.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element).ElementId) as Wall;

 

 

Test by the following methods:

var elementArray = (wall.Location as LocationCurve).get_ElementsAtJoin(0);

foreach(var element in elementArray )

{

   elementIds.Add(element.Id);

}

uiDoc.Selection.SetElementIds(elementIds);

 

0 Likes
Message 8 of 9

aignatovich
Advisor
Advisor
Accepted solution

A bit strange thing, but it works. Just disallow joins and then allow it again. If you create these walls programmatically, I think you should regenerate the document before performing this trick.

 

This is Iron Python shell code:

# you should select a wall before running this
tx = Transaction(doc, "test")
tx.Start()

WallUtils.DisallowWallJoinAtEnd(selection[0], 0)
WallUtils.AllowWallJoinAtEnd(selection[0], 0)

tx.Commit()
0 Likes
Message 9 of 9

Anonymous
Not applicable

Thank you very much. It's OK.

It's so strange!!!

0 Likes