Notifications
Clear all

[Closed] MaxScript DotNet integration

Thank you JHN, i understood the problem tested it in windows forms application same thing like you sead, off to make custom event handler thx again.

Ha Ha, what’s a little missed punctuation between friends?

Sounds like you are on the right track now, Dejan. If you wanted some more info about inheriting the eventarg class within a user control, I wrote an article about this exact thing a while back, and I promise it has a few shorter sentences than my first offering.

http://lonerobot.net/?p=411

Thank you Peter, i figured there are alot of ways to make custom controls… I was thinking about creating most of my project in c# and use

ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand()

to pass anything i need to maxscript and use execute query… for communication with dotnet…

Is this something that is recommended or its better to do all in maxscript and dotnet just for controls.

Hi Dejan,

I think that’s a good approach. Because my tools generally are set up for a specific task, more that I can hardcode into the class library the better. I use the managedservices.dll methods quite a lot!
It really depends on how complicated the maxscript call is. I have converted maxscript code into ‘dotnet friendly’ code and registered the function via the usercontrol’s new constructor. It’s sometimes fiddly to figure out, you just need to insert any variables into the overall string and remember that you’ll have to insert a special string character to make a string in a dotnet toMXS transfer. this is because managedservices can only pass a string.

I have a class that I have written that allows me to format code to the listener from the assembly, it helps checking the code going into max is as it should be. Let me know if you can use it and i’ll post it when I get home.

There are also a couple of other posts on my blog that talk about managedservices and how you can use them in a max-centric dotnet usercontrol. There’s a lot of tips and tricks I’ve picked up over the last couple of years writing custom controls for max.

 JHN

Hey Pete, how would you handle bigger functions like collect all scene materials, the objects they are attached to and their texturemaps. Now I have a maxscript function that collects it nicely for me in manageable structs that mostly use animHandles/IntPtr values (getHandleByAnim).
Now I have in my managed tool a class that mimics the struct, now I’m thinking about passing the struct to dotnet via a method, so that dotnet has representation of my scene materials in managed code and not just strings. I want to use the IntPtr values to communicate. What do you think, does it make sense?
In dotnet I only have some small utility maxscript functions to get data from a specific handle, but the bulk functions I rather leave in maxscript for now, for easier debugging…

There’s just so many ways to approach this communication.

Found a nice imageprocessing library btw, free image. Reads loads of formats, only 32bits though, afaik.

-Johan

Hi Johan,

That’s a good question, – my initial thoughs are that you are going to have to store an instance of the usercontrol in a global in max -perhaps when the script is run for the first time. Having a dotnet version of a struct is a good approach too, you can construct a class that contains properties for all the value types that you wish to store from max (although with nodes you would be limited to their names, not very robust I know but all I can think of currently) You can then use the script that is registered from your assembly to construct your struct class and feed that back into the usercontrol global variable. You could construct a method to handle this exact case. At the moment im thinking you cant pass anything that isnt a value type like string, boolean, image etc so for something more max-centric you would have to construct a class that stored the elements that make up a particular material. My approach might be a little simplistic, im sure the proper dotnet wizards on here could think of a better way.

I have used that, it is good although the 64bit limitation stopped me from using it. there is a wrapper called AIL that uses freeimage, and is great to use in a managed environment.

1 Reply
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

That’s where I was thinking of


handle = getHandleByAnim $
IntPtr = dotnet.ValueToDotNetObject handle (dotNetClass "System.IntPtr")
IntPtr.ToString()

And for arrays


handle = for o in selection collect getHandleByAnim o
IntPtrArr = dotNetObject "System.IntPtr[]" handle.count
for i = 0 to handle.count - 1 do IntPtrArr.Set i (dotNetObject "System.IntPtr" handle[i + 1])
	
print (IntPtrArr.Get 1)

The IntPtr’s can be fed to a custom dotnet class easily and you have a nice reference to your scene with the handles.

What do you use now then? Something you cooked up yourself, cause my first tests with creating thumbnails on the fly didn’t go very fast.

-Johan

Cool, i get it. I hadn’t seen the getanimbyhandle/GetHandleByAnim methods before. My question is, that obviously works fine on something like a teapot, but what if the object that you want doesn’t have a handle? sorry, I couldn’t resist it.

I’m assuming that the handle is different each time you open it in a max session, so if you wanted to store something like a rig, you are still stuck with using the name to grab the handle for the node in that session? I will definitely look into this now, it’s an interesting approach you’ve come up with. thanks!

What do you use now then? Something you cooked up yourself, cause my first tests with creating thumbnails on the fly didn’t go very fast.

I use GDI+ and Max’s built in Image classes in HitchHiker. The dotnet image classes can be cached with a backgroundworker and things like tga and rpf via 3dsmax. There is a cache mode on the latest release, the thumbs are stored locally now, it means it at least has the appearance of being fast after the first run!

 JHN

You mean people use something else then teapots in max?!

The handle should stick over a file, but not over a merge. So it’s not so solid for that, CA’s should be better suited for that. I’m using it on tools that have to alter the current scene properties. And you can get handles from almost anything, not just nodes.

getHandleByAnim scenematerials

Alright interesting, but I’m sticking with freeimage for now as the tool I’m building now is not for use in max, and it comes with a proper dotnet wrapper on it’s own.

Cheers,
-Johan

The handle should stick over a file, but not over a merge. So it’s not so solid for that, CA’s should be better suited for that. I’m using it on tools that have to alter the current scene properties. And you can get handles from almost anything, not just nodes.

I just tried this on a teapot (naturally) with hold/fetch. Each time i fetched and called
GetHandleByAnim $ it returned a different number. So i guess the handle is different each time or am I missing something?

I can still see there would be masses of applications for your approach! thanks again johan.

Alright interesting, but I’m sticking with freeimage for now as the tool I’m building now is not for use in max, and it comes with a proper dotnet wrapper on it’s own.

😮 not for use in max??? consider yeeself BANNISHED!

1 Reply
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

You’re right indeed, it should only be used on “sessions” it seems, I thought it was a bit more robust, ohwell.

Wish I could take full credit, but I also read it somewhere on this forum, probably from Bobo or Denis.

Project wrapping tools span more than max (unfortunatly!), lets say you want to semi automatically wrap(archive) a project and generate some nice JPG’s and some other statistics along the way. I love this sort of things!

Cheers,
-Johan

Sounds like I am writing a very similar tool to you at the moment – it’s a stand alone .net application that scans through our entire project and generates XML data files according to a set XML schema. Its so the project the can be added to a huge asset database. I’m glad i looked into LINQ a while ago, as it’s proving really useful. I couldn’t believe it when they told me that previously someone entered the data into excel manually for EVERY project asset and generated the xml from there!

So i guess we are married to max but there are many software mistresses these days…

3 Replies
 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

That’s step two for me to, now we don’t have an asset database, just some big elephant brains. The wrapping I’m doing now is for rendered/comped footage.

Python and Qt are flirting with me too, but I have not given in, yet.

-Johan

(@denist)
Joined: 11 months ago

Posts: 0

don’t flatter yourself. they are doing it for anyone.

 JHN
(@jhn)
Joined: 11 months ago

Posts: 0

I know, I saw a friend of mine doing c++ and Qt, made me jealous, nice UI controls!

-Johan

Page 2 / 3