Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

repetitive tasks on MM

Anonymous

repetitive tasks on MM

Anonymous
Not applicable

hi there,

 

i really need some help since at work i gotta do a repetitive task, several times, every single day at work, it is basically remesh an STL file with specific features which will be listed down below:

 

1) open the file 

2) cntrl + A

3) press R to remesh settings

4) set these features

 gaugrep.PNG

5) Export it to a folder

 

is there any way i can select the 18 STLs, process them like the steps above and export them all in a folder?

 

Any help will be much appreciated

 

thank you so much

0 Likes
Reply
Accepted solutions (1)
924 Views
5 Replies
Replies (5)

hfcandrew
Advisor
Advisor

For sure. If you know how to code you can automate it all with the mmAPI: https://github.com/meshmixer/mm-api

 

Then create your only little custom GUI and compile it into an .exe to run.

 

Would take an hour or so if you know some python, or a 6+ months if you don't.... Can be quite the undertaking depending on your starting point.

 

@MagWeb is the MM master around here, may be willing to help... or commissioned to work?...

0 Likes

MagWeb
Advisor
Advisor

This uses the last used settings of Remesh. So do some tiny selection first, enter Remesh and set your desired settings. That done cancel Remesh.

Now running the code will delete all current objects and call a file dialog where you can browse to your file and load them to MM. It will remesh the whole bundle of files and save them as something_out.stl to the same directory the files came from.

NOTE: There are two errors in scene.py which is in the mm directory.

The funktions select_objects and delete_objects need to be replaced by:

def select_objects(remote, objects_list):
    """Set the current objects selection to be the set of scene objects corresponding to the IDs in objects_list"""
    select_objects = mmapi.vectori();
    for object in objects_list:
        select_objects.push_back(object);
    cmd2 = mmapi.StoredCommands()
    cmd2.AppendSceneCommand_SelectObjects(select_objects)
    remote.runCommand(cmd2)


def delete_objects(remote, objects_list):
    """Delete the scene objects corresponding to the IDs in objects_list"""
    cur_selection = list_selected_objects(remote)
    select_objects(remote, objects_list)
    cmd = mmapi.StoredCommands()
    cmd.AppendSceneCommand_DeleteSelectedObjects();
    remote.runCommand(cmd)
    select_objects(remote, cur_selection)

That done this code should give a tiny one-button-dialog which triggers the whole process:

from Tkinter import *
from tkFileDialog   import askopenfilenames
import ttk

import mmapi
from mmRemote import *
import mm

root = Tk()
root.attributes("-topmost", True) 
remote = mmRemote()

def Remesh_Filez():
    remote.connect()
    cur_obj = mm.list_objects(remote)
    mm.delete_objects(remote, cur_obj)
    
    filez = askopenfilenames(parent = root,filetypes=[ ("OBJ","*.obj"),("STL","*.stl")] )
    if filez is"":
        return
    else:
        filez_list = root.tk.splitlist(filez)
        for filez in filez_list:
            mm.append_objects_from_file(remote, filez)
            
        items_list = mm.list_objects(remote)
        c = 0
        for items in items_list:
            mm.select_objects(remote,[items])
            mm.select_all(remote)
            mm.begin_tool(remote, "remesh")
            mm.accept_tool(remote)
            
            save_path = filez_list[c]
            out_filez = save_path.split('.')[0] + "_out.stl"
            mm.export_mesh(remote,out_filez)
            c+=1
            
        remote.shutdown()


button_Remesh = ttk.Button(root, text="Remesh All", command = Remesh_Filez) 
button_Remesh.pack()

root.mainloop()

 



Gunter Weber
Triangle Artisan

0 Likes

Anonymous
Not applicable

Thank you so much for that MagWeb, the program run nicely. however it remeshes and save only one file at a time, when i select the whole lot (more than 2 files), it shows me this error:

 

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1547, in __call__
return self.func(*args)
File "E:\Meshmixer\mmAPI\remeshMM2.py", line 24, in Remesh_Filez
mm.append_objects_from_file(remote, filez)
File "E:\Meshmixer\mmAPI\mm\scene.py", line 26, in append_objects_from_file
key = cmd.AppendSceneCommand_AppendMeshFile(filename);
File "E:\Meshmixer\mmAPI\mmapi.py", line 690, in AppendSceneCommand_AppendMeshFile
def AppendSceneCommand_AppendMeshFile(self, *args): return _mmapi.StoredCommands_AppendSceneCommand_AppendMeshFile(self, *args)
TypeError: in method 'StoredCommands_AppendSceneCommand_AppendMeshFile', argument 2 of type 'char const *'

 

 

 

 

do you know what is causing it?

Thank you so much for your time and sorry for the late reply

0 Likes

MagWeb
Advisor
Advisor
Accepted solution

While the code above works fine on a macOS system it's different on Win. After splitting a string one needs to sign the string parts as strings again on Windows. So on WIN this slightly modified code should work on multiple files:

from Tkinter import *
from tkFileDialog   import askopenfilenames
import ttk

import mmapi
from mmRemote import *
import mm

root = Tk()
root.attributes("-topmost", True) 
remote = mmRemote()

def Remesh_Filez():
    remote.connect()
    cur_obj = mm.list_objects(remote)
    mm.delete_objects(remote, cur_obj)
    
    filez = askopenfilenames(parent = root,filetypes=[ ("OBJ","*.obj"),("STL","*.stl")] )
    if filez is"":
        return
    else:
        filez_list = root.tk.splitlist(filez)
        for filez in filez_list:
            mm.append_objects_from_file(remote, str(filez))
            
        items_list = mm.list_objects(remote)
        c = 0
        for items in items_list:
            mm.select_objects(remote,[items])
            mm.select_all(remote)
            mm.begin_tool(remote, "remesh")
            mm.accept_tool(remote)
            
            save_path = filez_list[c]
            out_filez = save_path.split('.')[0] + "_out.stl"
            mm.export_mesh(remote,str(out_filez))
            c+=1
            
        remote.shutdown()


button_Remesh = ttk.Button(root, text="Remesh All", command = Remesh_Filez) 
button_Remesh.pack()

root.mainloop()


Gunter Weber
Triangle Artisan

Anonymous
Not applicable

MagWeb, you are a legend !!! it works smoothly, you made my day, you have no idea how much I appreciate this, thank you so much !!