Changing Family Instance and Saving Image Issues

Hi there, I am following this blog post (http://dynamobim.org/part-1changing-a-family-instance-and-saving-an-image/) by Michael Kirschner and am running into a few issues. I have managed to find the new component for most of the example but I do not understand the 'Transaction", “Perform All” and “Map” components and cannot find them in my library.

This is as far as I’ve gotten. Any help or wisdom is much appreciated :slight_smile:

 

UpdateParameterAndSaveImage

Part 1 - Changing a Family Instance and Saving an Image

The best way to find the new name of a node is to create the file in 0.63, save it and open it in 0.71:

2014-07-08_113328

 

 

 

 

 

 

 

I’ll try to explain the functionality of the nodes to the best of my knowledge. Anyone please correct me if you see any mistakes.

The "Map node is the most straight forward one. It is used to apply a function or a series of functions to a list of items( could be numbers, strings, elements, etc.). It is most commonly used for functions that expect a single input and you want to feed it more than one input. 0.7 is a bit smarter in that regard and most of the functions can now take lists as inputs.

2014-07-08_114428

 

 

 

 

The “Transaction” node is a bit more tricky. It has to do with how the Revit API functions. For you to apply any changes to a revit document, you need to open a transaction, run your operations and close the transaction. By default things in dynamo happen at the same time under a single transaction unless you otherwise specify differently. For example if I start a transaction, run three operations and finish it, if I go inside revit and undo the changes, it will undo all three operations at once. But if I separate the three operations in an individual transaction each, I will have to press undo three times to revert my document to its original state. In the example you linked to above, they want to separate the change of parameter and the screen capture, so that one action always follows the other, otherwise you might not be able to catch the change.

Once we know how the “transaction” node works, the “Perform All” node is self explanatory. It specifies the order in which the separate transactions have to happen, and makes it so that one event is finished before the next starts. I’m not sure exactly why it has been depreciated and what are the new mechanics that are used in its place. Hopefully someone can chime in to enlighten us both.

Hope that clears it up. :slight_smile:

So I think I have a viable conversion for this tutorial to .7!

It’s a bit functional! You get to use the function.compose node. I’m not sure yet, but you may also be able to use a python node as a kind of hacky perform all.

The image is corrupted, and the image is also held onto by Revit until close. I’ll be reporting these bugs to the team, but hopefully this gets you started.

You can see the use of the transaction.end node after the parameter update and after the image save, I used the function compose node, which is like writing f(g(x)). The top custom node is passed the value from the mapped list, then its output is passed to the second node.

Let me know if this makes no sense. I do not have time to test, but you might be able to get this going in one custom node if you use a python node as a surrogate perform all, taking in the result of the transaction and passing the file path through, this would force the transaction to be evaluated before the image save. (I think)

Cheers

Mike

 

 

Screen Shot 2014-07-08 at 9.11.03 PM

Thank you Dimitar and Michael for the comments! I get the List.Map now I think too, it checks the list against the function and returns the result? The transactions are a bit trickier as with the example above I couldn’t find a suitable place for the Transaction.Start (just in wondering why there was only a end transaction and not a start), however the description you gave Dimitar makes sense and i’ll keep working on it.

Thanks for replying Michael :slight_smile: I followed what you outlined and it ‘works’. I get a saved screen capture on my desktop which is awesome! Although it’s quite erratic for me. Sometimes it will save all 5 images and other times it will just save one (like the one attached). Every time it makes the cylinder WAY taller than it should be and components fail. Is this a 0.7 issue?

Also am I right in understanding the script? A function is scripted to take a family and alter one of its parameters by a given number (no number set just the capacity to deal with one), at the same time a function is scripted to take a screenshot and give it an incremental file name (again a place holder for different number values is entered into the function but not given yet), then these two functions are combined (with the Transaction.End component so Revit will perform one then the next, then the next etc.) and at the end the values are mapped against this combined function to give Revt 5 tasks to perform. Is this roughly what this script is trying to achieve? I’m not sure, also wondering why the number isn’t added to all the ‘value’ inputs of the custom nodes?

 

Thanks again :slight_smile:

MM{50,100,150,200,250}

 

Process

A few things

list.map, will map a function over a list of values. This means, do this function to each value in the list, and return a list of the results.

The reason the VAL is left open is precisely to do with how map works. When we call this function chain, saveimage(updatevalues(10)), saveimage(updatevalues(20)) etc. the numbers we map over ARE the inputs to VAL, thats why it’s left blank, dynamo figures out thats the input that is open and it calls that function chain with each number in the list.

The output of the first function is the current value again, it’s just passed through, so it’s also the input to the second function in the chain, so whatever the output is from update values, gets sent into save image(), thats what function.compose does.

I think the reason it’s not working all the time is the live runner/delta execution in .7, dynamo doesn’t realize that you want to run this graph again, you can force it do by unhooking something at the start of your graph, running, re hooking, and running again… I know a bad solution for now.

There is a force re-execute command in the debug branch if you want to try building from source. These bugs have been filed internally.

Mike

Thanks for the detailed response Mike. It’s taking me a while to get my head around this, but I’ll get there :slight_smile:

Thanks again!

MM

it might help to see that the actual function we’re calling is like this.

 

save image ( updatefamily(value,parameter,family) )

update family gets called first, it just returns the value, so the save image get called like this:

saveimage (value)

This is how we make sure that family updating occurs before the image save, because the function chain ensures that one function is evaluated before the other.