View Full Version : .net & passing a value to a function ??

02-02-2008, 04:44 PM
I have been trying to get this working for a few days now with no luck so I hope you guys dont mind if I post it up here. I wrote a simple C#/dotnet DLL with one function in it just so I can test dotnet in maxscript, all it does is add two values together and return the sum you can see the code inside the dll below below.

#region Referenced Assemblies
using System;
#endregion // Referenced Assemblies
namespace mathtest
/// <summary>Minimal class to do math</summary>
public class maths
#region Methods
/// <returns>a+b</returns>
static public int addval (ref int a, ref int b)
int c = a+b ;
return c ;
#endregion // Methods

using Maxscript I can load the Dll

scriptpath=getdir #scripts
Assembly = dotNetClass "System.Reflection.Assembly"
Assembly.loadfrom (scriptpath + "/mathtest/mathtest.dll")
math_1 = dotnetClass "mathtest.maths"

if I use showMethods math_1 I get this output

.[static]<System.Int32>addval <System.Int32&>a <System.Int32&>b
.[static]<System.Boolean>Equals <System.Object>objA <System.Object>objB
.[static]<System.Boolean>ReferenceEquals <System.Object>objA <System.Object>objB

now the thing I want to know is How the Hell do I pass a value to A and B and then get the returned value from C ??

Am I asking to much of max script ? can this be done with max script if it can could someone PLEASE show me the right way to go about it just so I can get going .
thanks very much for reading and I hope someone can help .
All the best ...

02-02-2008, 07:51 PM
static public int addval (ref int a, ref int b) -> ref are useless as you're not assigning a value to them in the method

And you can call the addval() method like this:
scriptpath=getdir #scripts
Assembly = dotNetClass "System.Reflection.Assembly"
Assembly.loadfrom (scriptpath + "/mathtest/mathtest.dll")
maths = dotnetClass "mathtest.maths"
val = maths.addval 1 3

02-03-2008, 03:23 PM
thanks ypuech I changed the code and took out the ref so now the c# = (int a, int b)

val = maths.addval 1 3 worked fine :)
Thanks again for your help

CGTalk Moderation
02-03-2008, 03:23 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.