Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I wrote a little script for ArcGis, and when I make it run by GUI it happens that it seems to create routes but the routes do not appear in the TOC. Consequently, when the script tries to execute operation on those routes, the dataset cannot be found.

How can I solve this issue?

Thanks in advance, Annalisa

share|improve this question
    
Can you provide some details of your code, please? –  PolyGeo Dec 8 '12 at 11:52
1  
Posting your code might help. –  Chad Cooper Dec 14 '12 at 1:11

2 Answers 2

up vote 2 down vote accepted

I just tested the code below which seemed to work when I placed it behind a tool with no parameters.

arcpy.CreateRoutes_lr("C:/temp/test.gdb/Streets","STREET","C:/temp/test.gdb/StreetRoutes","LENGTH","#","#","UPPER_LEFT","1","0","IGNORE","INDEX")

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
arcpy.MakeFeatureLayer_management("C:/temp/test.gdb/StreetRoutes", "route_lyr")
arcpy.SaveToLayerFile_management("route_lyr", "C:/temp/StreetRoutes.lyr")
addLayer = arcpy.mapping.Layer("C:/temp/StreetRoutes.lyr")
arcpy.mapping.AddLayer(df, addLayer)

MakeRouteEventLayer is for placing line and point events along routes so is not used as part of simply drawing the route.

share|improve this answer
    
many thanks, it seems to work (makes a route event layer) evenif it doesn't seems to add the created route to the TOC. Quite strange, but it works. –  Annalisa Minelli Jan 25 '13 at 14:50

You can do it with ArcPy.mapping:

# Project variables
arcpy.env.workspace = "[Your working directory]"
mapTemplate = "ModelDepDM.mxd"
lyrZones = "__Zone500_Rabat_DM"

# Mxd and dataframe
mxd = arcpy.mapping.MapDocument(os.path.join(arcpy.env.workspace, mapTemplate))
df = arcpy.mapping.ListDataFrames(mxd)[0]

# What I'd like to add
newSource = os.path.join(arcpy.env.workspace, lyrZones[0:-3] + _dirNum + ".shp")
result = arcpy.MakeFeatureLayer_management(newSource, lyrZones)

# Adding the result to the TOC
layer2 = result.getOutput(0)
arcpy.mapping.AddLayer(df, layer2, 'AUTO_ARRANGE')

You need to make a feature layer from your result and add it to a dataframe.

Maybe there's another way to do it, but it works for me...

share|improve this answer
1  
This script does not look like it creates routes so I am going to ask @Annalisa Minelli for more details of her code. –  PolyGeo Dec 8 '12 at 11:51
    
That's the part to add a layer to a TOC... According to Annalisa, her script creates the routes, but don't add them to the TOC... –  fgcartographix Dec 10 '12 at 16:10
    
I wanted to check what tools she used to "create" her routes. For example, she may not have followed the tips here –  PolyGeo Dec 10 '12 at 22:18
    
thanks @fgcartographix , I've got no data at the moment, but I'll try your suggestion as soon as possible. PolyGeo : I created the routes using arpcy.CreateRoutes_lr. Then I have to place some points on the routes, starting from a table. So I used the "MakeRouteEventLayer_lr", but, at that point, the command doesn't find the routes. –  Annalisa Minelli Dec 11 '12 at 8:59
    
@fgcartographix : I cannot understand what is the "newSource" since lyrZones seems not to be a list and the route is not produced in ".shp" format.. –  Annalisa Minelli Dec 13 '12 at 13:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.