I have a model which creates topology with rules and validate itself. But I got used to working with layers in TOC and have a script in Calculate value tool that with a help of Parse path tool make a string output with feature dataset path in. Here is a script:
def GetPath(lyr):
import os
mxd=arcpy.mapping.MapDocument("CURRENT")
target=arcpy.mapping.ListLayers(mxd,lyr)[0]
return target.dataSource
And here is a part of model I want to be working. enter image description here
Unfortunately, Create topology tool requires path not to some output value or variable, but probably direct file path. That is a reason for crashing of model due to the non-existance of dataset parameter.
Anyway is it possible to make an Input Feature dataset as a variable which records a path from string data? In my case it should be like %FDS%.
-
When you complete the Calculate Value tool what do you set the output type to?Hornbydd– Hornbydd2016年11月01日 11:52:29 +00:00Commented Nov 1, 2016 at 11:52
-
@Hornbydd Variant. I tried Feature Dataset, but it makes model crashing, because it still finds a path to layer, not dataset.Pavel Pereverzev– Pavel Pereverzev2016年11月01日 12:23:16 +00:00Commented Nov 1, 2016 at 12:23
-
Defining the calculate variable as Feature Dataset and removing parse path, did you try output_value for the topology in dataset?artwork21– artwork212016年11月01日 12:36:31 +00:00Commented Nov 1, 2016 at 12:36
-
@artwork21 I tried but it calculates a path to layer, not dataset.Pavel Pereverzev– Pavel Pereverzev2016年11月01日 12:42:24 +00:00Commented Nov 1, 2016 at 12:42
-
Is your GetPath(lyr) call lyr variable a string of the layer name in ArcMap?artwork21– artwork212016年11月01日 12:50:07 +00:00Commented Nov 1, 2016 at 12:50
1 Answer 1
- Set Calculate Value output to be FeatureDataset
- Remove Parse path tool
- Replace you code with the following:
def GetPath(lyr):
import arcpy,string
mxd=arcpy.mapping.MapDocument("CURRENT")
featureLayer=arcpy.mapping.ListLayers(mxd,lyr)[0]
# Get FULL path
path = featureLayer.dataSource
# Get FeatureClass name
fc = featureLayer.datasetName
# Get index position of featureclass name in full path, -1 strips off \
idx = string.rfind(path,fc) - 1
# Return FeatureDataset
return path[:idx]
- Connect tool to create Topology tool
-
everything is ok when I launch this model from model builder window. But when I launch it from the Catalog it crashes. The reason is a feature class, a path to which I calculate also through Calculate Value tool that has Feature class output. Topology is created right in Dataset I need but "Add feature class to topology" doesn't react on Calculate Value tool or something like
%Feature dataset%\tline
; it wants to add "tline" taken from the last launch of model within ModelBuilder interface.Pavel Pereverzev– Pavel Pereverzev2016年11月03日 07:46:37 +00:00Commented Nov 3, 2016 at 7:46
Explore related questions
See similar questions with these tags.