Python script to apply symbology to a map

4862
5
12-26-2014 08:58 AM
CoyPotts1
Occasional Contributor III

I am running ArcMap 10.2 on a Windows 7 Machine.

I would like to get a python script that will apply a symbology layer to a feature class in my map, export the map to a KMZ, and then reapply the original symbology layer. 

I tried to create a model to do this, and it "worked", but due to the slight load time ArcMap goes through when applying the new symbology layer, the model runs so fast that it exports the KMZ before ArcMap actually has time to apply the symbology change.  I was told by a technician that I could achieve what I am needing through a python script.  My skills in Python, however, are quite basic...next to non-existent, really... 😕

I intend on adding the python script to be a part of a larger model tool (if possible), as this was the intended goal.

Any help is greatly appreciated.  Thanks!

0 Kudos
5 Replies
CoyPotts1
Occasional Contributor III

I am still looking for a solution to this problem.  Just wanted to bump this up to hopefully find someone willing and able to assist. 

Thanks!

0 Kudos
Zeke
by
Regular Contributor III

I don't use ModelBuilder, but python runs as a script; that is, a line of code doesn't run until the previous line is done (unless maybe you get into threading and whatnot). I believe in ModelBuilder you can right click on your modules and export to a python snippet. This should give you an idea of what to script, although you may need to tweak it a bit. There's also a sleep function you could call in between applying the sumbology and exporting to kmz, but don't know if that's available in ModelBuilder.

0 Kudos
CoyPotts1
Occasional Contributor III

Yeah, there is a stop function in Model Builder, but I don't think it really works for what I need, or I just haven't been using it correctly.  I'll play around with exporting the model to script and manually modifying it.  That's where I get messed up with scripting, though, as I'm unaware of the proper syntax of a lot of the stuff involved.

I'll try it out and if I feel like I'm getting somewhere I'll post the code here for further input.

Thanks!

0 Kudos
HåvardMoe
New Contributor III

You should be able to set a precondition in the model that certain parts of it should run before the rest. Have a look at e.g. A quick tour of using preconditions from ArcGIS help.

Alternatively, if you want to try python export your model to a script (in MB: Model -> Export -> To Python Script) and make sure the commands are execuded in the correct order.

0 Kudos
CoyPotts1
Occasional Contributor III

Yes, I had the preconditions set.  I failed to mention that in the original post.  I ran the model as shown below:

Save Folder

- precondition -
Apply Layer Symbology (for KMZ export)

- precondition -

Map To KML

- precondition -

Apply Layer Symbology (original/default)

In theory that should work, but like I said in the original message, the model runs too quickly for the change to apply.  When I manually apply a layer as symbology, it takes about 3-5 seconds to apply.  The model doesn't wait for it to apply before moving on, though, and spits out  a KMZ with the original symbology.

0 Kudos