1

I don't know python so I often use ModelBuilder and export to python script. In this case, I have a model (that in itself is made of python scripts that have been exported from models) that works fine where if the precondition (ISG Template and VC Template) is false, it does not execute that branch and if true, it does.

When I export it to python script, the boolean does not exist and even if no parameters are input, the full script runs.

model that runs correctly

input parameters

Below is the python script that runs and produces an output regardless of whether the boolean is checked or not. How can I get the boolean precondition to work in Python? I'm using ArcGIS Desktop 10.6. All the parameters are optional in both the model and the python script.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Parent.py
# Created on: 2019年07月14日 16:21:30.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: Parent <ISG_Template> <Output_ISG_DWG_File> <VC_Template> <Output_VC_DWG_File> 
# Description: 
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
import os
# Load required toolboxes
arcpy.ImportToolbox("//cadd/users/steve/CADGIS/Version2019/GIStoCAD.tbx")
# Script arguments
ISG_Template = arcpy.GetParameterAsText(0)
Output_ISG_DWG_File = arcpy.GetParameterAsText(1)
VC_Template = arcpy.GetParameterAsText(2)
Output_VC_DWG_File = arcpy.GetParameterAsText(3)
# Local variables:
# Process: VC
arcpy.VC_GIStoCAD(Output_VC_DWG_File)
# Process: ISG
arcpy.ISG_GIStoCAD(Output_ISG_DWG_File)

Furthermore, below is the script with my modifications. I still doesn't work. The script runs regardless of whether boolean is checked but does not produce an output. It runs in about a second so its really not doing anything. It should take a minute.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Parent.py
# Created on: 2019年07月14日 18:31:23.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: Parent <ISG_Template> <Output_ISG_DWG_File> <VC_Template> <Output_VC_DWG_File> 
# Description: 
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Load required toolboxes
arcpy.ImportToolbox("//cadd/users/steve/CADGIS/Version2019/GIStoCAD.tbx")
# Script arguments
ISG_Template = arcpy.GetParameterAsText(0)
if ISG_Template == True:
 arcpy.ISG_GIStoCAD(Output_ISG_DWG_File)
Output_ISG_DWG_File = arcpy.GetParameterAsText(1)
VC_Template = arcpy.GetParameterAsText(2)
if VC_Template == True:
 arcpy.VC_GIStoCAD(Output_VC_DWG_File)
Output_VC_DWG_File = arcpy.GetParameterAsText(3)
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jul 14, 2019 at 21:33
0

1 Answer 1

3

The ISG_Template and VC_Template values are not Boolean values anymore, since you brought those parameters in as text using the arcpy.GetParameterAsText() function. So your conditions should most likely need to be If ISG_Template == 'true': and If VC_Template == 'true':. Add a print method after assigning the text to the variable to determine if it is storing 'true', 'True', '1', or some other text value. It looks like the values are 'true' based on your comment about using the Python snippet option, so I have made that the value in the script below.

Also you need to move the Output_ISG_DWG_File = arcpy.GetParameterAsText(1) above the if ISG_Template == 'true': and move the Output_VC_DWG_File = arcpy.GetParameterAsText(3) above the if VC_Template == 'true': Variables have to be assigned a value before they can be used in a method or function in Python.

# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# Parent.py
# Created on: 2019年07月14日 18:31:23.00000
# (generated by ArcGIS/ModelBuilder)
# Usage: Parent <ISG_Template> <Output_ISG_DWG_File> <VC_Template> <Output_VC_DWG_File> 
# Description: 
# ---------------------------------------------------------------------------
# Import arcpy module
import arcpy
# Load required toolboxes
arcpy.ImportToolbox("//cadd/users/steve/CADGIS/Version2019/GIStoCAD.tbx")
# Script arguments
ISG_Template = arcpy.GetParameterAsText(0)
Output_ISG_DWG_File = arcpy.GetParameterAsText(1)
if ISG_Template == 'true':
 arcpy.ISG_GIStoCAD(Output_ISG_DWG_File)
VC_Template = arcpy.GetParameterAsText(2)
Output_VC_DWG_File = arcpy.GetParameterAsText(3)
if VC_Template == 'true':
 arcpy.VC_GIStoCAD(Output_VC_DWG_File)
answered Jul 15, 2019 at 5:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.