1

I have a model which adds and calculates a new field with a workspace path. I upload only one layer from database to the model (called "tline"). Parse path can detect only the name and file of this layer, not the whole path to the GDB file which contains this layer. The path can be found only if I add a workspace variable and set the path to database in this variable. So when I set a parameter "Parse type" like "Path" for "tline" layer, model won't work, it just add a new field and says that "The process did not execute because the precondition is false."

enter image description here

How can I find the path to GDB automatically using model builder? It is also important when I have several GDB files that have the same layer "tline" within. I just want to overcome a manual input of GDB file into the model.

12
  • What is the relationship between the model and the tool dialog that you have pictured? They do not appear to correspond to each other.
    – PolyGeo
    Commented Aug 16, 2016 at 0:45
  • If you have python knowledge you can insert a script to find the path using os.path
    – jbalk
    Commented Aug 16, 2016 at 4:26
  • @PolyGeo It has no relationshps, I just want to show that often you need to put a workspace variable and make the path to GDB file manually. I think with some Arcmap tools this process can be simplified. Commented Aug 16, 2016 at 5:26
  • @jbalk Unfortunately I have no any knowledge of Py. Moreover, I make this model for several computers with other users, and if I am not mistaken Python script file should be on their computer too to import it properly to the model. I think it'sa bit complicated thing. Commented Aug 16, 2016 at 5:28
  • 2
    I'm trying to understand what it is that you are asking. I think when you say the view (called "tline") you are meaning a layer called "tline", and wanting to be able to access the source of that layer (presumably a file geodatabase feature class) and then to parse the path of that to get its file geodatabase.
    – PolyGeo
    Commented Aug 16, 2016 at 7:12

2 Answers 2

3

After seeing your conservation with @GISGE, though reluctantly, I have decided to put in my two cents. I do not think there is a direct way of getting file path of a layer's data source from given Model Builder tools. However you can use Calculate Value tool to get the required parts. Assuming you are always going to use LAYERs from your MXD's TOC, the setup below should work.

enter image description here

The difference here, Parse Path is not connected to your input layer and output_value is a precondition to Add Field to make sure Calculate Value will run before anything. The trick is to input the code very below into this tool as shown below.

enter image description here

And here is the code:

Expression

GetPath("%tline%")

Code Block

def GetPath(lyr): import os mxd=arcpy.mapping.MapDocument("CURRENT") target=arcpy.mapping.ListLayers(mxd,lyr)[0] return target.dataSource

ASSUMPTIONS

  • this works only with LAYERs from your CURRENT (the map document which is already open and where your model is open in editing mode) MXD's TOC
  • if there are more than two layers with the same name, this will get the first instance in the order of display
  • it will only work with layers which support dataSource property (essentially the feature and raster layers are just safe)
2
  • @faih_dur, heeey everything works fine!!! Thnak you so much. However, when I add Calculate field tool, it makes one mistake: instead of D:\Документы\АСПИР\ОФОРМЛЕНИЕ\test.gdb it makes D:\Документы\АСПИР\ОФОРМЛЕНИЕest.gdb I typed '%Value%' and used Python 9.3 Commented Aug 16, 2016 at 20:42
  • Try r"%Value%". Also have a look at gis.stackexchange.com/questions/63816/….
    – fatih_dur
    Commented Aug 17, 2016 at 3:31
0

First make sure you drag-and-drop the input feature class into your model from the Catalog Window or ArcCatalog, and not as a layer from ArcMap's TOC. Otherwise the path property (and extension) can't be retrieved.

Then use the expression '%Value%' with the PYTHON parser in the Calculate Field:

enter image description here

Make sure your new field is long enough to hold the dataset's path (the default 50 characters might not be enough).

8
  • I don't think tline in the asker's case is a dataset like in your answer. I think it is a layer.
    – PolyGeo
    Commented Aug 16, 2016 at 8:25
  • yes, it is a layer, containing in Gdb file. Commented Aug 16, 2016 at 8:31
  • A layer (in your display or in memory) is a view, or a representation of a feature class (i.e. a dataset saved on your disc - in a gdb or in a folder). So do you want to access the layer in ArcMap's TOC, or the feature class? How are users supposed to use your model?
    – GISGe
    Commented Aug 16, 2016 at 8:34
  • @GISGe In this case I need to get an access to feature class, from path of which I need only the path to *.gdb file, not the whole path to feature class. Other users are going to test my model which find roads that are torn by other ones of lower levels (in case someone made a mistake during attribute edition). The model I made is working without mistakes but I think that it would be better not to click hundred times to set a path to base, because there are lots of levels to check. I thought about drag'n'drop function to dialog box of model but it appeared to be impossible in modelbuilder Commented Aug 16, 2016 at 8:49
  • If you choose the PATH option in the Parse Path tool, you will get the path to the gdb (e.g. C:\data\mygdb.gdb). The rest of your comment is not clear to me, sorry.
    – GISGe
    Commented Aug 16, 2016 at 8:56

Your Answer

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

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