I'm writing a script tool to run multiple processes. See below:
Two problems. I was able to get the for loop to run before adding the if else statement. I need the loop to do extra steps if it is a polyline feature where as if it is a point or polygon it only needs to do the one process (Locate Features). Right now when I run it I just get invalid syntax.
Second, I am able to get this script to work if my arcpy.env.workspace = "C:\ExamplePath\" but when trying to use the Get Parameter As Text the for loop will not run. It thinks there is no data where I tell it there is.
Any help will be greatly appreciated!
Solved! Go to Solution.
Two easy changes to get your IF block to work:
1. You only need to do the Describe once; it returns a Describe object from which you can get the basename and feature type, rather than repeatedly returning to the feature class.
2. Use the ShapeType property of the Descibe object to determine if it's a polyline feature class.
Your IF block would start like this:
for fc in features: Desc = arcpy.Describe(fc) if Desc.shapeType == "Polyline": outFC = Desc.baseName + "INT.shp" outFC2 = Desc.baseName + "INT_sp.shp" # and so on....
Two easy changes to get your IF block to work:
1. You only need to do the Describe once; it returns a Describe object from which you can get the basename and feature type, rather than repeatedly returning to the feature class.
2. Use the ShapeType property of the Descibe object to determine if it's a polyline feature class.
Your IF block would start like this:
for fc in features: Desc = arcpy.Describe(fc) if Desc.shapeType == "Polyline": outFC = Desc.baseName + "INT.shp" outFC2 = Desc.baseName + "INT_sp.shp" # and so on....
This cleared up my invalid syntax but I am continuing to get this traceback
Traceback (most recent call last):
File "C:\Python27\ArcGIS10.7\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\GIS\Python\CROSSING_TABLES\CROSSING_TABLES.PY", line 8, in <module>
for fc in features:
TypeError: 'NoneType' object is not iterable
Actually I just ran it through the script tool and it worked perfectly! Thanks so much for your help!