Note Pad Feature in MaxScript


#1

Hello all!

I’m trying to create a note system that sticks with a max file or is easy to load the notes for another animator from a local folder(the more automated the better).

I am very new to max script and here’s what I’ve got,

(
if savedData == undefined do global savedData = #() – having truble with what to use for the Array.

if classOf NotesRollout == RolloutClass do DestroyDialog NotesRollout

rollout NotesRollout “Project Notes” width:550 height:450
(

dotNetControl textboxctrl “System.Windows.Forms.TextBox” pos:[40,16] width:450 height:300

button btnClearAll “Clear All” align:#right

Group “Info:” (
editText edt_path “Location:” align:#left labelOnTop:true
button btnSave “Save” across:3 align:#right
button btnLoad “Load” across:2 align:#right
)

on NotesRollout open do
(

textboxctrl.AcceptsReturn = true;

textboxctrl.AcceptsTab = true;

textboxctrl.WordWrap = true;

textboxctrl.Multiline = true;

textboxctrl.ScrollBars = textboxctrl.ScrollBars.Vertical;
)

on textboxctrl keydown pressedKey do
(
if (pressedKey.keyvalue == 13) do textboxctrl.paste("\r\n");
)
on btnSave pressed do --save as a text file that can be opened with plugin in a local directory
(

  folderPath = getSavePath()
  edt_path.text = folderPath
  if (dir != undefined) do (folderPathTxt.text = dir)
  out_name = ""
  out_file = createfile out_name

)
on btnLoad pressed do --open notes that relate to this file ( would love to make this load relating to file name from start up ) and deletes the old textbox text
(
folderPath = getSavePath()

)

on btnClearAll pressed do – clear all data fields (struggling to define text in text box)
(

  delete savedData
  textboxctrl.text = savedData

)

)

createDialog NotesRollout;
)

I’m having trouble creating the text file and then being able to load it and actually clear the text field.

Would anyone have any suggestions as to what I am doing wrong for pointing to the text field in a dotNet?
and then how to export/load the text?

Thank you in advance for all your help.


#2

You could use the fileProperties to save/read the comments and avoid working with external files if all you need is plain text.

-- Save text
fileProperties.addProperty #summary "Comments" "YOUR NOTES HERE"

--Read text
fileProperties.getPropertyValue #summary 3

#3

Oh my Glorb! I’ll try this when I get to my desk this is what I wanted from the get go! Thank you for the advice!


#4

I just realized that the “Comments” property index won’t always be 3, so before you start getting a lot of errors while attempting to read it here is a complete rollout.

It isn’t bullet proof, so you still may need to do some work on it.

(
	
	try destroydialog ::RO_PROJECT_NOTES catch()
	
	rollout RO_PROJECT_NOTES "Project Notes" width:360 height:330
	(
		dotNetControl textbox "System.Windows.Forms.TextBox" pos:[8,8] width:344 height:224
		
		button   bt_read       "Read"      pos:[184,240] width:84 height:28
		button   bt_clear      "Clear"     pos:[268,240] width:84 height:28
		button   bt_save       "Save"      pos:[268,276] width:84 height:28
		checkbox chk_overwrite "Overwrite" pos:[268,308] checked:true
		
		fn ReadNotes =
		(
			-- Find the "Comments" property index. For new files it is 0 so we can't use it
			index = fileProperties.findProperty #summary "Comments"
			if index > 0 then textbox.text = fileProperties.getPropertyValue #summary index else textbox.text = ""
		)
		
		fn SaveNotes =
		(
			overwrite = chk_overwrite.checked
			if overwrite == false do
			(
				overwrite = querybox "Would you like to overwrite the current Project Notes?"
			)
			if overwrite == true do fileProperties.addProperty #summary "Comments" textbox.text
		)
		
		fn RemoveCallbacks =
		(
			callbacks.removeScripts id:#ID_0X5AC4E92C
		)
		
		fn AddCallbacks =
		(
			-- Remove all callbacks if we have create any
			RemoveCallbacks()
			
			-- Add callbacks to automatically read the Projects Notes when a file is load
			callbacks.addScript #filePostOpen    "RO_PROJECT_NOTES.ReadNotes()" id:#ID_0X5AC4E92C
			callbacks.addScript #systemPostNew   "RO_PROJECT_NOTES.ReadNotes()" id:#ID_0X5AC4E92C
			callbacks.addScript #systemPostReset "RO_PROJECT_NOTES.ReadNotes()" id:#ID_0X5AC4E92C
		)
		
		on RO_PROJECT_NOTES open do
		(
			textbox.AcceptsReturn = true
			textbox.AcceptsTab    = true
			textbox.WordWrap      = true
			textbox.Multiline     = true
			textbox.ScrollBars    = textbox.ScrollBars.Vertical
			
			AddCallbacks()
			ReadNotes()
		)
		
		on textbox keydown key do
		(
			if (key.keyvalue == 13) do textbox.paste("\r\n")
		)
		
		on bt_read pressed do ReadNotes()
		
		on bt_clear pressed do textbox.text = ""
			
		on bt_save pressed do SaveNotes()
	)
	
	createdialog RO_PROJECT_NOTES style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)
	
)

