Community
Meshmixer
Welcome to Autodesk’s Meshmixer Forums. Share your knowledge, ask questions, and explore popular Meshmixer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MagWeb's mmApi scripts

71 REPLIES 71
Reply
Message 1 of 72
MagWeb
7406 Views, 71 Replies

MagWeb's mmApi scripts

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:

 

 

 

Screencast will be displayed here after you click Post.

bf8ff1a3-6198-4d7d-8e47-90d793fed1fb

 



Gunter Weber
Triangle Artisan

71 REPLIES 71
Message 61 of 72
hfcandrew
in reply to: MagWeb

Oh I see! Yes the transformation are working now all in any scene. (So now its only the face transform and soft transform of a selection which are still scene dependent.)

 

Thanks so much for an early Christmas gift!

Message 62 of 72

Hello .. Good night!
I recently started working with MM.
I work in dentistry and spend a lot of time preparing the models for 3D printing.
My repetitive process:
1. I import all models for each patient (about 20 per patient);
2. Select one by one and apply the "remesh";
3. I import numbered bars, which serve to increase the adhesion of the models on the printer platform;
4. Select model 01, bar 01 and execute a "boolean union"
5. Select the model resulting from the previous item and execute a "boolean difference", to drain the resin;
6. I export each .stl template to the patient's folder.

I was wondering if there is any way to automate at least part of this process, which consumes a lot of time in front of the computer, when I could be taking care of other tasks.
I am so grateful for your help.
Message 63 of 72
MagWeb
in reply to: franciscoengcivil

Did you already manage to setup mmApi? This isn't built in a Meshmixer installation.

Note this topic  and Andrew's version if you are on WIN10

 

Basically the whole process should be possible (although step5 isn't clear to me. What is the object you want to subtract from the result in step4?)

Think you should use fix file names within a patient's folder (e.g. tooth1.stl, tooth2.stl, tooth3.stl,...). This allows to find the corresponding objects (e.g. for step4) by their names automatically. 

 

You might try my ToolManager script (use the version attached in message 58 of this topic) to store the tools to a compose a workflow (which can be saved as a .csv table). It doesn't support the activation of certain objects yet (if I find time this would be a nice update) but this could be the first step.



Gunter Weber
Triangle Artisan

Message 64 of 72
franciscoengcivil
in reply to: MagWeb

Hello, MagWeb!
First of all, I appreciate your availability to help me.
I'm uploading a video I made, an entire process that I do, repeatedly, between 50 and 100 times a day.
Unfortunately, the export was not recorded at the end of the video.
Thanks for everything.
Message 65 of 72

you can use combine i dont think you need to make boolian speatialy its complicated 

Message 66 of 72
danyatallah
in reply to: MagWeb

can you please make exe stand alone  version of toolmanager 

Message 67 of 72
j2samodal
in reply to: MagWeb

Followed setup instructions. GUI does not appear. Test.py fails on bunny. Tried everything I know. Visual Studio 2012 installed. Nothing works

 

Message 68 of 72
MagWeb
in reply to: j2samodal

Which Python did you install?

Basically you need to load a script to the python IDLE and run the script from there. IDLE menu: Run>RunModule

If test.py doesn't work no other mmApi script will.



Gunter Weber
Triangle Artisan

Message 69 of 72
grahamJDGU9
in reply to: MagWeb

Hey not sure if this thread is dead or not, but I am having trouble with ToolManager_V3 (actually I've tried with all 3 and am still getting this issue).

 

I have 3 steps that need to be done: selectAll, remesh, and makePattern. selectAll and remesh work fine, but makePattern is unable to change the number fields. I need to change the Pattern type (which works), but when trying to change the Element dimension (dimension 1 if I'm not mistaken) the value of 2.5mm doesn't work and it reverts back to 2mm when the tool Plays All. I've checked the csv and the 2.5mm is there in the settings, so I can't figure out why it won't work this way?

 

Any help is appreciated, thanks.

Message 70 of 72
danyatallah
in reply to: MagWeb

I am creating c# code to get the

uint k = sc1.AppendGetToolParameterCommand("rotaion");
sc1.GetToolParameterCommandResult(k, m00.m,m01.m,m02.m,m10.m,m11.m,m12.m,m20.m,m21.m,m22.m);

the result is SwigType_p_float

what i am doing wrong here as i cant convert it to normal float

so i can use it in append _ tool _ parameter

Message 71 of 72
danyatallah
in reply to: danyatallah

i try mat3f wich break meshmixer 

as:

private void button8_Click(object sender, EventArgs e)
{

mm.RemoteControl rc = new mm.RemoteControl();
rc.Initialize();
List<int> all_objects = rc.ListObjects();
List<int> selected = rc.ListSelectedObjects();
int selectedid = selected[0];
Vector3f origin = get_object_location(rc, selectedid);
float myFloat;
StoredCommands sc1 = new StoredCommands();
mat3f mat = new mat3f();
uint k = sc1.AppendGetToolParameterCommand("rotaion");
sc1.GetToolParameterCommandResult(k,mat);

foreach (int i in all_objects)
{
List<int> objectselected = new List<int>();
objectselected.Add(i);
rc.SelectObjects(objectselected);
vec3f vec3F = origin.toVec3f();
StoredCommands sc = new StoredCommands();
sc.AppendBeginToolCommand("transform");
sc.AppendToolParameterCommand("origin", vec3F);


sc.AppendToolParameterCommand("rotation",mat);
sc.AppendCompleteToolCommand("accept");
rc.ExecuteCommands(sc);
}

rc.Shutdown();
}

Message 72 of 72
danyatallah
in reply to: danyatallah

I found the way its mat3f to flotarray9 to float

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums