Change polyline symbology in python

4047
7
12-01-2015 07:47 AM
DavidChevrier
Occasional Contributor II

Hi,

   In python, I've created a new polyline feature class, turned it into a layer and added it to an existing map.  How can I dynamically change the color of that line in python code?

0 Kudos
7 Replies
WesMiller
Regular Contributor III

You can use a lyr file to set the symbology in your script.

Setting output symbology in scripts—Help | ArcGIS for Desktop

DavidChevrier
Occasional Contributor II

I was hoping there was a way to do this without first creating a dummy layer file of every possible color I would use.  I'm looking for how to change the symbology in code, not just assign it an already existing one.  In arcims I could do this simply with arcxml:

<LAYER type="acetate" name="NAME" visible="true" id="$preLineID">

  <OBJECT units="database">

  <SIMPLELINESYMBOL transparency="1.0" type="$markType" overlap="false" color="255,0,0" antialiasing="true" width="4" />

  <POLYLINE>

  <PATH>

  <POINT x="$xPoint1" y="$yPoint1" />

  <POINT x="$xPoint2" y="$yPoint2" />

  </PATH>

  </POLYLINE>

  </OBJECT>

</LAYER>

0 Kudos
FreddieGibson
Occasional Contributor III

Currently this isn't possible within the arcpy site package. Although you can inherit the symbology from an existing layer file or use python to change the renderer for the layer, you cannot create the symbology from scratch and apply it to the layer.

To accomplish this you'd need to utilize ArcObjects. Within ArcObjects you could create the symbol, add it to a renderer and set the renderer for the layer.

How to make a line fill symbol

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#/How_to_make_a_line_fil...

Working with layers and renderers

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#/Working_with_layers_an...

DavidChevrier
Occasional Contributor II

While that would work, the way that was project has to be done, I can't use ArcObjects.  Its has to be done in an geoprocessing service that I can call within the existing perl code since this is replacing an old way of creating a map.  We can't recode the entire website for this one little part.  Thank you though.

0 Kudos
FreddieGibson
Occasional Contributor III

No problem. Without using ArcObjects directly I don't think you'd be able to accomplish this in a supported manner until these functionalities are added to the arcpy module. Otherwise, the ArcObjects code could easily be wrapped into a custom gp tool, published to the server as a gp service, and called from any client that can communicate with REST.

0 Kudos
DavidChevrier
Occasional Contributor II

I'm confused.  I can write something using ArcObjects and have it wrapped as a gp tool now or is that something that would need to be changed by Esri before I could do it?  Cause I think that would work for me if that is possible presently (and I saw an example of how to do that.)

0 Kudos
FreddieGibson
Occasional Contributor III

ArcObjects would allow you to build custom gp tools in the same manner that you build them in python. The python toolbox and python script tool workflows are essentially a watered down version of what you can do in ArcObjects.

Building a custom geoprocessing function tool

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Building_a_custom_geoprocessing_...

0 Kudos