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

  • When you complete the Calculate Value tool what do you set the output type to? – Hornbydd Nov 1 '16 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 Nov 1 '16 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 Nov 1 '16 at 12:36
  • @artwork21 I tried but it calculates a path to layer, not dataset. – Pavel Pereverzev Nov 1 '16 at 12:42
  • Is your GetPath(lyr) call lyr variable a string of the layer name in ArcMap? – artwork21 Nov 1 '16 at 12:50
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
  • 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 Nov 3 '16 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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