Using Boolean or if to activate a code block

I am having a bit of trouble trying to speed up my script as this one is part of a complicated script and really affects the performance if it receives a null value and try to run through all of it, for simplicity i’ve made a code block containing all the functions that I need to perform, however, I want this code block to run only if there is a “true” input to it.
I know that I can add an if node to allow data in, but that does not prevent the script from running entirely.


I also tried to put the code block into an imperative with the runit input like this, but the result gives me some error

I figure it might not be as simple as it seems
do I have to put it into a loop or something?

To address the error eliminate the parenthesis at the end of the offending line
vector1 = line1.Direction;

To help better understand your problem please provide a sample file and/or the script.

if_activated imperative.dyn (34.2 KB)
here’s the dynamo code i’m trying to convert