Add a topology and its associated layers to a map document with a python script

1119
4
05-15-2014 09:38 AM
marisavallve
New Contributor
I would like to add a topology and its associated layers to a map document with a python script (the script does many things and at the end I want it to load the layers to the mxd).  When I try to use

arcpy.MakeFeatureLayer_management (topology_layer,feature_layer)
lyrLayer = arcpy.mapping.Layer(feat_layer)
arcpy.mapping.AddLayer(df,lyrLayer, "TOP")

it says:
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input Features: Dataset \\dbs\DBS_ntdisk\tiger10\gdb\geo065.gdb\Tiger10\ed15_topology does not exist or is not supported

What type of layer is the topology? how can I add it to the current mxd?
Thanks!
Tags (2)
0 Kudos
4 Replies
MikeMacRae
Occasional Contributor III
Is the location of your topology password protected? Try setting your workspace environment first:

arcpy.env.workspace


Also, is 'feature_layer' and 'feat_layer' the same thing? If so, you making use of

arcpy.mapping.MakeFeatureLayer


and

arcpy.mapping.Layer


twice which is a little redundant.

You should be fine just using the later without the former.
0 Kudos
marisavallve
New Contributor
Thank you for your answer.

Well no ... feat_class and feat_layer are two different things:

feat_class ="\\\\dbs\\DBS_ntdisk\\tiger10\\gdb\\geo065.gdb\\Tiger10\\ed15_topology"
feat_layer = "ed_topology"
symbologyLayer ="\\\\dbs\\DBS_ntdisk\\tiger10\\Symbology_LayerFiles\\ed_topology.lyr"

arcpy.MakeFeatureLayer_management(feat_class,feat_layer)      ####This cannot create a layer from a topology layer..
                                                                                                so nothing works after this ...
arcpy.ApplySymbologyFromLayer_management(feat_layer,symbologyLayer)
lyrLayer = arcpy.mapping.Layer(feat_layer)
arcpy.mapping.AddLayer(df,lyrLayer, "TOP")

**** So this works for any feature class but not for topology. So I don't know how to add topology to my mxd with python... yet ...
0 Kudos
MathewCoyle
Frequent Contributor
You have to save it as a layer file, create a layer object from the file, then add it.

Example
import arcpy

topology_path = 'path1'
layerfile_path = 'path2'

mxd = arcpy.mapping.MapDocument('current')
df = arcpy.mapping.ListDataFrames(mxd)[0]
layer = arcpy.mapping.Layer(layerfile_path)
arcpy.mapping.AddLayer(df, layer)



Edit: disregard, this method does not work natively. It only works if you have already saved the topology as a layer file.
0 Kudos
Geography
New Contributor

It appears that I ran into the same question. Did you figure out how to do it using arcpy?

0 Kudos