Help with PathOfTravel using RevitAPI

Hi I am new to Revit and Dynamo Scripting,

Currently in a project where the system is capable of creating pathways and hallways in a BIM model just from the start and end points from the user. See I am aware that is system is possible by using the PathOfTravel Tool available in Revit, But what am trying to achieve is a system where the path of travel lines are made of 90 degree lines only. Path Of Travel tool typically finds the best and the shortest route and doesn’t mind about the angles of the lines. So iterative system using python scripting where the program runs until it figures it if the path of travel lines that are present only contain straight lines only. I was able to receive some help in getting the vectors from the path of travel and was even able to make few of the lines straight but the issue would be that I would need to insert way points within the lines to make them straight. Inserting way points using the existing nodes are fairly simple but I need them to be present in a python script so I could make the system be iterative and provide with fairly correct result.

The issue is that for the python script I was able to declare the necessary libraries from the revit api in the python script and apparently the insert way point function requires the waypoint location and index but declaring them in the script shows up with an error and saying that the arguments are incorrect.

This is how I declared it: waypoint = PathOfTravel.InsertWaypoint(“chosen point”,“index”)

I am awaiting for an response please help!!!

@abishek12354 ,

you can check this, maybe there are similarities

Is your chosen point a Revit XYZ object? If you are using the Dynamo geometry library you will have to convert it first. Best to share your code for review if not (or if you need help converting this specific data type).

The chosen point is a Autodesk Geometry Point and weirdly it started to work on its own but currently I am facing issues with the update function as it provides with an type error where the no methods matches the given argument

Path.InsertWayPoint(Point.ByCoordinates(100,-100,0),0)
status = Path.Update()

The error is:
image

Can you post some reproducible code? It’s quite a lot of work to build a Revit model to make a path and find a point to add, then build a your code with no more than a reference to your api call, and then finally start to debug.

@jacob.small Here is the python script:

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('RevitAPI') 
from Autodesk.Revit.DB.Analysis import *

# The inputs to this node will be stored as a list in the IN variables.
# Place your code below this line
travel = IN[0]  
counter = 1  

for paths in travel:
    tx = (10000 * counter + 1000);
    temp = Point.ByCoordinates(tx, 1000, 0)
    paths.InsertWayPoint(temp, 0)
    status = paths.Update()
    counter = counter + 1
OUT = 0

The python script just requires a path of travel element, select a path of travel element and attach to the Input 0 of the python script. Make sure your path of travel element is in a list.

Awaiting for your response!!!

1 Like

I’m finishing a PowerPoint and some prep work for a meeting Monday. Soon as that’s done I’ll review this.

1 Like

Hi,
Update() is a static method

Instead of
status = paths.Update()
try

import System
from System.Collections.Generic import List, IList, Dictionary
array_PathOfTravel = PathOfTravel.Update(path)

image

1 Like

@c.poupin it still provides with the same issue, but still thank you for your input

with same error message ?

@c.poupin Yes it presents with the same issue

@c.poupin It also provides this error message:


This is one appears because the system module is not present.

This one appears as soon as you remove the import and from lines

If I replace the status line with this one:
status = PathOfTravel.Update(paths)
An Object does not match target type error appears!!

This worked for me in Revit 2023.1 using the CPython, IronPython2, and the as of yet unofficial IronPython3 engine.

Think there was a miss in implementing the code from @c.poupin - likely skipped adding System to the clr causing the import to fail; either way that isn’t required if you update the paths in time with adding the waypoints.

import clr

# Import geometry conversion library
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.GeometryConversion) 

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import XYZ
from Autodesk.Revit.DB.Analysis import PathOfTravel

#Get the active document
doc = DocumentManager.Instance.CurrentDBDocument

# Input and unwrapping 
paths= UnwrapElement(IN[0])
pnts = IN[1]

# Start Transaction 
TransactionManager.Instance.EnsureInTransaction(doc) #NOTE: even if a transaction isn't required for modifyign the document, you want it to be here to prevent corruption, and ensure longevity of the code base (it's likely to be a requiement someday).
for path, pnt in zip(paths,pnts): #for each path and point pair
	pnt = pnt.ToXyz() #convert the Dynamo point to a Revit XYZ. If you're builidng your points as native XYZ you can skip this, but you'll have to do the work somewhere else instead.
	path.InsertWaypoint(pnt,0) #insert the waypoint at index 0 - you likely want to be a bit smarter than this
	PathOfTravel.Update(path) #update the path of travel
# End Transaction
TransactionManager.Instance.TransactionTaskDone() 
OUT = paths 
2 Likes

Thankyou @jacob.small for your help and your solution worked perfectly :slight_smile:

1 Like