Select to view content in your preferred language

Pylance / VSCode linting issues with arcpy.nax module

182
2
2 weeks ago
tcrammond
Occasional Contributor

I am trying to develop some routing scripts using the arcpy.nax module, which was portrayed as being much better than the old arcpy.na module.

However, when I try to access any members of the module, Pylance complains with a "Not a known member" error.

As a tester, I copied the script on the Service Areas page, but am still having the same issue. Has anyone else run into this? I'm happy to continue developing against the older na module; however we'd like to migrate at some point.

The exact error is:

"MakeNetworkDatasetLayer" is not a known member of module "arcpy.nax" Pylance(reportGeneralTypeIssues)

Here's the code (from the docs), and the error screenshot is attached.

# An example showing how to perform service area analysis using a feature class for input facilities.
import arcpy
arcpy.CheckOutExtension("network")

nds = "C:/data/NorthAmerica.gdb/Routing/Routing_ND"
nd_layer_name = "Routing_ND"
input_facilities = "C:/data/io.gdb/Facilities"
output_polygons = "C:/data/io.gdb/ServiceAreaPolygons"

# Create a network dataset layer and get the desired travel mode for analysis
arcpy.nax.MakeNetworkDatasetLayer(nds, nd_layer_name)
nd_travel_modes = arcpy.nax.GetTravelModes(nd_layer_name)
travel_mode = nd_travel_modes["Driving Time"]

# Instantiate a ServiceArea solver object
service_area = arcpy.nax.ServiceArea(nd_layer_name)
# Set properties
service_area.timeUnits = arcpy.nax.TimeUnits.Minutes
service_area.defaultImpedanceCutoffs = [5, 10, 15]
service_area.travelMode = travel_mode
service_area.outputType = arcpy.nax.ServiceAreaOutputType.Polygons
service_area.geometryAtOverlap = arcpy.nax.ServiceAreaOverlapGeometry.Split
# Load inputs
service_area.load(arcpy.nax.ServiceAreaInputDataType.Facilities, input_facilities)
# Solve the analysis
result = service_area.solve()

# Export the results to a feature class
if result.solveSucceeded:
    result.export(arcpy.nax.ServiceAreaOutputDataType.Polygons, output_polygons)
else:
    print("Solve failed")
    print(result.solverMessages(arcpy.nax.MessageSeverity.All))

 

0 Kudos
2 Replies
MelindaMorang
Esri Regular Contributor

Hello @tcrammond.  Sorry about this.  Unfortunately many of the arcpy modules don't behave nicely with linters, for a variety of technical reasons.  I will investigate this and see what options we have for improving the experience.  However, regardless of what Pylance is telling you, the module should still work as documented when the code is run.

Could you please tell me what version of ArcGIS Pro you're running?  I know we made some improvements to arcpy.nax linting and type hinting in the 3.2 release, but it may have been in a limited area.

0 Kudos
tcrammond
Occasional Contributor

Hi @MelindaMorang , I am using Pro 3.5. 

I'm definitely still able to run the files; it's more an inconvenience than anything, and I tend to rely on linting more when exploring new patterns (such this this module).

Thanks!

0 Kudos