# Finding Model/Tool name in custom Toolbox via ArcPy/Python?

We have a folder housing all custom Toolboxes/Models for our schema updates. We are attempting to automate these Toolboxes in upper environments. The initial problem is, I am unsure what Model name people are going to use.

How can I extract the Model name with Arcpy/Python then use this information with ap.GetParameterInfo?

The goal is to reset one required parameter in each environment.

Current failing code base:

import os
import arcpy as ap

_dir = r'D:\foo\bar' # folder with all the toolboxes

_lsdir = os.listdir(_dir)

for _tbx in _lsdir:
_tb = ap.ImportToolbox("{0}\{1}".format(_dir, _tbx), "fakealias")
print _tbx, _tb
_p = ap.GetParameterInfo(_tb)
for p in _p:
print p.name, p.parameterType, p.value


Current Error output:

20190419_AddFC.tbx 'module 'fakealias' (built-in)'


I've successfully printed the ap.GetParameterInfo from a single Toolbox but only when hardcoding the Model name. This will not work long term.

Code formatting did not take on original publish.

    import os
import arcpy as ap

_dir = r'D:\foo\bar' # folder with all the toolboxes

_lsdir = os.listdir(_dir)

for _tbx in _lsdir:
_tb = ap.ImportToolbox("{0}\{1}".format(_dir, _tbx), "fakealias")
print _tbx
for _t in dir(_tb):
if "__" not in _t:
print _t
_p = ap.GetParameterInfo(_t)
for p in _p:
print p.name, p.parameterType, p.value

• try a raw string (forward slashes are generally bad unless you want escape characters): ap.ImportToolbox(r"{0}\{1}".format(_dir, _tbx), "fakealias") – Paul H Apr 23 at 17:43
• I tested your suggestion and result is the same error. Even switching to '/' fails. – sstewart324 Apr 23 at 18:06
• Use os.path.join to combine your paths instead of format. – BERA Apr 23 at 18:20
• I tested your suggestion, results are the same. I'm thinking there has to be a step in between the getting "_tb" and GetParameterInfo. All the ESRI documentation shows a string value in GetParameterInfo("modelname"). – sstewart324 Apr 23 at 18:36

You can use a built in like dir to achieve your goal. You'll probably want to skip the dunder functions (if __ not in name):
for t in dir(_tb):