0

In Modelbuilder, I am trying to implement a condition regarding the type of workspace:

  • if this is a GDB, the output FC should not have an Extension
    (%Scratch%\Nodes_%NameFC%)
  • If this is a Folder, the FC Output should have one. (%Scratch%\Nodes_%NameFC%.shp)

So far, I built this thinking to use it somehow as a variable to add an extension to the OutputFC if needed.

  • In the first case, the returned value is 1, which is "wrong" because the Output Workspace is a fgdb and in the code block, 1 is supposed to be False.
  • In the second case, it's not returning anything as the Output Workspace doesn't have any Extension.
  • There is a message (when running the first set) ERROR 000539: Error running expression: gdb (...) name 'gdb' is not defined

enter image description here

Does anyone know what is going on here?

2

Consider testing against the workspace type property.

In your calculate value tool (you only need one for this step), modify your code to look something like this:

import os, arcpy
def workspace_type(wkspace,fc_name):
    wt = arcpy.Describe(wkspace)
    if wt.workspaceType == "FileSystem": #folder
       return os.path.join(wkspace,"{0}.shp".format(fc_name))
    elif wt.workspaceType == "LocalDatabase": #local geodatabase
       return os.path.join(wkspace,fc_name)
  • OK, that worked really well. I've adapted it to my variables – PMessager Apr 19 '16 at 9:43
  • change "wkspace" into the name of the variable Workspace existing in the model, linked the Workspace to the "Calculate value" as Environnement Setting "Current Workspace". Is that how it should be done? – PMessager Apr 19 '16 at 9:49
  • wkspace is the same as "OUT_DIR" (full workspace path) in the sample model you provided above. – Nxaunxau Apr 19 '16 at 9:53

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.