Thanks for trying
Send data from C# to Maxscript (Property/variable data)
Itâs the expected behavior.
System.Single (float) is a Value Type, thus it defaults to its default value 0.0. It can never be ânullâ (undefined).
System.String is a Refernce Type, thus its value is ânullâ (undefined) if not assigned.
Thatâs the behavior in C# and thatâs what you get.
If you need value types with the possibily of being ânullâ, you have to use the â?â modifier.
You donât have to do anything. Conversion is automatic from the main value types as floats, doubles or integers.
From strings too, and from arrays of these types too.
Yes, I understand that. However, the data is not coming across in a usable format. âUndefinedâ doesnât equal âThis is a stringâ. Itâs getting, extracting or whatever the data in Max the same as in C#. Iâm not sure what Iâm missing unless the data is there and that the Print function isnât showing it.
The problem is that the data being pulled in from C# is Undefined. It should be âThis is a stringâ. If I assign the data to the Text property of a textbox will it still show âThis is a stringâ or will it error out as being Undefined?
For example, the data for a given property, e.g. .PositionX is -39.52099 in the C# app. However it is always 0.0 in 3dsMax. Iâm trying to get the actual float value for use in Maxscript to position an object.
This is not right.
If you call a method of your class that returns a double (or an integer, or a stringâŚ) youâll get in Max a double (or an integer, or a stringâŚ). For example, in MaxScript:
classObj = dotNetObject "MyNameSpace.Out2Max"
aaa = classObj.myDoubleMethod() --> you'll get a double value
If you call a method of your class that returns a reference object, for example an âOut2Maxâ instance, youâll get an instance of âOut2Maxâ as a dotnet object, and you can read its public properties or fields without any problem, or call its methods without any problem.
classObj = dotNetObject "MyNameSpace.Out2Max"
aaaRef = classObj.myRefMethod() --> you'll get a dotnet object holding the reference object returned by this method.
X = aaaRef.PositionX --> you'll get the float value
Test = aaaRef.Test --> you'll get the string
If you allways get 0 for value types or undefined for strings is because you are returning void values, not because of Max behavior.
Could you give me a sample method that holds float and string variables inside it that are accessible to the sensor app?
(
local source = "using System;
namespace mxs
{
public class myclass
{
private string _testString;
public string GetTestString { get { return _testString; } set { _testString = value; } }
}
}"
compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerParams.ReferencedAssemblies.Add("System.IO.dll");
compilerParams.GenerateInMemory = on
csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #( source as string )
if (compilerResults.Errors.Count > 0 ) then
(
local errs = stringstream ""
for i = 0 to (compilerResults.Errors.Count-1) do
(
local err = compilerResults.Errors.Item[i]
format "Error:% Line:% Column:% %\n" err.ErrorNumber err.Line err.Column err.ErrorText to:errs
)
format "%\n" errs
undefined
)
else
(
compilerResults.CompiledAssembly.CreateInstance "mxs"
)
)
(
x = dotNetObject "mxs.myclass"
format "should return undefined >> %\n" x.GetTestString
x.GetTestString = "test"
format "should return test >> %\n" x.GetTestString
)
Thanks Sergey!! Iâm getting mad with this.
David, the only thing you can do is show both of your codes, C# and MaxScript, and we may find your problem. But the problem isnât where you think it is.
Yes, this is what I imagined⌠Computers can do many things but not magic (at least to date).
On the âon TestOut2Max open doâ event you create an object instance of your class, a new one. Why the hell should it be the one you are feeding with your sensor app?
You must get the instance you are updating from the sensor app or, directly, feed the one you create with Max with your app.
P.S. 1: By the way, the loading assembly should be at the start of your script or create a global for it and check in the âopenâ event if it is already loaded. You can load a dll only once.
P.S. 2: Programming is entertaining and fun, but itâs a professional job too. I do not know why there is a general idea of what anyone can do it with a few clever copy/paste.
What do you think you are doing when you write:
classObj = dotNetObject "MyNameSpace.Out2Max"