Using Python to find the owner of a file

I need to find a way to easily tell who created a Rhino model, without having to use Windows Explorer, right click on the file, pick Properties, Security, Advanced. I would like to do it with a script that reads the file that is currently open. I’ve tried Google, but all of the examples I’ve found so far require importing modules that don’t appear to be available.

Any suggestions would be appreciated.

Thanks,

Dan

I can’t tell if you want to do this from inside or outside of Rhino and so not sure if you can use this, but perhaps the Audit3dmFile helps?

It will tell you who created the file and who was the last to edit it. You can run it and pick any file - also the file that is currently open.

Hmmm… Didn’t know about this command. I see that it browses to a file, but you mentioned that it can audit the currently opened file. How do I do that? That’s really what I’m after.

Thanks,

Dan

Ha! Well, then you just use the AuditCurrent command…
:wink: (I’ve never used that command before now…)

I don’t have that in 6.5.

Me neither in the 6.6 RC…

Hi @DanBayn,

the File3dm class has a CreatedBy property which you could use. Note the LastEditedBy property as well.

_
c.

Hi Clement,

This is something I can use with Python? Seems to be exactly what I’m looking for if I can make it work.

Thanks,

Dan

Hi Dan, this should work:

import Rhino
import scriptcontext
import rhinoscriptsyntax as rs

def DoSomething():
    
    file_path_name = rs.DocumentPath()
    if not file_path_name: return
    if len(file_path_name) == 0: return
  
    f = Rhino.FileIO.File3dm.Read(file_path_name)
    print "CreatedBy:", f.CreatedBy
    print "LastEditedBy:", f.LastEditedBy
    
DoSomething()

note that on larger files, even when already opened, reading the file can take a while.

_
c.

1 Like

Unnnnnrelated answer:

Security descriptor (as is saved in a hidden stream named $SDS) is disposed when you move/copy between NTFS/non-NTFS filesystem; often disposed when you copy between computers. It is even less reliable than getting the current username.

Hi Clement,

Very helpful, as usual.

Thanks,

Dan