Notifications
Clear all

[Closed] dotNet and dll

Hi,

I am trying to use my dll inside maxscript but am a bit lost after reading maxscript help and the forum.

In dotNet I would do something like this (having a Mydll.dll):

Dim MyText As Mydll = New Mydll("property1", "property2")
If (MyText.Result = "Ok") Then Messagebox.show(MyText.Result)

In MaxScript I started:

dotNet.loadAssembly "Mydll.dll"

…and how can I declare MyText as a new Mydll and do some work on MyText?

Many thanks,
Davy

8 Replies
 JHN

If you want to instanciate a new object


local myCustomObject = dotNetObject "Mydll" "myproperty1" "myproperty2"

showProperties myCustomObject
showMethods myCustomObject
showEvens myCustomObject

The properties the dotNetObject takes are important offcourse, since dotnet is “typecasted” you have to know what sort of value (string, int, float etc) the object needs as input. If it’s a string as your example shows you’ll probably be okay to pass on straight max string values.

-Johan

…it says “cannot resolve type” when defining the dotNetObject.

Davy

 JHN

My example has to be preceded by the loadAssembly, but I think you know this too. After that, you have to know what classes/objects are exposed, other then that you would have to show the source of the dll. Maybe you have a namespace that you forget to mention? Most dotnet dll, define default namespaces, that need to be included in the maxscript declaration.


dotNet.loadAssembly "Mydll.dll"
local myCustomObject = dotNetObject "MyNameSpace.Mydll" "myproperty1" "myproperty2"

showProperties myCustomObject
showMethods myCustomObject
showEvens myCustomObject

Do you get error messages?

-Johan

…nope, did not forget the assembly, I forgot my namespace.
It seems to be heading in the right direction. I can take it from here.

Thank you!
Davy

In the future you can use reflection to list out the types exported by your dll. Just keep track of the assembly object returned by the call to dotNet.loadAssembly

asm = dotNet.loadAssembly "Mydll.dll"

-- Dump the types exported by the assembly
for t in asm.GetExportedTypes() do print t.fullname

…all is working fine except one issue I can’t resolve:

My custom dll returns e.g. a date but maxscript just doesn’t return values like dates (and other) but instead it returns “dotNetObject:System.DateTime”.

How can I get values that maxscript doesn’t seem to translate?
I tried the “asDotNetObject:true” in my “getProperty” command but that doesn’t change anything.

Thanks!
Davy

 JHN

If you do a showProperties on that date value, you’ll find all available properties for the date object.
I image someting like date.Day returns the day value as integer (or something)… and there’s always the .ToString() method every DNObject has. It will return whatever value as string, so you can print it and check it.

Inspecting the dateTime class:


 showProperties (dotNetClass "System.DateTime")
 showMethods (dotNetClass "System.DateTime")
 
(dotNetClass "System.DateTime").Now.ToString()
 

-Johan

…ah, great. I was not going into the object (which sounds actually logical). Now it all makes perfect sense.
I am getting a grip on it now.

Many thanks for the help!
Davy