Notifications
Clear all

[Closed] MSX Editor Access

this one looks nice too
Many thanks Serejah, you helped me a lot

Finlay this part of code is finished
Is useful during develop tools which is in different structures
here is one example>

http://cestaslunce.cz/testy/updates/insertFunctionAtStruct.webm


part of code here>

	fn replaceText offset_pos str = (
	
		local ptr = marshal.StringToHGlobalUni str
		windows.sendmessage mxse_hwnd mcWinMsg.EM_REPLACESEL offset_pos ptr 
	),
	fn selectText offset str_len = (

		windows.sendmessage mxse_hwnd mcWinMsg.EM_SETSEL (offset-1) (offset+str_len-1)
	),
	fn moveCarretTo offset = (
	
		windows.sendMessage mxse_hwnd mcWinMsg.SCI_GOTOPOS offset 0
	),
	fn findText str = ( --OK
		
		local current_script_text = mcWin32.GetWindowText mxse_hwnd
	        findString current_script_text str
	),
	fn insertFunctionAtStructureEnd fn_str = (
	
		focus()
		fn_str += "\n\t" + struct_end_marker
		format "mcMsx > insertFunction >\n%\n" fn_str
		local end_pos = findText struct_end_marker
		if end_pos == undefined do return false
		format "mcMsx > insertFunction > end_pos:%\n" end_pos
		moveCarretTo (end_pos-1)
		selectText end_pos struct_end_marker.count
		replaceText end_pos fn_str
		focus()
	)

call >

local success = mcMsx.editStrucrure struct_name --edit structure file (in Maxscript Editor)
						if not success do return false
						--define new function as string
						local new_fn = "fn " + fn_name
						if fn_params != "" do new_fn += " " + fn_params
						new_fn += " = (\n\t\t\n\t\tInsert Code Here...\n\t)"
						--append function to current file (in Maxscript Editor)
						mcMsx.insertFunctionAtStructureEnd new_fn 

cheers

Is it possible all folds to be collapsed separately per fold?
What I mean – int he Maxscript Editor you can click anywhere in the code and then using View-Toggle current fold to collapse/expand the brackets.
There is View-Toggle all folds but its just collapse/expand the first and the last bracked(whole code).

this one will fold only the folds of certain level


(

	fn mxsEditorHWND asdotnet:false = (

		for c in (windows.getchildrenhwnd 0) where c[4] == "MXS_SciTEWindow" do for t in (windows.getchildrenhwnd c[1]) where t[4] == "MXS_Scintilla" do (
		
			if asdotnet then return dotNetObject "system.intptr" t[1] else return t[1]
		
		)
		
	)
	
	hwnd = mxsEditorHWND()
	
	SCI_GETFOLDLEVEL = 2223
	SCI_GETLINECOUNT = 2154
	SCI_TOGGLEFOLD = 2231
	SCI_GETLINEVISIBLE = 2228
	
	for i=0 to (windows.sendMessage hwnd SCI_GETLINECOUNT 0 0) - 1 do
	(
		linefoldlevel = (bit.shift (windows.sendMessage hwnd SCI_GETFOLDLEVEL i 0) -16) - 1024
		foldisexpanded = 1 == windows.sendMessage hwnd SCI_GETLINEVISIBLE i 0
		format "line#% - expaned:%  foldlevel:%\n" (1+i) foldisexpanded linefoldlevel 
		
		if linefoldlevel == 2 and foldisexpanded do windows.sendMessage hwnd SCI_TOGGLEFOLD i 0
		
	)

)

scite_commands.txt (19.2 KB)

Thank you. It works as expected. I have changed the linefoldlevel == 2 to linefoldlevel == 3 to fit my needs.
For folding on deeper level this have to be used, or there are more elegnat solution?

