Autobracket MXSE


#1

hi
i found this video showing autoclose brackets on scite editors

does somebody knows how to make it work in Maxscript editor?
seems that he is using a lua script that is launched on editor open, but we just have “.proprieties” files

thanks


#2

It works, but as a side-effect it slows down the editor too much.
You need some external application that would check what user has entered in the editor and replace the input if it matches particular pattern.

QanyYLl8b0

fn MakeListener =
(		
	local source  = "using System;
	using System.Collections.Generic;
	using System.Text;
	using System.Runtime.InteropServices;
	using System.Windows.Forms;
	
	namespace WinAPI
	{
		class Listener : NativeWindow
		{
			public delegate void MessageHandler(object msg);
			public event MessageHandler MessageEvent;
			protected override void WndProc(ref Message m)
			{
				base.WndProc(ref m);
				if (MessageEvent != null) MessageEvent((object)m);
			}
		}
	}
	"
			
	csharpProvider = dotnetobject "Microsoft.CSharp.CSharpCodeProvider"
	compilerParams = dotnetobject "System.CodeDom.Compiler.CompilerParameters"
	compilerParams.ReferencedAssemblies.Add("System.dll");
	compilerParams.ReferencedAssemblies.Add("System.IO.dll");
	compilerParams.ReferencedAssemblies.Add("System.Windows.Forms.dll");		
	compilerParams.GenerateInMemory = on
	compilerResults = csharpProvider.CompileAssemblyFromSource compilerParams #(source)
	
	
	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:% % err.ErrorNumber err.Line err.Column err.ErrorText to:errs\n"
		)
		format "%" errs
		undefined
	)
	else
	(
		compilerResults.CompiledAssembly.CreateInstance "WinAPI.Listener"
	)
)

try
(	
	w.releaseHandle()
	dotNet.removeAllEventHandlers w
) catch()

g    = (dotNetClass "Autodesk.Max.GlobalInterface").Instance
hwnd = g.TheMxsEditorInterface.EditorGetEditHWND
w    = MakeListener()
ptr  = dotNetObject "System.IntPtr" hwnd
w.assignHandle ptr		

prev_insert = timeStamp()
goto_pos    = 0

fn InsertCharacter char =
(	
	local t = timeStamp()
	local delta = t - prev_insert
	
	if delta > 200 do
	(
		windows.postMessage hwnd 0x102 (bit.charAsInt char) 0
		goto_pos = windows.sendMessage hwnd 2008 0 0 -- SCI_GETCURRENTPOS
		prev_insert = t		
	)
)

fn OnWindowMessage ev =
(
-- 	format "%\n" ev.Msg
	
	if ev.Msg == 258 do -- WM_CHAR	
	(
-- 		format ">> % - % - %\n" ev.Msg ev.WParam ev.LParam
				
		case ev.WParam of
		(
			39  : InsertCharacter "'"
			34  : InsertCharacter "\""
			40  : InsertCharacter ")"
			91  : InsertCharacter "]"
			123 : InsertCharacter "}"
		)
	)

	if ev.Msg == 257 do -- WM_KEYUP
	(
		local t = timeStamp()			
		if t - prev_insert < 200 do
		(
			windows.sendMessage hwnd 2025 goto_pos 0 -- SCI_GOTOPOS
		)			
	)
	
)
dotnet.addEventHandler w "MessageEvent" OnWindowMessage

#3

do everything (messages check, insert…) in c#. you don’t need to go to mxs for it