# Shortest path with Python

**URL:** <https://discourse.mcneel.com/t/shortest-path-with-python/160940>\
**Category:** Scripting\
**Tags:** windows, rhinocommon, python, grasshopperrhino\
**Created:** [June 3, 2023, 1:22pm UTC](https://discourse.mcneel.com/t/shortest-path-with-python/160940 "2023-06-03T13:22:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [June 3, 2023, 1:22pm UTC](https://discourse.mcneel.com/t/shortest-path-with-python/160940/1 "2023-06-03T13:22:43Z")

</div>

Hi  
In this example i find the shortest path using **Short Walk plugin**  
Is there a way to find this path with python ?

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/8/6/4869873078811703d6ab4194bd607b70578989f5.png)

[find\_path.gh](https://discourse.mcneel.com/uploads/short-url/xAdMmFEmE6JAJmj3wKLDO2jmLJR.gh) (20.2 KB)

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [June 3, 2023, 2:12pm UTC](https://discourse.mcneel.com/t/shortest-path-with-python/160940/2 "2023-06-03T14:12:10Z")

</div>

You can implement `networkx`. Here’s a recent example:

> [@Shortest path - taking obstacles and the terrain into account](https://discourse.mcneel.com/t/shortest-path-taking-obstacles-and-the-terrain-into-account/141786/18):
>
> FWIW, it’d be pretty trivial to add slope angle as the edge weight to this [MeshPaths](https://github.com/AndersDeleuran/MeshAnalysis/blob/master/src/MeshPaths.py) GHPython component I once wrote (i.e. add another weightMode to the two functions that generate the graph), which implements networkx for the graph computation. You can download the 1.5 version [here](https://discourse.mcneel.com/t/explenation-of-adding-extra-libraries-to-gh-python-standard-content/80385/5) and unzip it to: C:\Users\USERNAME\AppData\Roaming\McNeel\Rhinoceros\7.0\scripts Edit: Here’s a quick implementation of what I was suggesting above. I also added a Smoothen input, which iteratively averages the pa…

Or implement e.g. Dijkstra’s shortest path natively. Example here:

> [@Python Shortest Walk 3D: Interpolate grid of points with start & end point to get shortest curve thorough points of grid](https://discourse.mcneel.com/t/python-shortest-walk-3d-interpolate-grid-of-points-with-start-end-point-to-get-shortest-curve-thorough-points-of-grid/80333/29):
>
> Hi @STUDENT_F, Here’s a GHPython implementation of Dijkstar’s Shortest Path algorithm I wrote awhile back. It should work with multiple start and end points in 2D as well as in 3D space. The graph connections are evaluated beforehand by a separate component. The connections are evaluated by proximity. A higher radius means more possible connections. Feel free to check it out below. [dijkstra\_v2.gh](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/d/b/db6e2971fbc9c591176ae5e2dd08d6cc22df773f.gh) (36.0 KB)

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [June 3, 2023, 3:31pm UTC](https://discourse.mcneel.com/t/shortest-path-with-python/160940/3 "2023-06-03T15:31:30Z")

</div>

Thanks @AndersDeleuran

I want avoid python modules.  
Short walk plugin works faster and if there is no other choice i will keep using it
