If I start with the python 2 note, I get an error “System.IO object has no attribute DriveInfo”
If I start with the python 3 note, the DriveInfo stuff is missing from the Intellisense but it compiles
#! python 2
import System
drives = System.IO.DriveInfo.GetDrives()
for drive in drives:
print(drive)
Hi @williamjb741
WMI can display tons of information about the user machine and can be quite useful for HWID lock on licenses and such, It also comes quite handy in your specific use case.
import os
import clr # Import the Common Language Runtime
clr.AddReference('System.Management') # Add reference for WMI access
from System.Management import ManagementObjectSearcher
def get_drive_info():
searcher = ManagementObjectSearcher('SELECT * FROM Win32_LogicalDisk')
for disk in searcher.Get():
drive_letter = disk['DeviceID']
drive_type = get_drive_type(disk['DriveType'])
free_space = disk['FreeSpace']
size = disk['Size']
print("Drive:", drive_letter)
print(" Type:", drive_type)
if free_space:
print(" Free Space:", free_space)
if size:
print(" Total Size:", size)
print()
def get_drive_type(type_number):
types = {
0: "Unknown",
1: "No Root Directory",
2: "Removable Disk",
3: "Local Disk",
4: "Network Drive",
5: "Compact Disc",
6: "RAM Disk"
}
return types.get(int(type_number), "Unknown")
if __name__ == "__main__":
get_drive_info()
Ah, turns out I’m on 8.3, but I have the evaluation copy for now, and it considers itself up-to-date. But it sounds like they’ve already ironed this out. So that’s good to hear.
We hope to make 8.4 the official service release tomorrow (Feb 13). Slightly after that you should be able to get an update for your evaluation version.
Steve, I just wanted to let you know that I have 8.4 now, but I still get the same error. I’m not expecting you to fix it or anything, but I’m just letting you know in case it matters somehow. Also, the DriveInfo attribute is missing from the intellisense as well (but only in Rhino 8, not when I code in Rhino 7).
Hopefully I can get some version of Farouk’s solution working somehow.
Seems like under dotnet core, the DriveInfo class is in the System.IO.FileSystem.DriveInfo assembly, so let’s reference that. I was able to replicate the issue you have in Rhino (dotnet core) and it works when reference to this library is added. If you run Rhino (dotnet framework) adding the reference will not be necessary.
#! python 2
import System
import clr
clr.AddReference("System.IO.FileSystem.DriveInfo")
drives = System.IO.DriveInfo.GetDrives()
for drive in drives:
print(drive)
Python 3 engine works slightly differently. It sees System.IO.FileSystem.DriveInfo being loaded at runtime and it captures the types. I see that python 3 does not autocomplete this.
I am able to get it working by adding the reference as you show (thank you).
But, and I’m just curious, what do you mean by “running Rhino (dotnet framework)”? I have Rhino open and am making/running these scripts in Rhino’s script editor; so, in my mind I’m runnng Rhino already. But do you mean something else?
Also, in case it matters somehow for your ticket, this System.IO.DriveInfo thing works fine and autocompletes fine on my PC in Rhino 6 and Rhino 7. It’s only in Rhino 8 that I have a problem. Same PC, just different versions of Rhino.
Fortunately, it looks like that clr reference thing works in Rhino6, Rhino7, and Rhino8, which is what I need since this is part of a little kit I sell to people who might have any version of Rhino.