MagWeb's mmApi scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Instead of spreading scripts all over the forum I'll post them in this thread from now on.
1 Script:
ToolManager
On a user's request I repost a message I did at MM's old forum on March 23, 2018, 01:30:51 PM:
Download below
"
Here’s a long raw script meant to run api commands without coding a .py file. Well, you’ll need the api to run (important instructions at post’s bottom) or compile the script to a standalone application (recommended it’s easy and seems to be faster) but after that it’s something I find very useful. I post it as it is without any warranty at your own risk in the hope you find it useful and maybe some better coder polishes this…
Why to use it:
For some tools MM remembers the last used parameter setting. For some tools or special parameters it always loads hard coded default values entering a tool. Now what to do if you want the parameters at a step before „last“ or different to defaults? In MM you always have to set this manually - hopefully your own brain remembers all parameters…..
What this script does:
With this ToolManager you can save current tool parameters and reload them. Means you can save several settings for the same tool and others as well.
As there is no direct function to get the current tool’s name in mmApi and it needs to be known to call this very tool and its parameters again, I use a pretty ugly workaround:
There’s a long list of tools and their parameters (BTW: There are more parameters than listed in the documentation or StoredCommands.h, so see this list as a reference too). As the tools have unique (one exception only: Bridge and Handle use the same parameters!) combinations of parameters one can find the tool itself. So the code iterates through the list of params trying to get that kind of value from MM. If MM responds with an empty list the very parameter isn’t currently available so skip to the next…. This ends in a list of available values and a toollname fitting to this combination which is saved in ToolManager.
Usage:
+Standard Tool features:
- Hitting „Save Tool“ button will save current tool settings to the list at top if MM is in some tool. So do your settings in MM and hit „SaveTool“ before leaving the tool. You may do several saves while being in the same tool too.
- The new entry in the list will be called „setting“ + some number by default. RMB-double click (on MAC), MMB-double click (on WIN) an item in the list opens a dialog where you can set a more meaningful description.
- Hitting „Delete“ will remove an selected item from the list.
- To restore a saved tool setting LMB-double click the item in the list. Note: It will cancel a tool currently open in MM. So if you want to keep the current result hit Accept in MM first.
- To change saved parameters in a saved setting, double click the item to run the tool with saved settings. Now change your settings in MM and hit UpdateTool in ToolManager. New settings are saved to the item now.
+ AutoSet features:
- Clicking AutoSet will perform listed tool actions from top to bottom and automatically accept them. This way you can perform some kind of simple „scripting“ .
- There are tools in MM not owning some parameters (e.g. Duplicate). Therefor they can’t be detected by my approach as described above. You can add such tools at the list’s bottom by hitting AddCom. A dialog will pop up where you can choose such a command to add.
- You can copy a selected item hitting the Copy button it will be copied to the bottom of the list.
- You can move an item up/down LMB-dragging it in the list. This is needed to get the right order of commands running AutoSet
- By default all added items in the list are active while running AutoSet. If you want to exclude an item without deleting it use the +/-Auto button. This toggles between active and inactive which greys-out selected item in the list.
I/O:
- You can save the current set of saved tools to a .csv file hitting SaveSet
- You can load such a set via LoadSet. This will replace the current list
Limitations:
- Using mmApi sends each parameter one by one. So expect some „motion“ in the scene while restoring tool settings of tools using a transformation widget.
- There’s no way I found to get/save the brush-type,-falloff,-color,-stencil in SCULPT so it will still use the last used one. Against that all other brush parameters can be saved (even symmetry plane settings)
- In case of SELECT/Edit/Handle and Bridge his approach can’t decide which was used. It will always think it’s Handle (maybe fixed by a decision dialog in the future)
- Don’t expect advanced mmApi stuff on this level of simply calling tools.
- Maybe bad, inefficient coding for now but working….
################
How to run this script:
- Download and setup mmApi using instructions at: https://github.com/meshmixer/mm-api
- Download, unzip attached file „ToolManager.py“ to mm-api-master/distrib/python (or python_osx on MAC)
- Edit def get_toolparam_mat3f(remote, param_name): in tool.py (mm directory) that way:
def get_toolparam_mat3f(remote, param_name): """Returns the current value of the given Tool parameter, or empty list if the parameter is not found.""" cmd = mmapi.StoredCommands() key = cmd.AppendGetToolParameterCommand(param_name) remote.runCommand(cmd) m = mmapi.mat3f() bFound = cmd.GetToolParameterCommandResult(key, m) if bFound: return tuple(m.m) #MagWeb: added output as tuple else: return ()
tuple(m.m) is needed to return 9 element tuples instead of SWIG objects in case of rotation matrices
##################
enjoy
"
You can do stuff like this:
bf8ff1a3-6198-4d7d-8e47-90d793fed1fb
Gunter Weber
Triangle Artisan