Apr 4 2013

3dsmax .Net and the windows environment

so i have never been a big fan of tying my tools to windows environment..
but the reality is that people do this all the time…
at some point when trouble shooting a script plugin or in my case BlurPython qt deployment you are going to have to see what the current windows environment looks like inside of the max session, which unfortunately can be very different from what the windows environment looks like to the current session of windows and other apps..
anyway.. i put small snippet togather that build on the previous hashTable (.net dictonary) example, that allows us to not only print the windows environment variables visible to max, but also returns a hash table that we could use refer to the values at a later time..
here’s the good stuff..

fn getHashKeys hash =
    --spit the posible keys out
    DNArray = dotNetObject "System.string[]" hash.keys.count
    hash.keys.copyTo DNArray 0
    keys = for i = 1 to hash.keys.count collect (DNArray.get (i-1))

fn printWindowsEnv =
    Environment = dotNetClass "System.Environment"
    env = Environment.GetEnvironmentVariables()
    keys = getHashKeys (env)
    sort keys
    for k in keys do format "%=%\n" k env.item[k]

give it a go! see what it prints for you!

Leave a Reply