ScriptSpot

Forum topic · Scripts Wanted

MacroscriptLister - needs repair

By Haider of Sweden · 2014-03-04

Description

Hi!

this is one of my favorite scripts, or was, since it crashes my Max 2014 nowadays.

Original credits: I dont remember :( I searched for the internet, but couldn't find where I found this script in the first place.
Great many thanks to the original author anyway. :)


macroScript MacroscriptLister
	category:"Haider"
	toolTip:"Macroscript Lister..."
	buttontext:"Macroscript Lister..."
	
(
	(
		rollout macroList "Macroscript List" (
			local mcrCategories;
			local mcrNames;
			local mcrTexts;
			
			
			dropdownlist categoryList;
			dropdownlist mcrNamesList;
			button runMcr "Run";
			
			on categoryList selected arg do (
				mcrNamesList.items = mcrTexts[arg];
			)
			
			on runMcr pressed do (
				--try (
					macros.run categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection];
				--) catch ()
			)
		)
		
		
		
		local mcrCategories	= #();
		local mcrNames			= #();
		local mcrTexts			= #();
		local mcrFiles			= #();
		
		
		
		local mcrStream = stringstream "";
		macros.list to:mcrStream;
		
		
		
		seek mcrStream 0;
		while (not (eof mcrStream)) do (
			local line = (readDelimitedString mcrStream "\n");
			local lineSplit = (filterString line "\"");
				
	 		local mcrName			= lineSplit[2];
	 		local mcrCategory		= lineSplit[6];
	 		local mcrFile			= lineSplit[8];

			local catIndex = (findItem mcrCategories mcrCategory);
			if (catIndex == 0) do (
				append mcrCategories mcrCategory;
				append mcrNames #();
				append mcrTexts #();
				append mcrFiles #();
				catIndex = mcrCategories.count;
			)
			
			append mcrNames[catIndex] mcrName;
			append mcrTexts[catIndex] mcrName;
			append mcrFiles[catIndex] mcrFile;		
		)
		
		
		local grinIndex = (findItem mcrCategories "Grin tools");
		if (grinIndex != 0) do (
			if (mcrFiles[grinIndex] != undefined) do (
				for i = 1 to mcrFiles[grinIndex].count do (
					local mcr = openFile mcrFiles[grinIndex][i];
					if (mcr != undefined) do (
						seek mcr 0;
						skipToString mcr "toolTip:";
						readDelimitedString mcr "\"";
						local newName = readDelimitedString mcr "\"";
						if (newName == "") do (
							seek mcr 0;
							skipToString mcr "buttonText:";
							readDelimitedString mcr "\"";
							newName = readDelimitedString mcr "\"";
						)
						if (newName != "") do mcrTexts[grinIndex][i] = newName;
					)
				)
			)
		)

		createdialog macroList width:400 style:#(#style_toolwindow, #style_sysmenu);	
		macroList.categoryList.items = mcrCategories;
		macroList.mcrNames = mcrNames;
		macroList.mcrTexts = mcrTexts;
		
		cui.RegisterDialogBar macroList;
	)
)

Comments (13)

.

Haider of Sweden · 2014-03-14

Yes, I think I know now who gave me the first script :)

.

Haider of Sweden · 2014-03-14

Thank you very much.

Maybe this one could be published soon ;)

.

miauu · 2014-03-14

You have to publish it from the name of its original creator. :)

.

Haider of Sweden · 2014-03-13

Works splendid. Thank you.

If you're in the mood to add an update, then:

- a parameter where the user can type what default category to show. Eg "miauu" is my most used category, then it opens that category upon running the script. If not defined, then the first is shown.

ps. about that code I commented out - can you read from it what it does?

.

miauu · 2014-03-13

You can see where to write the default category.


