I am having an issue with the GenerateTransectsAlongLines command when I try running it through an ArcToolbox script in ArcGIS Pro 2.9.3. The command runs fine at the Python Window command line and also when running manually from the Tools popup. I can run other commands from the Arcpy module via scripting no problem but I get a license error when trying to run this particular command. I have an Advanced license (which shouldn't matter as it's a basic Arcpy command). I also switched back to the default read-only Python Environment in case something might have gone corrupt in the custom environments I setup but no success. Also tried formatting the string parameters as shown below but still no success.
I extracted the relevant code from my script below:
import arcpy
Output_Workspace = arcpy.GetParameterAsText(0)
Output_Vector_GDB_Workspace = arcpy.GetParameterAsText(1)
Input_DEM = arcpy.GetParameterAsText(2)
if Input_DEM == '#' or not Input_DEM:
Input_DEM = "RawLidarDTM" # provide a default value if unspecified
Input_Watercourses = arcpy.GetParameterAsText(3)
if Input_Watercourses == '#' or not Input_Watercourses:
Input_Watercourses = "OHN WC" # provide a default value if unspecified
Input_Waterbodies = arcpy.GetParameterAsText(4)
if Input_Waterbodies == '#' or not Input_Waterbodies:
Input_Waterbodies = "OHN WB" # provide a default value if unspecified
Input_Distance = arcpy.GetParameterAsText(5)
if Input_Distance == '#' or not Input_Distance:
Input_Distance = 100 # provide a default value if unspecified
Input_Length = arcpy.GetParameterAsText(6)
if Input_Length == '#' or not Input_Length:
Input_Length = 400 # provide a default value if unspecified
# Get characteristics
descR = arcpy.Describe(Input_DEM)
descV = arcpy.Describe(Input_Waterbodies)
#Set environment variables
arcpy.env.workspace = Output_Workspace
arcpy.env.outputCoordinateSystem = descV.spatialReference # Input_DEM
arcpy.env.extent = descV.extent
arcpy.env.snapRaster = Input_DEM
arcpy.env.cellSize = str(int(4 * descR.meanCellHeight)) # For half metre lidar, recommended resolution output flattened surface is 2m to create a smoother surface and minimize noise.
# Extract Measure Units
spatial_ref = arcpy.Describe(Input_DEM).spatialReference
mUnit = spatial_ref.linearUnitName
if mUnit == "Meter":
mUnits = "Meters"
else:
if mUnit == "Foot_US":
mUnits = "Feet"
else:
arcpy.AddError("Units can only be Meters or Feet!")
sys.exit()
# Local Variables
WC_Transects = Output_Vector_GDB_Workspace + "\\WC_Transects"
mDistance = str(Input_Distance) + " " + mUnits.lower()
mLength = str(Input_Length) + " " + mUnits.lower()
arcpy.AddMessage("Generating transects along watercourse centrelines..")
arcpy.AddMessage("Units: " + mUnits + " Dist: " + mDistance + " Length: " + mLength)
arcpy.GenerateTransectsAlongLines_management(Input_Watercourses, WC_Transects, mDistance, mLength, "NO_END_POINTS")
Error message is as follows:
Start Time: June 27, 2022 12:08:57 PM
Generating transects along watercourse centrelines..
Units: Meters Dist: 100 meters Length: 400 meters
Traceback (most recent call last):
File "C:\_Workspace\Projects-2022-23\Elevation\HydroFlattening\CreateTransects.py", line 156, in <module>
arcpy.GenerateTransectsAlongLines_management(Input_Watercourses, WC_Transects, mDistance, mLength, "NO_END_POINTS")
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 21801, in GenerateTransectsAlongLines
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 21798, in GenerateTransectsAlongLines
retval = convertArcObjectToPythonObject(gp.GenerateTransectsAlongLines_management(*gp_fixargs((in_features, out_feature_class, interval, transect_length, include_ends), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000824: The tool is not licensed.
Failed to execute (GenerateTransectsAlongLines).Failed script (null)...
Failed to execute (CreateTransects).
Failed at June 27, 2022 12:08:58 PM (Elapsed Time: 0.78 seconds)
Any thoughts would be appreciated.
Thanks,
John