2

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%.

Hornbydd
44.9k5 gold badges42 silver badges84 bronze badges
asked Nov 1, 2016 at 10:30
8
  • When you complete the Calculate Value tool what do you set the output type to? Commented 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. Commented 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? Commented Nov 1, 2016 at 12:36
  • @artwork21 I tried but it calculates a path to layer, not dataset. Commented Nov 1, 2016 at 12:42
  • Is your GetPath(lyr) call lyr variable a string of the layer name in ArcMap? Commented Nov 1, 2016 at 12:50

1 Answer 1

2
  1. Set Calculate Value output to be FeatureDataset
  2. Remove Parse path tool
  3. 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]
  1. Connect tool to create Topology tool
answered Nov 1, 2016 at 16:41
1
  • 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. Commented Nov 3, 2016 at 7:46

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.