Exception with JoinGeometryUtils.JoinGeometry and Walls

Exception with JoinGeometryUtils.JoinGeometry and Walls

guillain.jolivet
Contributor Contributor
2,216 Views
3 Replies
Message 1 of 4

Exception with JoinGeometryUtils.JoinGeometry and Walls

guillain.jolivet
Contributor
Contributor

Hi,

 

i'm working on a python script to split a multilayer wall in several monolayer walls (a wall by layer). After creating them, i want to join them, so the hosted elements, like windows, will cut the different monolayer walls.

 

For exemple, i got a 3-layers-wall, and after my script i got three 1-layer-walls, in a list called Walls. And i'm doing this :

 

TransactionManager.Instance.EnsureInTransaction(doc)
for wall1 in Walls :
	for wall2 in Walls :
		try :
			JoinGeometryUtils.JoinGeometry(doc, wall1, wall2)
		except :
			pass
TransactionManager.Instance.TransactionTaskDone()

 

This code, return an Exception : The elements cannot be joined. Parameter name: secondElement

 

But, if i run my python script, create my walls, and then select the 3 walls with the dynamo node "Select Model Elements" and run an other script, it works...

 

doc = DocumentManager.Instance.CurrentDBDocument 
Walls = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)
for wall1 in Walls :
	for wall2 in Walls :
		try :
			JoinGeometryUtils.JoinGeometry(doc, wall1, wall2)
		except :
			pass
TransactionManager.Instance.TransactionTaskDone()

 

 

Any idea why it's not working in the first script but i does in the second one?

 

Accepted solutions (1)
2,217 Views
3 Replies
Replies (3)
Message 2 of 4

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi,

 

Could be the created walls first need to regenerate in order to perform the JoinGeometry.

 

In the API I use a transactiongroup, so you can create the walls in a transaction, commit it and then start a new transaction for the JoinGeometry. Afterwards all transactions can be "grouped" by assimilating the transactiongroup so it's considered a single command in Revit.

 

TransactionGroup Class 

 

Also the 2 loops uses the same collection, wouldn't the JoinGeometry try to join the same walls once for each wall in the collection (maybe allowed without error?). Check if it's tying to join same elements first or create a pair collection first...

 

- Michel

Message 3 of 4

guillain.jolivet
Contributor
Contributor

What's weird is that i can join the monolayer walls to the multilayer wall..

In my code I create a dictionnary where keys are Wall Types Id, with :

  • Layercount
  • Width of each layer
  • Stack width of layers
  • Monolayer Walls Id
  • Stuctural layer

Then, for each selected wall, I use this dictionnary to create the differents monolayer walls, and then i join them.

 

Joining monolayer walls to the multilayer wall is working. Not between monolayer walls :

Dic_Wall_Types[key] = [Compo_Wall.LayerCount, Widths, Stack_Wi, Monolayer_Walls, Structure]

tg = TransactionGroup(doc ,"Main")
tg.Start()
for wall in Walls_Selection :
	Object, Curves, Storage =[], [], []
	Wall_Type = wall.GetTypeId()
	Vect_API = Orientation_API(wall)	# Normal vector of the wall
	Location = wall.Location
	list_test = []

	# Get parameters values from the wall to split (level, offset,...)
	for param in Parameters :
		p = wall.LookupParameter(param)
		val = Param_Value(p, p.StorageType)
		Object.append(val)
	
	# Get Wall Type data from the Wall_Types dictionnary
	n = Dic_Wall_Types[Wall_Type][0]
	Width = Dic_Wall_Types[Wall_Type][1]
	Stack = Dic_Wall_Types[Wall_Type][2]
	Wall_Mono = Dic_Wall_Types[Wall_Type][3]
	St = Dic_Wall_Types[Wall_Type][4]

	# Creation curves of each monolayer wall to create
	for i in range(0, n) :
		a = sum(Width)/2-(Stack[i]-Width[i]/2)
		Tr = Transform.CreateTranslation(Vect_API.Multiply(a))
		c = Location.Curve.CreateTransformed(Tr)
		Curves.append(c)
	
	# Creation of monolayer walls
	t = Transaction(doc, "Creating monolayer walls")
 	t.Start()
	for index, curve in enumerate(Curves) :
		s = False
		if index == St and Object[7] == 1 :
			s = True

		mono_wall = Wall.Create(doc, curve, Wall_Mono[index], Object[0], Object[4], Object[1], False, s)
		
		Walls.append(mono_wall)
	t.Commit()
 	
 	t = Transaction(doc, "Join walls")
 	t.Start()
	for monowall1 in Walls :
		JoinGeometryUtils.JoinGeometry(doc, monowall1, wall)
		for monowall2 in Walls :
			JoinGeometryUtils.JoinGeometry(doc, monowall1, monowall2)

	t.Commit()

tg.Commit()

TaskDialog.Show("The transaction {} has ended well : {}".format(tg.GetName(), tg.HasEnded()))

 

But if I run my script, then select the monolayer walls, and run the script below, it works...

doc = DocumentManager.Instance.CurrentDBDocument 
Walls = UnwrapElement(IN[0])

TransactionManager.Instance.EnsureInTransaction(doc)
for wall1 in Walls :
	for wall2 in Walls :
		JoinGeometryUtils.JoinGeometry(doc, wall1, wall2)
TransactionManager.Instance.TransactionTaskDone()

 

I've made lot of tests, but unfortunately, it's never working. I have to do it in 2 steps and I can't figure out why...

Message 4 of 4

Anonymous
Not applicable

That was the solution to my problem too.
Thank you for sharing!
Here is a very simple exemple of the GoupTransaction :
https://thebuildingcoder.typepad.com/blog/2015/02/using-transaction-groups.html


Best regards,

François Robberts