Notifications
Clear all

[Closed] Send data from C# to Maxscript (Property/variable data)

(
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.

Thanks for trying

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.

Thanks for trying

What do you think you are doing when you write:

classObj = dotNetObject "MyNameSpace.Out2Max"

Page 2 / 2