Notifications
Clear all
[Closed] [C#] passing enum values from mxs to C#
May 22, 2014 7:23 pm
I’m new to Enums and I’m trying to figure out how I can pass enum values form Max script to a C# method.
For some reason the argument is not being recognized…
here’s my C#
namespace myTools
{
public class Files
{
public enum AssetType {heroes,grunts,weapons,items}
public string newAsset(AssetType type, string assetName)
{
string message = string.Format("NewAsset:{0} {1}", type.ToString(), assetName);
return message;
}
}
}
and the mxs with –listener output
Files =dotNetObject "myTools.Files"
--dotNetObject:myTools.Files
type=dotnetClass "myTools.Files+AssetType"
--dotNetClass:myTools.Files+AssetType
Files.NewAsset (type.heroes) "newHero"
-- Runtime error: No method found which matched argument list
3 Replies
May 22, 2014 7:23 pm
LO tells you about the right usage of public enums. if you want to use an enum across different classes you have to define the enum outside the class.
but if you want to use some enum mostly in one class but make it visible for other classes you still can do. and can define it as public inside the class. but an access to this enum will be different.
here is a sample that shows these two cases and their usage with mxs:
(
source = ""
source += "namespace TRYIT
"
source += "{
"
source += " public enum Place { Left = 0, Middle = 1, Right = 2 }
"
source += " public class EnumTest
"
source += " {
"
source += " public enum Place { Left = -1, Middle = 0, Right = 1 }
"
source += " public object GetPlace(object place)
"
source += " {
"
source += " return place;
"
source += " }
"
source += " }
"
source += "}
"
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.GenerateInMemory = on
csharpProvider.CompileAssemblyFromSource compilerParams #(source)
)
/*
((dotnetobject "TRYIT.EnumTest").GetPlace (dotnetclass "TRYIT.Place").Left).value__
((dotnetobject "TRYIT.EnumTest").GetPlace (dotnetclass "TRYIT.EnumTest+Place").Left).value__
*/