Set Lightmap texture by the code

I need to set the Lightmap texture by the code.
I’ve tried this:

if(is_lightmapped){
Texture2D lmTex=Resources.Load("lightmaps",  typeof(Texture2D)) as Texture2D;
LightmapData[] lightmaparray = new LightmapData[1];// LightmapSettings.lightmaps;
LightmapData mapdata = new LightmapData();
mapdata.lightmapFar = lmTex;
mapdata.lightmapNear = lmTex;
lightmaparray[0] = mapdata;
LightmapSettings.lightmaps = lightmaparray;
}

but it doesn’t work.
1246788--53610--$li.png
Note that my lightmaps texture is in a Resources folder.

I’ve done something similar with the texture atlas:

Material theNewMaterial = Resources.Load("Materials/"+texture_atlas_name, typeof(Material)) as Material;
Material[] mats;
mats = meshRenderer.materials;
mats[0] = theNewMaterial;
meshRenderer.materials = mats;

and it works but i need to do the same with the lightmap texture.

SOLVED

meshRenderer.sharedMaterial.SetTexture(“_LightMap”,lmTex);