Use a package structure. __init__.py
can hold your package scope variables. The package modules can access those variables easily, calling scripts can set them if they need to and everything is all nicely wrapped up in a single directory.
e.g.
# | mainscript.py
# \--somepackage
# | __init__.py
# | script1.py
# | script2.py
#----------------------------
#mainscript.py
#----------------------------
import somepackage
#set some variables
somepackage.args=['a','b','c']
somepackage.kwargs={'d':1,'e':2,'f':3}
#Call some functions
somepackage.script1.main()
somepackage.script2.main()
#----------------------------
#somepackage.__init__.py
#----------------------------
__all__=['script1','script2']
import script1,script2
#Some defaults
args=[]
kwargs={}
somevar=1
anothervar=2
#----------------------------
#somepackage.script1.py
#----------------------------
import somepackage
def main():
print somepackage.args
print somepackage.somevar
#----------------------------
#somepackage.script2.py
#----------------------------
import somepackage
def main():
print somepackage.kwargs
print somepackage.anothervar
Odds are it has finished, and finished properly.
You don't have any outputs on your tool, thus the script tool wont return anything to your ArcMap session.
In most Trace models/scripts I've seen, you need to Select Data to pull out whatever child element you want, then its good to run Copy Features on that item. The output of CopyFeatures should be passed into one more variable you need to define on the Parameters page you've shown. You can set it as a derived output if you're handling the output location of the data in your script.
Model
See the picture of the model here where you can see Select and Make Feature Layer after the Trace tool (but dont use Make Feature Layer, use Copy Features). Note that the Select tool is a ModelBuilder ONLY tool. The workflow is different in Python.
Python
To select an item out of the group layer, you need to have prior knowledge of what it's name will be. The below code shows you can list the sub items of a group layer to get their name. Having prior knowledge of the names, you just need to build up a path to the output using traceName/subLayerName
. (arcpy.mapping code is only added for reference to print out all available item names, in practice you probably wouldn't add this to a production tool)
arcpy.Snap_edit(Flags, "'Primary OH Conductor' VERTEX '30 Meters'")
arcpy.TraceGeometricNetwork_management(El_Paso_Electric, "Storm_Net", Flags, "TRACE_UPSTREAM", "", "", "", "", "", "NO_TRACE_ENDS", "TRACE_INDETERMINATE_FLOW", "", "", "AS_IS", "", "", "", "AS_IS")
network = arcpy.mapping.Layer("Storm_Net")
if network.isGroupLayer:
for sublayer in network:
arcpy.AddMessage(" {} ".format(sublayer.name))
# Process: Select Data
#arcpy.SelectData_management("Storm_Net", "ServiceLocation") # <--- dont use
# Build up the path to the item you want, in this case, "Storm_Net" is my output Trace, and "ServiceLocation" is the item inside I want.
arcpy.CopyFeatures_management("Storm_Net/ServiceLocation", outputFeatureClass)
Best Answer
When you call a script tool it behaves just like any other geoprocessing tool you call from Python. No messages are automatically added to the console (unless there is an unhandled exception).
What you want to do is use arcpy.GetMessages() and arcpy.AddMessage, AddWarning, AddError, etc. after calling the script tool as described in the help.