for i=0 to (windows.sendMessage hwnd SCI_GETLINECOUNT 0 0) - 1 do
	(
		linefoldlevel = (bit.shift (windows.sendMessage hwnd SCI_GETFOLDLEVEL i 0) -16) - 1024
		foldisexpanded = 1 == windows.sendMessage hwnd SCI_GETLINEVISIBLE i 0
		format "line#% - expaned:%  foldlevel:%\n" (1+i) foldisexpanded linefoldlevel 
		
		if linefoldlevel == 4 and foldisexpanded do windows.sendMessage hwnd SCI_TOGGLEFOLD i 0
		
	)

for i=0 to (windows.sendMessage hwnd SCI_GETLINECOUNT 0 0) - 1 do
	(
		linefoldlevel = (bit.shift (windows.sendMessage hwnd SCI_GETFOLDLEVEL i 0) -16) - 1024
		foldisexpanded = 1 == windows.sendMessage hwnd SCI_GETLINEVISIBLE i 0
		format "line#% - expaned:%  foldlevel:%\n" (1+i) foldisexpanded linefoldlevel 
		
		if linefoldlevel == 3 and foldisexpanded do windows.sendMessage hwnd SCI_TOGGLEFOLD i 0
		
	)

Any chance this to be used with # User defined key commands inside MaxScript editor like: # Ctrl+Shift+V|IDM_PASTEANDDOWN|\?

I wouldn’t call it elegant
First we collect all folds data and then sort them by depth and finally toggle


(

	fn mxsEditorHWND asdotnet:false =
	(
		for c in (windows.getchildrenhwnd 0) where c[4] == "MXS_SciTEWindow" do for t in (windows.getchildrenhwnd c[1]) where t[4] == "MXS_Scintilla" do
		(		
			if asdotnet then return dotNetObject "system.intptr" t[1] else return t[1]		
		)
		
	)
	
	global hwnd = mxsEditorHWND()
		
	SCI_GETFOLDLEVEL = 2223
	SCI_GETLINECOUNT = 2154
	SCI_TOGGLEFOLD  = 2231
	SCI_GETLINEVISIBLE = 2228
	SCI_GETLASTCHILD = 2224
	
	
	folds = #()
	
	for i=0 to (windows.sendMessage hwnd SCI_GETLINECOUNT 0 0) - 1 do
	(
		linefoldlevel  = (bit.shift (windows.sendMessage hwnd SCI_GETFOLDLEVEL i 0) -16) - 1024
		foldisexpanded = 1 == windows.sendMessage hwnd SCI_GETLINEVISIBLE i 0
		foldendline    = windows.sendMessage hwnd SCI_GETLASTCHILD i -1
		format "line#% - expaned:%  foldlevel:% foldend:%\n" (1+i) foldisexpanded linefoldlevel foldendline
		
		if linefoldlevel >= 2 and foldisexpanded do 
		(

-- 			windows.sendMessage hwnd SCI_TOGGLEFOLD i 0
			
			(
				(
					
					(
						
						
					)
					
				)
			)
			
			append folds #( i, foldendline, linefoldlevel ) -- fold start line, fold last line, fold level
			
		)
		
	)
	
	fn sortByFoldDepth a b = if a[3] > b[3] then -1 else if a[3] < b[3] then 1 else 0

	qsort folds sortByFoldDepth

	folded = #{}
	for f in folds where not (folded[f[1]] and folded[f[2]]) and f[1] != f[2] do 
	(
		windows.sendMessage hwnd SCI_TOGGLEFOLD f[1] 0
		
		folded[f[1]] = true
		folded[f[2]] = true
	)

)


In short, there’s no easy way.

You can try utilize http://www.scriptspot.com/3ds-max/plugins/mxspycom
Or if you prefer mxs way of doing it (but it tends to break after a while)

Thank you very much.
I will stay with default hotkey that I alrady have assigned.

executeMXS

BS9CyKiN9g

unfortunately it always prompts and shows output pane when script isn’t saved … don’t know if it possible to do something about it
hope somebody find useful

Page 2 / 2