0

I have a modelbuilder parent model with two nested models in it that ouputs a dwg file. I exported the parent model to a python script which is shown below. In modelbuilder, the output dwg file is a parameter so I can define its name and location when I run it. In the python script, it does not let me set the name and location. It shows the message "this model has no parameters" when its run in Python. I would like to be able to define the output name and location but am not sure how to do this in Python. The output file is "OutputFile.dwg" in the code below.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# GIStoCAD.py
# Created on: 2014-02-27 13:15:51.00000
#   (generated by ArcGIS/ModelBuilder)
# Usage: GIStoCAD <Output_File_Name> 
# Description: 
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy

# Load required toolboxes
arcpy.ImportToolbox("/cadd1/gisusers/CADGIS/Version2014/GIStoCADv10_1.tbx")

# Script arguments
Output_File_Name = arcpy.GetParameterAsText(0)
if Output_File_Name == '#' or not Output_File_Name:
Output_File_Name = "E:\\Workspace\OutputFile.dwg" # provide a default value if unspecified

# Local variables:
Delete_succeeded = Output_File_Name
GIStoCAD_gdb__4_ = "C:\\GIStoCAD.gdb"
V_PROP_LINE_PGCO = "C:\\GIStoCAD.gdb\\V_PROP_LINE_PGCO"
V_PROP_LINE_MOCO = "C:\\GIStoCAD.gdb\\V_PROP_LINE_MOCO"
V_BLDG_OUTL_PGCO = "C:\\GIStoCAD.gdb\\V_BLDG_OUTL_PGCO"
V_BLDG_OUTL_MOCO = "C:\\GIStoCAD.gdb\\V_BLDG_OUTL_MOCO"
V_ROAD_ASPH_PGCO = "C:\\GIStoCAD.gdb\\V_ROAD_ASPH_PGCO"
V_ROAD_ASPH_MOCO = "C:\\GIStoCAD.gdb\\V_ROAD_ASPH_MOCO"
V_SSWR_PIPE = "C:\\GIStoCAD.gdb\\V_SSWR_PIPE"
V_WATR_PIPE = "C:\\GIStoCAD.gdb\\V_WATR_PIPE"
V_WATR_STRC = "C:\\GIStoCAD.gdb\\V_WATR_STRC"
V_SSWR_MHOL__3_ = "C:\\GIStoCAD.gdb\\V_SSWR_MHOL"
V_WATR_INST = "C:\\GIStoCAD.gdb\\V_WATR_INST"

# Process: Setup
arcpy.gp.toolbox = "//cadd1/gisusers/CADGIS/Version2014/GIStoCADv10_1.tbx";
# Warning: the toolbox //cadd1/gisusers/CADGIS/Version2014/GIStoCADv10_1.tbx DOES NOT have an alias. 
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.Setup3(...) with arcpy.Setup3_ALIAS(...)
arcpy.gp.Setup3(GIStoCAD_gdb__4_, V_PROP_LINE_PGCO, V_PROP_LINE_MOCO, V_BLDG_OUTL_PGCO, V_BLDG_OUTL_MOCO, V_ROAD_ASPH_PGCO, V_ROAD_ASPH_MOCO, V_SSWR_PIPE, V_WATR_PIPE, V_WATR_STRC, V_SSWR_MHOL__3_, V_WATR_INST)

# Process: Export
arcpy.gp.toolbox = "//cadd1/gisusers/CADGIS/Version2014/GIStoCADv10_1.tbx";
# Warning: the toolbox //cadd1/gisusers/CADGIS/Version2014/GIStoCADv10_1.tbx DOES NOT have an alias. 
# Please assign this toolbox an alias to avoid tool name collisions
# And replace arcpy.gp.Export3(...) with arcpy.Export3_ALIAS(...)
arcpy.gp.Export3(Output_File_Name, "C:\\GIStoCAD.gdb\\V_PROP_LINE_PGCO;C:\\GIStoCAD.gdb\\V_PROP_LINE_MOCO;C:\\GIStoCAD.gdb\\V_BLDG_OUTL_PGCO;C:\\GIStoCAD.gdb\\V_BLDG_OUTL_MOCO;C:\\GIStoCAD.gdb\\V_ROAD_ASPH_PGCO;C:\\GIStoCAD.gdb\\V_ROAD_ASPH_MOCO;C:\\GIStoCAD.gdb\\V_SSWR_PIPE;C:\\GIStoCAD.gdb\\V_WATR_PIPE;C:\\GIStoCAD.gdb\\V_WATR_STRC;C:\\GIStoCAD.gdb\\V_SSWR_MHOL;C:\\GIStoCAD.gdb\\V_WATR_INST")

# Process: Delete
arcpy.Delete_management(GIStoCAD_gdb__4_, "")
3

It sounds like you have not defined any parameters. Right-click on the tool in your toolbox, go to properties, and go to the Parameters tab. Do you have any parameters defined?

  • On the modelbuilder model, I do have the parameter set under properties-->parameters. One the exported python script (which is in the same toolbox), there are no parameters set under properties. Do I need to add one for the python script under parameters? – Steve Feb 27 '14 at 19:26
  • Yes, see the link in @Craig's answer. You'll probably need to use the type "CAD Drawing Dataset" – Barbarossa Feb 27 '14 at 19:30
  • FWIW, the easiest way to add parameter is to add them under properties > parameters. – Barbarossa Feb 27 '14 at 19:35
  • Barbarossa, thank you! The properties-->parameters did the trick :) – Steve Feb 27 '14 at 20:39
1

I believe the first line after the toolbox import statement is what is tripping up your script. It is looking for input parameters from a script tool interface:

Output_File_Name = arcpy.GetParameterAsText(0)

Comment out that line and the following line and you will be good to go:

#Output_File_Name = arcpy.GetParameterAsText(0)
#if Output_File_Name == '#' or not Output_File_Name:
Output_File_Name = "E:\\Workspace\OutputFile.dwg" # provide a default value if unspecified
  • Hi Jason, thank you for the response. I commented out those two lines but its still says "This tool has no parameters" – Steve Feb 27 '14 at 19:10
  • Are you running this as a script tool or as a stand-alone script? – Jason Feb 27 '14 at 19:26
  • Its running as a script tool. – Steve Feb 27 '14 at 19:26
  • Ok, in that case my answer is not valid as you'll need the GetParameterAsText() function to fetch user input from the tool. See @Barbarossa's answer instead... – Jason Feb 27 '14 at 19:29
1

This link from the ArcGIS Help on defining parameters in a python toolbox should get you started. Sounds like you'll need to setup a python toolbox and define the parameters within that.

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.