rollout macroList "Macroscript List" 
	(
		local defaultCategory = "miauu"
		local mcrCategories;
		local mcrNames;
		local mcrTexts;
 
		dropdownlist categoryList height:50;
		dropdownlist mcrNamesList height:50 ;
		button runMcr "Run" width:100 tooltip:"Run the Macro" across:3
		button editMCR "Edit" tooltip:"Edit the Macro"  width:100
		button btn_refresh "Refresh" tooltip:"Refresh list"  width:100
 
		function QuickSortByName subArr1 subArr2 = striCmp subArr1[1] subArr2[1]
 
		function Reload =
		(
			local mcrCategoriesArr = #();
			local mcrNamesArr	= #();
			local mcrTextsArr = #();
			local mcrFilesArr = #();
 
			local mcrStream = stringstream "";
			macros.list to:mcrStream;
 
			seek mcrStream 0;
			while (not (eof mcrStream)) do 
			(
				local line = (readDelimitedString mcrStream "\n");
				local lineSplit = (filterString line "\"");
				local mcrName = lineSplit[2];
				local mcrCategory = lineSplit[6];
				local mcrFile = lineSplit[8];
 
				local catIndex = (findItem mcrCategoriesArr mcrCategory);
				if (catIndex == 0) do 
				(
					append mcrCategoriesArr mcrCategory;
					append mcrNamesArr #();
					append mcrTextsArr #();
					append mcrFilesArr #();
					catIndex = mcrCategoriesArr.count;
				)
 
				append mcrNamesArr[catIndex] mcrName;
				append mcrTextsArr[catIndex] mcrName;
				append mcrFilesArr[catIndex] mcrFile;		
			)
			--	sort the macros
			for arr in mcrNamesArr do qSort arr QuickSortByName
			/* 	
			local grinIndex = (findItem mcrCategoriesArr "CatName");
			if (grinIndex != 0) do 
			(
				if (mcrFilesArr[grinIndex] != undefined) do 
				(
					for i = 1 to mcrFilesArr[grinIndex].count do 
					(
						local mcr = openFile mcrFilesArr[grinIndex][i];
						if (mcr != undefined) do 
						(
							seek mcr 0;
							skipToString mcr "toolTip:";
							readDelimitedString mcr "\"";
							local newName = readDelimitedString mcr "\"";
							if (newName == "") do (
								seek mcr 0;
								skipToString mcr "buttonText:";
								readDelimitedString mcr "\"";
								newName = readDelimitedString mcr "\"";
							)
							if (newName != "") do mcrTextsArr[grinIndex][i] = newName;
						)
					)
				)
			)
			*/
			toSortArr = #()
			for i = 1 to mcrCategoriesArr.count do append toSortArr #(mcrCategoriesArr[i], mcrNamesArr[i], mcrTextsArr[i])
			qSort toSortArr QuickSortByName
			mcrCategoriesArr = #()
			mcrNamesArr = #()
			mcrTextsArr = #()
			for i = 1 to toSortArr.count do
			(
				append mcrCategoriesArr toSortArr[i][1]
				append mcrNamesArr toSortArr[i][2]
				append mcrTextsArr toSortArr[i][2]
			)
			categoryList.items = mcrCategoriesArr;
			mcrNames = mcrNamesArr;
			mcrTexts = mcrTextsArr;
			--	set the desired category
			if defaultCategory != undefined and classOf defaultCategory == string then
			(
				cat = findItem mcrCategoriesArr defaultCategory
				categoryList.selection= cat
				mcrNamesList.items = mcrTexts[cat]
			)
			else
			(
				mcrNamesList.items = mcrTexts[1]
			)
		)
 
		on categoryList selected arg do 
		(
			mcrNamesList.items = mcrTexts[arg];
		)
 
		on runMcr pressed do
		(
			macros.run categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection];
		)
 
		on editMcr pressed do
		(
			macros.edit categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection]; 
		)
 
		on macroList open do
		(
			Reload()
		)
	)
	createdialog macroList width:400 style:#(#style_toolwindow, #style_sysmenu);	
	

The comented part of the script searches for a script category with name "CatName". If this category exist then the rest of the codes does something with the name of the scripts by readin them from the mcr files.

.

Haider of Sweden · 2014-03-12

Hello again,

I noticed that some category items slipped out of the order and the Macroscript is not alphabetical at all. I dont know if I did anything wrong, so I attach the latest code, plus some screen dumps.

There is a part on row 60 I commented out (maybe I shouldn't?) - what does it do?

Attachments

.

miauu · 2014-03-12

Try this:


rollout macroList "Macroscript List" 
	(
		local mcrCategories;
		local mcrNames;
		local mcrTexts;
 
		dropdownlist categoryList height:50;
		dropdownlist mcrNamesList height:50 ;
		button runMcr "Run" width:100 tooltip:"Run the Macro" across:3
		button editMCR "Edit" tooltip:"Edit the Macro"  width:100
		button btn_refresh "Refresh" tooltip:"Refresh list"  width:100

		function QuickSortByName subArr1 subArr2 = striCmp subArr1[1] subArr2[1]
 
		function Reload =
		(
			local mcrCategoriesArr = #();
			local mcrNamesArr	= #();
			local mcrTextsArr = #();
			local mcrFilesArr = #();
 
			local mcrStream = stringstream "";
			macros.list to:mcrStream;
 
			seek mcrStream 0;
			while (not (eof mcrStream)) do 
			(
				local line = (readDelimitedString mcrStream "\n");
				local lineSplit = (filterString line "\"");
				local mcrName = lineSplit[2];
				local mcrCategory = lineSplit[6];
				local mcrFile = lineSplit[8];
 
				local catIndex = (findItem mcrCategoriesArr mcrCategory);
				if (catIndex == 0) do 
				(
					append mcrCategoriesArr mcrCategory;
					append mcrNamesArr #();
					append mcrTextsArr #();
					append mcrFilesArr #();
					catIndex = mcrCategoriesArr.count;
				)
				
				append mcrNamesArr[catIndex] mcrName;
				append mcrTextsArr[catIndex] mcrName;
				append mcrFilesArr[catIndex] mcrFile;		
			)
			--	sort the macros
			for arr in mcrNamesArr do qSort arr QuickSortByName
			/* 	
			local grinIndex = (findItem mcrCategoriesArr "CatName");
			if (grinIndex != 0) do 
			(
				if (mcrFilesArr[grinIndex] != undefined) do 
				(
					for i = 1 to mcrFilesArr[grinIndex].count do 
					(
						local mcr = openFile mcrFilesArr[grinIndex][i];
						if (mcr != undefined) do 
						(
							seek mcr 0;
							skipToString mcr "toolTip:";
							readDelimitedString mcr "\"";
							local newName = readDelimitedString mcr "\"";
							if (newName == "") do (
								seek mcr 0;
								skipToString mcr "buttonText:";
								readDelimitedString mcr "\"";
								newName = readDelimitedString mcr "\"";
							)
							if (newName != "") do mcrTextsArr[grinIndex][i] = newName;
						)
					)
				)
			)
			*/
			toSortArr = #()
			for i = 1 to mcrCategoriesArr.count do append toSortArr #(mcrCategoriesArr[i], mcrNamesArr[i], mcrTextsArr[i])
			qSort toSortArr QuickSortByName
			mcrCategoriesArr = #()
			mcrNamesArr = #()
			mcrTextsArr = #()
			for i = 1 to toSortArr.count do
			(
				append mcrCategoriesArr toSortArr[i][1]
				append mcrNamesArr toSortArr[i][2]
				append mcrTextsArr toSortArr[i][2]
			)
			categoryList.items = mcrCategoriesArr;
			mcrNames = mcrNamesArr;
			mcrTexts = mcrTextsArr;
			mcrNamesList.items = mcrTexts[1]
		)
 
		on categoryList selected arg do 
		(
			mcrNamesList.items = mcrTexts[arg];
		)
 
		on runMcr pressed do
		(
			macros.run categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection];
		)
 
		on editMcr pressed do
		(
			macros.edit categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection]; 
		)
 
		on macroList open do
		(
			Reload()
		)
	)
	createdialog macroList width:400 style:#(#style_toolwindow, #style_sysmenu);	

.

miauu · 2014-03-04

The script will works if you remove the line that register the script as dialog bar. You will no longer be able to dock the UI, but at least the non docked UI will works as it should.


macroScript MacroscriptLister
	category:"Haider"
	toolTip:"Macroscript Lister..."
	buttontext:"Macroscript Lister..."
 
(
	(
		rollout macroList "Macroscript List" (
			local mcrCategories;
			local mcrNames;
			local mcrTexts;
 
 
			dropdownlist categoryList;
			dropdownlist mcrNamesList;
			button runMcr "Run";
 
			on categoryList selected arg do (
				mcrNamesList.items = mcrTexts[arg];
			)
 
			on runMcr pressed do (
				--try (
					macros.run categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection];
				--) catch ()
			)
		)
 
 
 
		local mcrCategories	= #();
		local mcrNames			= #();
		local mcrTexts			= #();
		local mcrFiles			= #();
 
 
 
		local mcrStream = stringstream "";
		macros.list to:mcrStream;
 
 
 
		seek mcrStream 0;
		while (not (eof mcrStream)) do (
			local line = (readDelimitedString mcrStream "\n");
			local lineSplit = (filterString line "\"");
 
	 		local mcrName			= lineSplit[2];
	 		local mcrCategory		= lineSplit[6];
	 		local mcrFile			= lineSplit[8];
 
			local catIndex = (findItem mcrCategories mcrCategory);
			if (catIndex == 0) do (
				append mcrCategories mcrCategory;
				append mcrNames #();
				append mcrTexts #();
				append mcrFiles #();
				catIndex = mcrCategories.count;
			)
 
			append mcrNames[catIndex] mcrName;
			append mcrTexts[catIndex] mcrName;
			append mcrFiles[catIndex] mcrFile;		
		)
 
 
		local grinIndex = (findItem mcrCategories "Grin tools");
		if (grinIndex != 0) do (
			if (mcrFiles[grinIndex] != undefined) do (
				for i = 1 to mcrFiles[grinIndex].count do (
					local mcr = openFile mcrFiles[grinIndex][i];
					if (mcr != undefined) do (
						seek mcr 0;
						skipToString mcr "toolTip:";
						readDelimitedString mcr "\"";
						local newName = readDelimitedString mcr "\"";
						if (newName == "") do (
							seek mcr 0;
							skipToString mcr "buttonText:";
							readDelimitedString mcr "\"";
							newName = readDelimitedString mcr "\"";
						)
						if (newName != "") do mcrTexts[grinIndex][i] = newName;
					)
				)
			)
		)
 
		createdialog macroList width:400 style:#(#style_toolwindow, #style_sysmenu);	
		macroList.categoryList.items = mcrCategories;
		macroList.mcrNames = mcrNames;
		macroList.mcrTexts = mcrTexts;
 
		-- cui.RegisterDialogBar macroList;
	)
)

.

Haider of Sweden · 2014-03-04

Works now, thank you very much.

Why did it crash in the first place? Didnt crash on 2013 what I remember...

- How can the dropdownlist categoryList and mcrNamesList be ordered alphabetically?- - Does maxscript support refresh, so that there could be a button next to "Run", or do I have to close and repoen?

.

miauu · 2014-03-04


macroScript MacroscriptLister
category:"Haider"
toolTip:"Macroscript Lister..."
buttontext:"Macroscript Lister..." 
(
	
	rollout macroList "Macroscript List" 
	(
		local mcrCategories;
		local mcrNames;
		local mcrTexts;

		dropdownlist categoryList;
		dropdownlist mcrNamesList;
		button runMcr "Run" width:100 across:2
		button btn_refresh "Refresh" width:100 offset:[0,0]
		
		function QuickSortByName subArr1 subArr2 =
		(
			local idx1 = subArr1[1]
			local idx2 = subArr2[1]
			case of 
			(
				(idx1 < idx2): (-1)
				(idx1 > idx2): (1)
				default:0
			)
		)
		
		function Reload =
		(
			local mcrCategoriesArr	= #();
			local mcrNamesArr			= #();
			local mcrTextsArr			= #();
			local mcrFilesArr			= #();
			
			local mcrStream = stringstream "";
			macros.list to:mcrStream;
			
			seek mcrStream 0;
			while (not (eof mcrStream)) do 
			(
				local line = (readDelimitedString mcrStream "\n");
				local lineSplit = (filterString line "\"");

				local mcrName			= lineSplit[2];
				local mcrCategory		= lineSplit[6];
				local mcrFile			= lineSplit[8];

				local catIndex = (findItem mcrCategoriesArr mcrCategory);
				if (catIndex == 0) do 
				(
					append mcrCategoriesArr mcrCategory;
					append mcrNamesArr #();
					append mcrTextsArr #();
					append mcrFilesArr #();
					catIndex = mcrCategoriesArr.count;
				)

				append mcrNamesArr[catIndex] mcrName;
				append mcrTextsArr[catIndex] mcrName;
				append mcrFilesArr[catIndex] mcrFile;		
			)

			local grinIndex = (findItem mcrCategoriesArr "Grin tools");
			if (grinIndex != 0) do 
			(
				if (mcrFilesArr[grinIndex] != undefined) do 
				(
					for i = 1 to mcrFilesArr[grinIndex].count do 
					(
						local mcr = openFile mcrFilesArr[grinIndex][i];
						if (mcr != undefined) do 
						(
							seek mcr 0;
							skipToString mcr "toolTip:";
							readDelimitedString mcr "\"";
							local newName = readDelimitedString mcr "\"";
							if (newName == "") do (
								seek mcr 0;
								skipToString mcr "buttonText:";
								readDelimitedString mcr "\"";
								newName = readDelimitedString mcr "\"";
							)
							if (newName != "") do mcrTextsArr[grinIndex][i] = newName;
						)
					)
				)
			)
			toSortArr = #()
			for i = 1 to mcrCategoriesArr.count do append toSortArr #(mcrCategoriesArr[i], mcrNamesArr[i], mcrTextsArr[i])
			qsort toSortArr QuickSortByName
			mcrCategoriesArr = #()
			mcrNamesArr = #()
			mcrTextsArr = #()
			for i = 1 to toSortArr.count do
			(
				append mcrCategoriesArr toSortArr[i][1]
				append mcrNamesArr toSortArr[i][2]
				append mcrTextsArr toSortArr[i][2]
			)
			categoryList.items = mcrCategoriesArr;
			mcrNames = mcrNamesArr;
			mcrTexts = mcrTextsArr;
		)

		on categoryList selected arg do 
		(
			mcrNamesList.items = mcrTexts[arg];
		)

		on runMcr pressed do
		(
			macros.run categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection];
		)
		
		on macroList open do
		(
			Reload()
		)
	)
	createdialog macroList width:400 style:#(#style_toolwindow, #style_sysmenu);	
)

.

Haider of Sweden · 2014-03-05

Many thanks my friend. Works like a charm.

To make it even more useful, I added


button editMCR "Edit" width:100

and


on editMcr pressed do
(
macros.edit categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection]; 
)


There is a tiny bug of some sort.

When you run the script, you see the first category, but the dropdownlist mcrNamesList appears empty. You will have to pick the category again to make the mcrNamesList show something.
Can this be fixed?

.

miauu · 2014-03-06


macroScript MacroscriptLister
category:"Haider"
toolTip:"Macroscript Lister..."
buttontext:"Macroscript Lister..." 
(
 
	rollout macroList "Macroscript List" 
	(
		local mcrCategories;
		local mcrNames;
		local mcrTexts;
 
		dropdownlist categoryList;
		dropdownlist mcrNamesList;
		button runMcr "Run" width:100 across:3
		button editMCR "Edit" width:100
		button btn_refresh "Refresh" width:100
 
		function QuickSortByName subArr1 subArr2 =
		(
			local idx1 = subArr1[1]
			local idx2 = subArr2[1]
			case of 
			(
				(idx1 < idx2): (-1)
				(idx1 > idx2): (1)
				default:0
			)
		)
 
		function Reload =
		(
			local mcrCategoriesArr	= #();
			local mcrNamesArr			= #();
			local mcrTextsArr			= #();
			local mcrFilesArr			= #();
 
			local mcrStream = stringstream "";
			macros.list to:mcrStream;
 
			seek mcrStream 0;
			while (not (eof mcrStream)) do 
			(
				local line = (readDelimitedString mcrStream "\n");
				local lineSplit = (filterString line "\"");
 
				local mcrName			= lineSplit[2];
				local mcrCategory		= lineSplit[6];
				local mcrFile			= lineSplit[8];
 
				local catIndex = (findItem mcrCategoriesArr mcrCategory);
				if (catIndex == 0) do 
				(
					append mcrCategoriesArr mcrCategory;
					append mcrNamesArr #();
					append mcrTextsArr #();
					append mcrFilesArr #();
					catIndex = mcrCategoriesArr.count;
				)
 
				append mcrNamesArr[catIndex] mcrName;
				append mcrTextsArr[catIndex] mcrName;
				append mcrFilesArr[catIndex] mcrFile;		
			)
 
			local grinIndex = (findItem mcrCategoriesArr "Grin tools");
			if (grinIndex != 0) do 
			(
				if (mcrFilesArr[grinIndex] != undefined) do 
				(
					for i = 1 to mcrFilesArr[grinIndex].count do 
					(
						local mcr = openFile mcrFilesArr[grinIndex][i];
						if (mcr != undefined) do 
						(
							seek mcr 0;
							skipToString mcr "toolTip:";
							readDelimitedString mcr "\"";
							local newName = readDelimitedString mcr "\"";
							if (newName == "") do (
								seek mcr 0;
								skipToString mcr "buttonText:";
								readDelimitedString mcr "\"";
								newName = readDelimitedString mcr "\"";
							)
							if (newName != "") do mcrTextsArr[grinIndex][i] = newName;
						)
					)
				)
			)
			toSortArr = #()
			for i = 1 to mcrCategoriesArr.count do append toSortArr #(mcrCategoriesArr[i], mcrNamesArr[i], mcrTextsArr[i])
			qsort toSortArr QuickSortByName
			mcrCategoriesArr = #()
			mcrNamesArr = #()
			mcrTextsArr = #()
			for i = 1 to toSortArr.count do
			(
				append mcrCategoriesArr toSortArr[i][1]
				append mcrNamesArr toSortArr[i][2]
				append mcrTextsArr toSortArr[i][2]
			)
			categoryList.items = mcrCategoriesArr;
			mcrNames = mcrNamesArr;
			mcrTexts = mcrTextsArr;
			mcrNamesList.items = mcrTexts[1]
		)
 
		on categoryList selected arg do 
		(
			mcrNamesList.items = mcrTexts[arg];
		)
 
		on runMcr pressed do
		(
			macros.run categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection];
		)
		
		on editMcr pressed do
		(
			macros.edit categoryList.selected mcrNames[categoryList.selection][mcrNamesList.selection]; 
		)
 
		on macroList open do
		(
			Reload()
		)
	)
	createdialog macroList width:400 style:#(#style_toolwindow, #style_sysmenu);	
)

.

Haider of Sweden · 2014-03-06

Thank you :)