Rs. or Rhino. DocumentPath()

There is a difference between how vb Rhinoscript and Python rhinoscriptsyntax work here… VB returns just the path to the folder where the document is located, whereas Python returns the path plus the file name in one string. Both also have the command DocumentName to get just the filename.

Problem is if one wants just the folder, it’s a bit more difficult to get at in Python - something like:

folder=rs.DocumentPath()[:-len(rs.DocumentName())]

In VB to get the full path to the document including the name you just concatenate Rhino.DocumentPath and Rhino.DocumentName…

Wonder if a switch can’t be added in Python rhinoscriptsyntax:

rs.DocumentPath(append_filename=True/False) (default - True)

??

–Mitch

Hi Mitch,
It should probably be consistent between Rhinoscript and Python. In the meantime if you need to do a lot of path or file name parsing you might find the System.IO.Path class useful:

http://msdn.microsoft.com/en-us/library/System.IO.Path(v=vs.110).aspx

for example:
directory_name = System.IO.Path.GetDirectoryName(rs.DocumentPath() or None)

Yep, I agree. @Alain, can you add a big to youtrack for me to fix this in python? I’m away from my computer at the moment.

OK, thanks guys, I only suggested adding a switch in Python so as to possibly not invalidate existing scripts using that method… If it’s the same between the vb rhinoscript and Python it’s even better as far as I’m concerned…

–Mitch

Hi @stevebaer,

Here it is: RH-27617

I also fixed it but I’m just noticing now that you said “for me to fix”.

I added ‘’ or ‘/’ at the end of the path to be consistent with RhinoScript but I guess that wouldn’t matter when using:
full_path = System.IO.Path.Combine(directory_name, file_name)

Thanks for fixing it Alain. I wouldn’t add the optional parameter. If we do, we will need to update the documentation.

Changes have been made in the code. rs.DocumentPath() and rs.DocumentName() now work just like in RhinoScript. This also means that when in a new/unsaved document the methods return null.