Select to view content in your preferred language

Running a Model from A model in Python

97
2
2 weeks ago
TaiDuong
Emerging Contributor

Trying to run a Model from a Model by exporting to Python. It's been painful so far but I'm close. One last issue. My Model runs ok and when called from a Master Model it also runs fine. BUT when I export a Python file, then edit to make it overwrite (arcpy.env.overwriteOutput = True) and then paste the script in the Python window I get the following.

 

 

# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2025-01-20 10:35:23
"""
import arcpy
from DaylightFP.DaylightFPx1 import DaylightFPx1

def MasterModelFP(): # MasterModelFP

# To allow overwriting outputs change overwriteOutput option to True.
arcpy.env.overwriteOutput = True

main_multipolygons_2_ = "main.multipolygons"
main_lines_2_ = "main.lines"

# Process: DaylightFPx1 (2) (DaylightFPx1) (DaylightFP)
World_8_5_32_98_FP_shp_2_ = "D:\\ESRI-Daylight\\NCERTS_1.0\\World_8_5\\World_8_5_32_-98_FP.shp"
DaylightFPx1(Output_Shapefile=World_8_5_32_98_FP_shp_2_, Input_Polygons=main_multipolygons_2_, Input_Lines=main_lines_2_)

if __name__ == '__main__':
# Global Environment settings
with arcpy.EnvManager(scratchWorkspace="C:\\ArcGIS_Scratch\\NXTScratch.gdb", workspace="C:\\ArcGIS_Scratch\\NXTScratch.gdb"):
MasterModelFP()
Traceback (most recent call last):
File "<string>", line 6, in <module>
ModuleNotFoundError: No module named 'DaylightFP'

 

I'm sure it's something very simple but I'm at a loss. Help !

 

0 Kudos
2 Replies
CodyPatterson
MVP Regular Contributor

Hey @TaiDuong 

Python  cannot find the DaylightFP module that you're attempting to reference seemingly. If it is in the same location, you may have the import incorrect or different, try this here instead as well:

from DaylightFP import DaylightFPx1

Cody

0 Kudos
DavidSolari
MVP Regular Contributor

If you want to run another model (or script tool) using arcpy, use the Import Toolbox function to add the model's toolbox, then run it like so: arcpy.toolbox_label.ModelName(param1, param2). Toolbox items aren't accessible as Python modules and trying to call an exported script file directly is possible, but error prone without practice.

0 Kudos