ApplySymbologyFromLayer does not work in my python code

2573
2
12-27-2015 02:27 AM
MonirRahman
New Contributor II

Hi,

I have  a layer file. I make a button in ArcGIS 10 with .NET. I want to change layer symbology with the layer file. For this purpose I Write python code and execute it from C#. If the following code is written in python window of ArcGIS, then works fantastic. But from my code, it does not work. Can anyone help me ??

try

           {

               const string prg = @"import sys

import arcpy

from arcpy import env

mxd = arcpy.mapping.MapDocument('CURRENT')

layer = arcpy.mapping.ListLayers(mxd)[0]

    arcpy.ApplySymbologyFromLayer_management(layer,'C:\Users\DELL\AppData\Local\Temp\Junctions_Temp.lyr')

"

                   ;

               var sw = new StreamWriter("D:\\test2.py");

               sw.Write(prg); // write this program to a file

               sw.Close();

               var p = new Process

                           {

                               StartInfo =

                                   {

                                       FileName = @"C:\Python26\ArcGIS10.0\python.exe",

                                       RedirectStandardOutput = true,

                                       UseShellExecute = false,

                                       Arguments = "D:\\test2.py "

                                   }

                           }; // create process (i.e., the python program

               p.Start();

Thanks ...

Tags (4)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

your filename in applylayerfromsymbology is not pythonic, the layer location needs to be preceeded by an r to denote raw notation for paths ie r"c:\somepath\somefile" that may not be the issue, but the path to the file needs to be specified correctly

0 Kudos
MonirRahman
New Contributor II

Thanks Dan, for your quick reply. I have correct path format as your, but no result.

0 Kudos