I’m trying to put together a graph to set the function of layers in compound families (walls, roofs, floors, ceilings) and am stuck on the actual implementation of setting the function. I’ve shamelessly hacked up the FamilyType.SetCompoundLayerMaterial node from Clockwork and managed to restructure the node itself (woo!) and have managed to get the python to set the function IF I force it using MaterialFunctionAssignment.Substrate (or Finish1, Structure, etc.) However, that isn’t very useful long-term since the function might need to be something different depending on the family.
So - I’m obviously missing something in the Python code itself on how to allow the Layer Function to be an input and then executed based on the input but I’m stumped. Long term goal with this is to be able to filter everything by the material (i.e. 1/2" Metal Furring) and have all layers that have that material be set to a particular function (i.e. Substrate); however the application could easily go in a variety of other directions.
After stumbling around this for a while I’m a bit lost (my python knowledge is… limited); I’ll try and work on it a bit more today and come back with some actual questions rather than just stating I’m lost.
What’s the benefit of using IF rather than TRY in this instance? I looked them up and it seems the main reason to use one or the other has to do with error handling, but I don’t quite have a full grasp on it.
Does the IF nest inside of the TRY statement or is it a replacement? I’ve tried both but haven’t had much luck…
The 0 in the if material_function_string == ‘0’ string corresponds to the 0 in the IN statement correct? So if I have multiple inputs that could be a 2, as long as both of them are 2?
The bigger issue I’m running into is your code still forces the assignment by using MaterialFunctionAssignment.Structure. In theory what I want to achieve is MaterialFunctionAssignment.(material_function_string), where the (material_function_string) could be Structure, or Substrate, or FInish1, etc.
In the attached version I fumbled through the Python (script from string) and at least managed to get it to not error, but the OUT on the node returns the name of the wall, rather than the function, which probably relates to item 3 above…
1.The benefit of using ‘if’ is creating a conditional statement. We want to assign MaterialFunctionAssignment.Structure to material_function if the given string on the input is equal “0” (as a letter). You can change “0” to “structure” for example. Then you can add another if statement:
if material_function_string == 'structure':
material_function = MaterialFunctionAssignment.Structure
if material_function_string == 'finish':
material_function = MaterialFunctionAssignment.Finish1
2 - Both ‘if’ and ‘try’ can be nested inside each other but they have two different purposes. Please see Python documentation.
3 - No, it does not correspond. The IN is assigned here:
material_function_string = IN
Wherever you see ‘material_function_string’ you shoud read it as ‘IN’. You only change value you feed to input.