Ramesh, your code block needs to be a function to return a value. You call that function in the expression, usually passing a model element value as a parameter. For datasets that is often a raw string (so any "\" in the paths are interpreted correctly).
As I said, the easiest way to get that string representation is to run the tool interactively and Copy As Python Snippet from the Results window.
I know this is kludgy but this is the way to pass unsupported parameter types like value tables to a GP service. This method of building your own string representations is a handy way to get ModelBuilder to work with tools whose parameter validation or environment setup isn't working for you in the ModelBuilder environment. For example: Re: Create fishnet in iterative model
The following example worked for me with ArcGIS 10.2.2.
Screen shot of tool interface:
Copy As Python Snippet (I did some line wrapping here though it's still legal Python):
arcpy.gp.WeightedOverlay_sa(
"('C:/WorkSpace/xg' 100 'VALUE' (1 1;NODATA NODATA); "
"'C:/WorkSpace/yg' 0 'VALUE' (1 1;NODATA NODATA)); "
"1 9 1",
"C:/WorkSpace/StepI_0601/Step_I_0601.gdb/Weighte_xg1"
)
From the above this is my attempt at creating a Calculate Value expression. If this runs you can connect its output to the Weighted Overlay tool. I tried this in ModelBuilder and it does validate (the tool will run with this input). I had to be fanatical in matching the formatting from my Copy As Python Snippet!!
Expression:
CalcWOTable(r"%Input Raster 1%", %Weight 1%, r"%Input Raster 2%", %Weight 2%)
Code Block:
def CalcWOTable(raster1, wt1, raster2, wt2):
remap_string = "(1 1;2 2;3 3;4 4;5 5;NODATA NODATA)"
scale_string = "1 9 1"
WO_Table1 = "'{}' {} 'VALUE' {}".format(raster1, wt1, remap_string)
WO_Table2 = "'{}' {} 'VALUE' {}".format(raster2, wt2, remap_string)
WO_Table = "({}; {}); {}".format(WO_Table1, WO_Table2, scale_string)
return WO_Table
Data Type:
Weighted Overlay Table
Of course you could modify this to add a third input raster and weight, and pass the scale_string as a parameter, but I kept the example simple so it would match my test tool run.