Transaction with Loops

So Inhave an example of repeating a transaction until a condition is met which I’ll link to… however it’s a bad idea in most cases for a few reasons.

  1. You could do the action once, 100 times, or infinitely (say the initial mass had a volume of 1 and you wanted an overlapping volume of 2). Infinite loops are a bad idea in all cases so you’ll need to write a bunch more code to prevent them, or risk having to force quit Revit periodically.

  2. You can have to do a bunch of compute with no value, as you may have to shift the elements many unknown number of times to get your first result.

  3. Transactions and document regeneration is slower than using geometry. Pulling the solids and working with them means you can commit one action (just find the first vector which produces the volume and move the element by that).

  4. Finding a ‘realistic’ value using a single calculation is doable. In most real cases you can move the two solids so they have an adjoining surface by using a pair of ‘closest point to’ methods to form a vector and shift the first object by that vector, divide the desired volume by the area of that overlapping surface to find the necessary depth, add the normal vector of the surface for the first object scaled to the depth value to the original vector. Shift the original first object by that vector and validate the results. This won’t work for highly irregular solids but those are quite rare.

2 Likes