Creating a .mzp package

Creating a .mzp package

Anonymous
Not applicable
5,581 Views
3 Replies
Message 1 of 4

Creating a .mzp package

Anonymous
Not applicable

Hello,

 

I am able to create a folder containing a .ms script, zip that folder, and rename it to a .mzp file. This allows me to drag this .mzp file into the 3ds max viewport, and that runs the .ms script by default.

 

Now, I have read I am supposed to be able to use a file in the folder described above called mzip.run, which allows scripts to be copied to proper directories, and a command called 'drop' which runs a script upon dragging the .mzp file into the viewport.

 

My goal is to drag the package into the viewport, copy a .ms file (which creates a menu and assigns a python script to be executed on click) and a python script to the scripts directory.

 

I have not been able to get the mzip.run file to do anything it is supposed to do, and there appears to be limited documentation on it.

 

This forum unfortunately won't let me post any of my code. As a simple demo, if anyone could show me how to create a mzip.run file which copies two scripts to the $script directory and runs one of them, I would be very pleased.

 

- Jed

0 Likes
Accepted solutions (1)
5,582 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable

My mzip.run file:

 

name "MZP test"

version 0.1

copy menuCreate.ms to $scripts
copy organizeLayers.py to $scripts

drop "menuCreate.ms"

menuCreate.ms :

 

macroScript Command category:"Custom Plugins" 
(
	print "menu create ran"
	python.ExecuteFile ("organizeLayers.py")
)

theMainMenu = menuMan.getMainMenuBar() --get the main menu bar
theMenu = menuMan.createMenu "Custom Plugins" --create a menu called Forum Help
theSubMenu = menuMan.createSubMenuItem "Command" theMenu --create a SubMenuItem
theMainMenu.addItem theSubMenu (theMainMenu.numItems()+1) --add the SubMenu to the Main Menu
theAction = menuMan.createActionItem "Command" "Custom Plugins" --create an ActionItem from the MacroScript
theMenu.addItem theAction (theMenu.numItems()+1) --add the ActionItem to the menu
menuMan.updateMenuBar() --update the menu bar 

organizeLayers (the content doesn't matter, not the issue, even a simple printing script in python would be enough to prove it works):

 

import MaxPlus, pymxs
from pymxs import runtime as rt

def getRTLayer(name):
	for i in range(rt.LayerManager.count):
		ilayer = rt.layerManager.getLayer(i)
		layerName = ilayer.name
		layer = rt.ILayerManager.getLayerObject(i)
		if(layerName == name):
			print "layerName: " + layerName
			return ilayer
			
def testLayer(layerName):
	
	print "in testlayer"
	layer = MaxPlus.LayerManager.GetLayer(layerName)
	name = ""
	print "before tyr"

	try:
		name = layer.GetName()
	except:
		name = "null"

	if (name != "null"):
		return True
	else:
		return False
		
nodeList = []
nodes = MaxPlus.SelectionManager.GetNodes()

for x in nodes:
	name = x.Name
	nameSplit = name.split('__')
	nodeList.append((nameSplit, x))

sortedNodes = sorted(nodeList, key = lambda x: 0- len(x[0]))
nodeCount = 0

for node in sortedNodes:
	
	hierarchy = node[0]
	value = node[1]

	hLength = len(hierarchy)
	pastLayerName = "none"
	layers = []
	
	print("Node: " + str(nodeCount))
	nodeCount += 1

	for i in range(hLength):
		
		# print("i: " + str(i))
		# print("h: " + hierarchy[i])
		
		test = testLayer(str(hierarchy[i]))
		print str(test)
		
		if(test == False):
			layer = rt.LayerManager.NewLayerFromName(hierarchy[i])
			print("layer " + hierarchy[i] + " is appended")
		else:
			print "else"		
			layer = getRTLayer(hierarchy[i])

		layers.append(layer)
		
		if(i >0):
			try:
				print("layer " + hierarchy[i-1] + " is the parent")
				# print("Layer i-1: " + layers[i-1].
				layer.setParent(layers[i-1])
			except:
				print("no")
			
		if(hLength - 1 == i):
			# print("hLength is greater than 1")
			maxLayer = MaxPlus.LayerManager.GetLayer(hierarchy[i])
			maxLayer.AddToLayer(value)
			print("Adding value...")
			

		'''
		if(pastLayerName == "none"):
			layer = rt.LayerManager.NewLayerFromName(hierarchy[i])
		else:
			layer = rt.LayerManager.NewLayerFromName(hierarchy[i])

			layer.setParent(pastLayer)
			parent = rt.LayerManager.NewLayerFromName("C")
			child = rt.LayerManager.NewLayerFromName("D")
			child.setParent(parent)
			
		print ("create layer: " + str(i))
		if(layer):
			pastLayerName = layer.getmxsprop.__name__
			pastLayer = layer
		'''
		
0 Likes
Message 3 of 4

Anonymous
Not applicable

So found some scripts online that do this sort of thing. I noticed whenever I can successfully get a copy of a python script to the temp folder it stops the plugin from installing. There seems to be some serious incompatibilities with python files and mzip.run files. Kinda talking to myself on this one but just trying to expose the root of the problem

0 Likes
Message 4 of 4

Anonymous
Not applicable
Accepted solution

For anyone struggling with mzp package development here is my solution:

 

https://github.com/jlankitus/Easy-MZP-Plugin

 

With a bit of editing, you can include any number of scripts including both python and maxscript. This also automatically creates a toolbar and sub category item which activates the plugin. I included my email in the readme, let me know if you have any questions!

 

- Jed