View Full Version : DotNetClass [System.IO.DriveInfo]
MikeOwen 05-29-2009, 11:26 AM Can someone give me some pointers with regard how to get the following DotNetObject/Class to check if the renderoutput location defined by an artist is attempting to save the output to a file server which has a threshold of say < 5GB in "available free space".
So far I have:
x = DotNetClass "System.IO.DriveInfo"
RenderOutput = outputfilename
"AvailableFreeSpace" is the method on MSDN.
Mike
|
|
LoneRobot
05-29-2009, 12:51 PM
hi mike
try
SomeDriveInfo = DotNetobject "System.IO.DriveInfo" "c:\\"
-- result is in bytes so divide a few times to get GB
GBleft = (((SomeDriveInfo.AvailableFreeSpace/1024)/1024)/1024)
if GBleft > 5 then print "enough space" else print "medic!"
MikeOwen
05-29-2009, 02:51 PM
Thanks Pete, much appreciated!
However, a problem, which I can't think of a workaround is, if the path is a UNC path, then it doesn't work!
All these are vaild...
DriveOutput = DotNetobject "System.IO.DriveInfo" "C"
DriveOutput = DotNetobject "System.IO.DriveInfo" "C:"
DriveOutput = DotNetobject "System.IO.DriveInfo" "C:\\"
But,
DriveOutput = DotNetobject "System.IO.DriveInfo" "\\myserver\\"
fails :-(
Mike
PiXeL_MoNKeY
05-29-2009, 03:35 PM
According to the error ("-- Runtime error: dotNet runtime exception: Object must be a root directory ("C:\") or a drive letter ("C").") you must point to a drive letter, so unmapped unc paths will be invalid.
-Eric
LoneRobot
05-29-2009, 03:45 PM
hi mike, could you map a network path and use that letter instead?
MikeOwen
05-29-2009, 04:04 PM
Hence my problem..!
Looks like a lookup table for UNC paths against drive letters is the only option :-(
LoneRobot
05-29-2009, 04:17 PM
or some more storage!
Kameleon
05-29-2009, 04:34 PM
Have a look at this : http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/63c0b94a-8e53-46f8-b46e-c2e8c9f4686f
You can write a custom class and you've solved your problem. Cheers
Kameleon
05-29-2009, 05:29 PM
Or you download my KClasses and do something like this :D
dotnet.loadassembly @"C:\KClasses.dll"
dnGet=dotnetObject "KClasses.DnGetDiskFreeSpaceEx"
dnGet.dnGetDiskFreeSpace @"\\yourserver\shared\"
print (((dnGet.freeBytes / 1024) / 1024) / 1024)
Values are returned in Long. Cheers!
MikeOwen
06-01-2009, 09:35 AM
Thanks very much Kameleon, much appreciated.
However, running this code;
dotnet.loadassembly @"C:\KClasses.dll"
dnGet=dotnetObject "KClasses.DnGetDiskFreeSpaceEx"
dnGet.dnGetDiskFreeSpace @"\\myserver"
GBleft = (((dnGet.freeBytes/1024)/1024)/1024)
results in:
dotNetObject:System.Reflection.Assembly
dotNetObject:KClasses.dnGetDiskFreeSpaceEx
false
0L
But myserver has 7GB free..! Does this class work on a x64bit XP OS with x64bit Max?
BTW, what did you use to compile the dll with? VS2008 Express?
Thanks,
Mike
ZeBoxx2
06-01-2009, 10:58 AM
you have to specify the actual resource.. and make sure it exists.
e.g.
-- correct
dnGet.dnGetDiskFreeSpace @"c:"
false
GBleft = (((dnGet.freeBytes/1024)/1024)/1024)
17L
-- wrong
dnGet.dnGetDiskFreeSpace @"\\zb-test\"
false
GBleft = (((dnGet.freeBytes/1024)/1024)/1024)
17L -- bogus value left over from the previous call
-- correct
dnGet.dnGetDiskFreeSpace @"\\zb-test\Public"
false
GBleft = (((dnGet.freeBytes/1024)/1024)/1024)
489L -- that's better
Kameleon
06-01-2009, 11:58 AM
I've updated my example, my bad sorry :D Just go by what ZBoxx said :)
Yeah, I've used VS2008 Express. Cheers!
MikeOwen
06-12-2009, 12:14 PM
Hi All,
I have just found out that due to security permissions, you can't put the "KClasses.dll" onto a network server, which is annoying....!
dotnet.loadassembly @"\\\\myserver\\newfolder\\KClasses.dll"
dnGet=dotnetObject "KClasses.DnGetDiskFreeSpaceEx"
dnGet.dnGetDiskFreeSpace @"\\myserver\newfolder"
GBleft = (((dnGet.freeBytes/1024)/1024)/1024)
if GBleft > 10 then print "enough space" else print "medic!"
Causes the error:
-- Runtime error: dotNet runtime exception: System.Security.Permissions.SecurityPermission
Do you know of a workaround, apart from copying the dll to say, the root of whatever version of 3dsMax I am using?
Thanks,
Mike
Kameleon
06-12-2009, 03:54 PM
One thing that I did was to check if the KClasses.dll file was in the network folder and if it was, copy it to the local scripts folder and load the assembly from there.
MikeOwen
06-15-2009, 04:49 PM
Thanks.
I have now taken this approach and its working at the moment.
Mike
CGTalk Moderation
06-15-2009, 04:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.