#5

Thank you so very much! This does the trick! I have a lot to learn to make more ui tools.

My only other question is now I’ve made an Icon and put it with the .ms file, zipped them up and renamed it to a .mzp file.

The icon wont load with the .mzp. What does the “#” refer to? and the , 1 or number that would go there for loading a script? Sorry to ask such remedial questions, but I would like to have some basic knowledge to problem solve in the future.

macroScript ProjectNote
category:“Project Notes”
toolTip:“Project Notes”
ButtonText:“ProjectNotes”
icon:#(“ProjectNotes_Icon”,1)
(
(

  try destroydialog ::RO_PROJECT_NOTES catch()
  
  rollout RO_PROJECT_NOTES "Project Notes" width:360 height:330
  (
  	dotNetControl textbox "System.Windows.Forms.TextBox" pos:[8,8] width:344 height:224
  	
  	button   bt_read       "Read"      pos:[184,240] width:84 height:28
  	button   bt_clear      "Clear"     pos:[268,240] width:84 height:28
  	button   bt_save       "Save"      pos:[268,276] width:84 height:28
  	checkbox chk_overwrite "Overwrite" pos:[268,308] checked:true
  	
  	fn ReadNotes =
  	(
  		-- Find the "Comments" property index. For new files it is 0 so we can't use it
  		index = fileProperties.findProperty #summary "Comments"
  		if index > 0 then textbox.text = fileProperties.getPropertyValue #summary index else textbox.text = ""
  	)
  	
  	fn SaveNotes =
  	(
  		overwrite = chk_overwrite.checked
  		if overwrite == false do
  		(
  			overwrite = querybox "Would you like to overwrite the current Project Notes?"
  		)
  		if overwrite == true do fileProperties.addProperty #summary "Comments" textbox.text
  	)
  	
  	fn RemoveCallbacks =
  	(
  		callbacks.removeScripts id:#ID_0X5AC4E92C
  	)
  	
  	fn AddCallbacks =
  	(
  		-- Remove all callbacks if we have create any
  		RemoveCallbacks()
  		
  		-- Add callbacks to automatically read the Projects Notes when a file is load
  		callbacks.addScript #filePostOpen    "RO_PROJECT_NOTES.ReadNotes()" id:#ID_0X5AC4E92C
  		callbacks.addScript #systemPostNew   "RO_PROJECT_NOTES.ReadNotes()" id:#ID_0X5AC4E92C
  		callbacks.addScript #systemPostReset "RO_PROJECT_NOTES.ReadNotes()" id:#ID_0X5AC4E92C
  	)
  	
  	on RO_PROJECT_NOTES open do
  	(
  		textbox.AcceptsReturn = true
  		textbox.AcceptsTab    = true
  		textbox.WordWrap      = true
  		textbox.Multiline     = true
  		textbox.ScrollBars    = textbox.ScrollBars.Vertical
  		
  		AddCallbacks()
  		ReadNotes()
  	)
  	
  	on textbox keydown key do
  	(
  		if (key.keyvalue == 13) do textbox.paste("\r\n")
  	)
  	
  	on bt_read pressed do ReadNotes()
  	
  	on bt_clear pressed do textbox.text = ""
  		
  	on bt_save pressed do SaveNotes()
  )
  
  createdialog RO_PROJECT_NOTES style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)

)
)


