curtvprice

How to find tbx path in Calculate Value tool

Discussion created by curtvprice Champion on May 16, 2013
It was mentioned on the forum that a nifty way to keep Calculate value code from filling the geoprocessing message screen is to write functions in a separate Python script and import them. If you want to do ship a model builder tool that includes such a module, you would need to calculate a path relative to the toolbox.

So here is today's puzzler: is there a way to access the current model's tbx path? I've tried a few methods with no success:

Expression: f()

Code block: 
import sys
import os
def f():
  return (chr(10) + chr(10) + 
    "sys.argv[0]: " + sys.argv[0] + chr(10) +
    "os.path.realpath(os.curdir): " + os.path.realpath(os.curdir) + chr(10) +
    "__file__: " + __file__ +
    chr(10) + chr(10))


displays:

sys.argv[0]:
os.path.realpath(os.curdir): D:\Users\cprice\work\UGuide
__file__: <string>


os.path.realpath(os.curdir) does not update when I copy/paste the model somewhere new! Seems to be the mxd working folder, not the tbx folder?

Outcomes