OK I’m having some issues getting
dotNet.loadAssembly "Microsoft.Win32.Registry"
to work. Is it not supported or am I doing something wrong?
I want to be able to read and write reg keys.
OK I’m having some issues getting
dotNet.loadAssembly "Microsoft.Win32.Registry"
to work. Is it not supported or am I doing something wrong?
I want to be able to read and write reg keys.
Never mind, I’m a bone head. Must have miss typed my frist test of
reg=dotNetClass "Microsoft.Win32.Registry"
reg.localMachine
This works fine so far.
OK I still need a bit of help on this. I can create new keys but I can’t sort out how to create values.
reg=dotNetClass "Microsoft.Win32.Registry"
reg.LocalMachine.GetSubKeyNames()
softWare=reg.LocalMachine.OpenSubKey "SOFTWARE" true --Opens key and makes it writable.
pen=softWare.CreateSubKey "Pen" --Creates a new key.
--This isn't working. Can any one shed any light on it?
pen.SetValue "Version" 1.0 --Errors
pen.close()
softWare.close()
Hi Pen! My first filling would be that .net can’t convert the value “1.0” to an appropriate “object” value (as setValue is expecting a Object value). Using something like
setValue("DWordValue", 42, RegistryValueKind.DWord)
might help…Obviously you will need to “pre-load” the registerValueKind enumeration struct…
Using the “setValue” method as you have implies a RegisterValueKind.Unknown, which might be the reason you are having problems.
The only other thing that comes to mind is trying to convert the value to a .net double, but .net doesn’t have a “object” representation of it’s primitive types, so I’m not sure if it will really work…but you could use something like
System.Double.TryParse "1.0"
(obviously I’ve not loaded the assembly, but simply used the calling convention here)
I will have a closer look at it when I get to work this morning…
Shane
Thanks Shane but I’m still getting errors with lines like this.
pen.SetValue "Version" "1.0" (dotNetClass "Microsoft.Win32.RegistryValueKind").String --Errors
I might have to resort to doing it with DOS but that is just a pain.
Forgive me if I don’t accept that as a valid workaround…
reg=dotNetClass "Microsoft.Win32.Registry"
reg.LocalMachine.GetSubKeyNames()
softWare=reg.LocalMachine.OpenSubKey "SOFTWARE" true --Opens key and makes it writable.
pen=softWare.CreateSubKey "Pen" --Creates a new key.
[b] dnStr = dotNetObject "System.String" "1.0"[/b]
--This isn't working. Can any one shed any light on it?
pen.SetValue "Version" dnStr --Errors
format "%
" (pen.GetValue("Version"))
pen.close()
softWare.close()
This didn’t throw any errors. Can’t say for 100% that it worked, but at least it didn’t cry…
Shane
Verified
(
reg=dotNetClass "Microsoft.Win32.Registry"
reg.LocalMachine.GetSubKeyNames()
softWare=reg.LocalMachine.OpenSubKey "SOFTWARE" true --Opens key and makes it writable.
pen=softWare.OpenSubKey "Pen"
format "%
" (pen.GetValue("Version"))
pen.close()
softWare.close()
)
Produces “1.0”
Interesting. So this is only a string how ever. now I’m wondering how it will take a integer as I don’t see a way yet in dotNet to make an int object.
Thanks for the help.
Oh, i’ve been banging my head against a wall over that one to…
First I tried
local dValue = (dotnetclass "System.Convert").toDouble("1.1")
Now that does SOMETHING, but when you try and pass through the setValue method MAX has a whinge that it can’t find an appropriate method…
Presumably, .net’s primative’s are also a special type of “object” that max doesn’t recognise…oh joy
Now, I’m probably missing something, but I’ve not yet had any luck with trying to use numbers…
edt: ps - Oh the joys of not coding in a pure OO language…I’m going to get flammed for that aren’t I…
I’ve been reading through a whole bunch of documentation and it would appear that, from my perspetive, I’m reasonable right…always room for improvement. But at least from max’s point of view I’m right.
We can’t pass a “primitive” type to a dotnet class requiring an “Object” type, because the cross over implementation does not allow for converstion between them.
Having said that, it is possible to be done, inside dotnet. Basically, the suggested method is to create an “Object”, then point the object at the value and pass the object to the class…
double dValue = 1.1
Object o = new Object()
o = dValue
we can’t do that…I’ve tried.
The only other thing I can think off is to write a “wrapper” object which does it for you…but that kinda defeats the purpose…
Shane
Well Shane thanks for the info again. So it is a Max limitation with dotNet? A limitation with dotNet it self or a bit of both? I gather it is more Max then dotNet if we could do it in dotNet. I will put in a request to see if it can be corrected.
Thanks go to Grant Adam for this one Shane…
dValue = dotNetObject "System.Double" 32
pen.SetValue "Double" dValue
I tried doing something like that but couldn’t get it to work…obviously missed something…also the fact that “Double” is listed as struct without constructors in the docs makes it little obscure…
Nice to know though!
Shane
Such pure conversion to .NET type is sometimes required, for example in the use of a .NET array:
-- Create a .NET array of 10 integers
intArray = dotNetObject "System.Int32[]" 10
-- Fill array
for idx = 1 to 10 do
(
intValue = dotNetObject "System.Int32" (random 1 100)
intIndex = dotNetObject "System.Int32" (idx-1)
intArray.SetValue intValue intIndex
)
-- Print array data
for idx = 1 to 10 do
(
intIndex = dotNetObject "System.Int32" (idx-1)
print (intArray.GetValue intIndex)
)
Here is a thread where I have posted information about writting XML files. This should get you started.
http://forums.cgsociety.org/showthread.php?f=98&t=590934&page=2&highlight=xml
Reading XML is just as easy, it will allow you to read in each node as an object and get the properties for it. You then can recursively search and read all the objects in the XML file.
Nice one. I’m still working very slowely on a Dot Net page for my site, mind if I use this example? Full credit of course.
You can use it as you want but the credit goes to an Area member : KoichiSenada (http://area.autodesk.com/index.php/forums/viewthread/3651/#11557). I don’t know if he is a CGTalk member.
I never succeed in working with .NET arrays before his post and now I can use more advanced methods of .NET framework.
I’m also working (very slowely :)) on adding new pages and articles about using .NET in MAXScript. I’ll post these on my web when I’ll have time.
Uh!
Hello everybody, ypuech especially!
I was just wondering what’s going on these days in this thread, and was really surprised to see the same issues that I was working with. 
For example, reading XML files.
If anyone is still intrested in more samples, I can provide a link to my macroscript, that I’ve developed with Yannick Puech:
KoichiSenada / 3dsMax / 3dsMaxConvertXml
Hello everybody and ypuech especially!
I was just wondering what’s going on in this thread lately.
And I was quite suprised to see that those are things I was working on earlier.
If anyone still wants more examples of reading XML files, check out macroscript that I have written with Yannick Puech:
KoichiSenada / 3dsMax / 3dsMaxConvertXml