Based on Andrew Moylanโs decision, you can build a function of type โBlockโ that will accept the rules:
SetAttributes[BlockRules, HoldRest] BlockRules[rules_, expr_] := Block @@ Append[Apply[Set, Hold@rules , {2}], Unevaluated[expr]]
Then you can save your numerical rules in a variable and use BlockRules [savedrules, code] or even define a function that would apply a fixed set of rules, like:
In[76]:= NumericCheck = Function[body, BlockRules[{a -> 3, b -> 2`}, body], HoldAll]; In[78]:= a + b
EDIT In response to Timo's comment, it may be possible to use NotebookEvaluate (new in 8) to achieve the requested effect.
SetAttributes[BlockRules, HoldRest] BlockRules[rules_, expr_] := Block @@ Append[Apply[Set, Hold@rules , {2}], Unevaluated[expr]] nb = CreateDocument[{ExpressionCell[ Defer[Plot[Sin[ax], {x, 0, 2 Pi}]], "Input"], ExpressionCell[Defer[Integrate[Sin[ax^2], {x, 0, 2 Pi}]], "Input"]}]; BlockRules[{a -> 4}, NotebookEvaluate[nb, InsertResults -> "True"];]
As a result of this assessment, you get a laptop with evaluated commands when it was locally set to 4. To take it further, you will have to take a laptop with a code, open a new notebook, evaluate Notebooks[] to identify the notebook of interest, and then do:
BlockRules[variablerules, NotebookEvaluate[NotebookPut[NotebookGet[nbobj]], InsertResults -> "True"]]
Hope you can make this idea work.
