[Closed] Inheritance in DotNet Controls – New Article on LoneRobot.com
Hello all,
Just thought i’d post some research about control inheritance on my dotnet research page. It’s got some information about using Enums in dotnet too, which could be of use. Finally there is a section detailing the use of embedded resources in dotnet classes, something I am doing more and more to simplify the deployment process of scripts.
There is also a MaxButton assembly for everyone to download that does the UI above.
Thanks for this, LR, your site is growing into a really useful resource for learning. It’s nicely presented, too.
You refer to this syntax:
To use an enum in 3DSMax, you use a plus symbol in between the class string and the enum type. therefore, in the maxbutton class, to get the enums used you would type the following – (dotnetclass “LoneRobot.Controls.MaxButton+CustomIcons”).NewDocument
Can you point me to where this comes from? I can’t find any MXS docs on it. I just wondered whether the ‘+’ is only ever used to refer to enums declared inside a class, or if it’s also used for other nested thingies.
Thanks drdubosc, Paul.
I'm pleased you find it useful. While there are many,many programming resources out there Im trying to link my site's stuff as closely to a 3dsMax slant as possible. I'm also trying to give examples of MXS that are similar to dotnet concepts as much as I can for clarity.
It wasn't in the help drdubosc, I found this from a showproperties query of the custom assembly after it had been loaded into max.
dotNet.loadAssembly "C:\lonerobot\classlib\MaxButton.dll"
dotNetObject:System.Reflection.Assembly
lrclass = dotnetobject "LoneRobot.Controls.MaxButton"
dotNetObject:LoneRobot.Controls.MaxButton
show lrclass
.ColorPreset : [color=Red]<LoneRobot.Controls.MaxButton+ColorPresets>
.CustomIcon : <LoneRobot.Controls.MaxButton+CustomIcons>
.LayoutStyle : <LoneRobot.Controls.MaxButton+LayoutStyles>[/color]
-- try just adding the enum onto the class
lrenum = dotnetclass "LoneRobot.Controls.MaxButton.ColorPresets"
undefined
-- hmmmm now use the syntax from the listener
lrenum = dotnetclass "LoneRobot.Controls.MaxButton+ColorPresets"
dotNetClass:LoneRobot.Controls.MaxButton+ColorPresets
show lrenum
.MaxUIDark : <LoneRobot.Controls.MaxButton+ColorPresets>, read-only, static
.MaxUILight : <LoneRobot.Controls.MaxButton+ColorPresets>, read-only, static
lrenum.MaxUILight
dotNetObject:LoneRobot.Controls.MaxButton+ColorPresets
It doesn't use this + syntax in VS, but seems to be a max thing on initial inspection. The other approach I guess would be to write a new class instead of an enum.
One thing I haven't been able to access is the equivalent of the "my" keyword in DotNet. This is where you can get access to the embedded resources and settings. As it stands, I am placing a function or property in the class that returns them, like the customicons property in the assembly featured in this article. I'm not sure if this is the best way but I'm going on what i can get from the MXS querying methods. This is a VB only method, apparently.
can i ask what sort of nested things were you thinking about using?
Thanks! Now i get the idea, I can do some trial and error of my own. I was thinking of inner classes, nested structs.
The VB ‘My’ namespace provides shortcuts to a multitude of operations. For instance,
dotNet.loadAssembly “Microsoft.VisualBasic”
MyComputer = dotNetobject “Microsoft.VisualBasic.Devices.Computer”
gives you My.Computer, roughly. But not everyone will have the VB dll?
The C#ish way of getting at embedded resources is through System.Reflection.Assembly. Via MXS, something like:
MAXButtonAssembly = dotNet.loadAssembly “C:…\MaxButton.dll”
resNames = MAXButtonAssembly.GetManifestResourceNames()
dataStream = MAXButtonAssembly.GetManifestResourceStream ResNames[x]
But when I try it on your dll, resNames is a 1 element array containing “LoneRobot.Controls.Resources.resources” and I get stuck there…
I think it’s better to provide access to embedded resources from inside the assembly, (possibly using a purpose-built resource-reader class), anyway.
Thanks dr for the heads up on C# reflection, that is interesting. As for providing access to the embedded resources, i was thinking a public function with the return type the same as the resource you are retrieving should do it.
[i]example code[/i]
maxbutton.stopicon()
[i]calls -[/i]
function stopicon () as image
(
return my.resources.stopicon
)
this way, you could embed images, sounds, and text into a class library and then retrieve it in max or wherever.
… saves a lot of trouble, doesn’t it? It would be a class method, Shared in VB?.
If you had a lot of classes in one assembly, and they all had to get at the same resources, it might be worth splitting out a resource reader (to respond appropriately to resource types, handle errors, etc), which they could all use. You’d have to see the need before bothering:).
good point, i’d read about keeping useful resx files so that you can reuse them on other projects. In the simple classes i’m writing it is manageable but any larger projects would need it!