Notifications
Clear all

[Closed] C# talking to Max

I know this isn’t really maxscript, but you guys have done this before I’m sure.

 I'm trying to get a C# .dll and max to talk to each other.  I can get a variable from Max, but i can't seem to pass a variable To max.
 
 Example:

     string NewBuffer = ManagedServices.MaxscriptSDK.ExecuteStringMaxscriptQuery(@"GetUserPropBuffer $");
     
     .... 
     
     if (NewBuffer.Length >0)
     {
     ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand("print /" + NewBuffer.ToString()+"/");
     ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(@"SetUserPropBuffer $ " + NewBuffer.ToString() );
     }
     

Note: Idk why the form here is messing up the word MaxscriptCommand or MaxscriptQuery…at least it appears that way on the preview.

Anyways, i’ve attached process, and I can see that NewBuffer has a property when its “passing into max”…but it doesnt seem to read. Is there a way to do this, or do i have to assign to a public property, and then read that in from max…I’d prefer not to do that, but seems my only other option.

2 Replies

Hmm…i got them to work…syntex errors on my part.

ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(“print “” + NewBuffer.ToString() + “””);
ManagedServices.MaxscriptSDK.ExecuteMaxscriptCommand(“SetUserPropBuffer $ “” + NewBuffer.ToString()+”””);

I’ll leave here incase anyone else has same problems

i have also found its a tricky thing, especially with strings within strings from managed services. I wrote a class so that i could examine the string that was being passed to max for debugging purposes. here it is (converted from vb) –

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using ManagedServices.MaxscriptSDK;
using System.Windows.Forms;

namespace Integration
{
	public class MaxScriptOps
	{
		public void Execute(string ExecuteString, bool TestMode)
		{
			if (TestMode) {
				MessageBox.Show("Execute (" + Strings.Chr(34) + ExecuteString + Strings.Chr(34) + ")");
			} else {
				ExecuteMaxscriptCommand("Execute (" + Strings.Chr(34) + ExecuteString + Strings.Chr(34) + ")");
			}
		}

		public void PrintToListener(string caption, string text, bool TestMode)
		{
			if (TestMode) {
				MessageBox.Show("Print @" + Strings.Chr(34) + caption + " - " + text + Strings.Chr(34) + "% - %\
");
			} else {
				ExecuteMaxscriptCommand("Print @" + Strings.Chr(34) + caption + " - " + text + Strings.Chr(34) + "% - %\
");
			}
		}

		public void FormatToListener(string caption, string text, bool TestMode)
		{
			if (TestMode) {
				MessageBox.Show("Format" + Strings.Chr(34) + "% - %\
" + Strings.Chr(34) + " " + Strings.Chr(34) + caption + Strings.Chr(34) + " " + Strings.Chr(34) + text + Strings.Chr(34));
			} else {
				ExecuteMaxscriptCommand("Format" + Strings.Chr(34) + "% - %\
" + Strings.Chr(34) + " " + Strings.Chr(34) + caption + Strings.Chr(34) + " " + Strings.Chr(34) + text + Strings.Chr(34));
			}
		}
	}
}