#6

Please do a search on how to add an icon to a MacroScript. It has been answered many times here and in other forums as well as in the MXS help.

The # symbol defines an array in this case.

#(“ProjectNotes_Icon”, 1)

-- This is an array with 2 items, 1 string and 1 integer.

#7

Thank you again! I’m really new to this process and have been trying to decipher what code is being used for what and where.


#8

You can check this(paid script) if you want: https://miauu-maxscript.com/portfolio-item/miauu-scene-notes-pro/


#9

I saw that one and it was where I knew this was a possible idea from. I’m absolutely horrible with code, so my goal was to attempt to understand more of why things are being written instead of copy pasting and hoping it works lol.


#10

In a continuation to learn, and get unstuck I got to here with googling and copy and pasting. — installer issue

error

my folder that I want to compress looks like this:

The installer is where I think I’m having the most trouble following what’s happening and what I need to do to call my scripts from the .MZP

mzp.run

name “ProjectNotes”
description “Scripts”
version 1

copy “ProjectNotesScript.ms” to “$userScripts”
copy “NotePad_Icon_24i.bmp” to “$userIcons”
copy “NotePad_Icon_24a.bmp” to “$userIcons”
copy “NotePad_Icon_16i.bmp” to “$userIcons”
copy “NotePad_Icon_16a.bmp” to “$userIcons”
copy “install_script.ms” to “$userScripts”

run “install_script.ms”
drop “install_script.ms”

clear temp on MAX exit
clear temp on reset

installer.ms

– actionMan.executeAction 0 “40472” – MAX Script: MAXScript Listener
– clearListener()

print “install mpz package…”

src = GetDir $temp + “/ProjectNotesScript.ms”
dst = GetDir $userScripts + “/ProjectNotesScript.ms”

if (doesFileExist dst) then (
format “remove existing file %…\n” dst
deleteFile dst
print “OK”
)

if (doesFileExist dst2) then (
format “remove existing file %…\n” dst2
deleteFile dst2
print “OK”
)

format “copy % to %…\n” src dst
– format “copy % to %…\n” src2 dst2

System_IO_File = dotNetClass “System.IO.File”
System_IO_File.Copy src dst
System_IO_File.Copy src2 dst2
print “OK”

print “run the macro, to install it…”
filein “$userScripts//ProjectNotesScript.ms”
print “OK”

– Display only a small Info
str = “MZP Plugin installed.”

messageBox str title:“Script installed.”

print “-- END --”

and my ini

[Header]
name=ProjectNotes
description=note feature
[config]
sourcerootpath=C:Notes
runfilepath=C:notesInstallfiles
buildfilename=ProjectNotes
buildfilepath=C:ProjectNotesBuild
[Source]
1=ProjectNotesScript.ms
2=NotePad_Icon_24i.bmp
3=NotePad_Icon_24a.bmp
4=NotePad_Icon_16i.bmp
5=NotePad_Icon_16a.bmp
6=install_script.ms
[Destination]
1=$userScriptsProjectNotes
2=$userIcons
3=$userIcons
4=$userIcons
5=$userIcons
6=$userScriptsProjectNotes
[DropIndicates]
1=6
[RunIndicates]
1=6

It may seem very remedial but I’m not exactly sure on what to search and do research on as I’ve spent the last few days to get this far, and had to have major help so far. I assume it has to do with the mzp.run, but is it a syntax thing?


#11

I don’t know if this will help but replace all / with \ in your paths to files/folders

filein “$userScripts\\ProjectNotesScript.ms”

Also you can comment this line

filein “$userScripts//ProjectNotesScript.ms”

and can run your installer again. Then check if all files are where you want them to be. If ProjectNotesScript.ms is in the $userScripts then fileIn will work.


#12

I think this solved it, I had to manually add the script, but this should be good enough! thank you again to everyone who gave me help!

I still have a lot to learn with maxscript, but at least I got my feet wet.