Control Freeze Node

Hi

I refer on Forum run branch node based Freeze Node Control.
But seem like need run 2 time (double run) so the firstime run return “null”
How to solve that issue
Thank advance!

# let's see if we can break some stuff

#import standard python libraries
import clr

#reference loaded dynamo revit module
clr.AddReference('DynamoRevitDS')
import Dynamo 

#reference dynamo core to update node values
clr.AddReference('DynamoCore')

#access to the current Dynamo instance and workspace
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace

branch1 = None
branch2 = None

#find the branch nodes
for i in currentWorkspace.Nodes:
	if i.Name == "1":
		branch1 = i
	elif i.Name == "2":
		branch2 = i	
	
#freeze/unfreeze branch nodes
if IN[0]:
	branch1.IsFrozen = False
	branch2.IsFrozen = True
	out = "Running Branch 1."
else:
	branch1.IsFrozen = True
	branch2.IsFrozen = False
	out = "Running Branch 2."

#return confirmation
OUT = out

Works perfectly for me.
only difference i can see is this.

image

I assume you got this from the original thread or one referencing it, but this is somewhat explained in conversation there. This is similar to how ScopeIf works in graph.

Yeah, like @Nick_Boyts states, ScopeIf or codeblock would be much easier. But it is cool what you are trying to do with code.

The bigger question is “Why are you wanting to freeze nodes during execution?” This is poor practice as it will usually cause a lot of problems.

Hello is it possible to convert this python code to Civil 3d ?