MeshMixer Scripting for repetive task

MeshMixer Scripting for repetive task

Anonymous
Not applicable
20,335 Views
26 Replies
Message 1 of 27

MeshMixer Scripting for repetive task

Anonymous
Not applicable

Hi there,

i get from a 3rd party software several STL-Files which i have to modify in MM.

Always the same steps:

 

1) open file 🙂

2) hollow with wall thickness 2.5 mm

3) horizontal plane cut about 1/3 of the model height from the bottom (model is plane and horizontaly aligned)

4) save/export to another directory

 

Takes a lot of time and is boring, too!

I think there should be a solution that a task will take all files from the import directory one by one, performing the operations with MM and finally save the new STLs in my output dir.

Is such a repetive task makeable with AppleScript or only with the MM API (python or C++) ?

We have iMacs as well as Windows-PCs

And, i would pay for that script of course if a solution is to time consuming.

 

Best regards and thanks in advance

Karim

0 Likes
Accepted solutions (2)
20,336 Views
26 Replies
Replies (26)
Message 21 of 27

prazmjou
Observer
Observer

I tried using this code from mmapi on github, but I have windows 10 in which I download and used  hfcandrew updated files for it to work on windows 10. Anyway we can make this work with hfcandrew updated files? Thank you

0 Likes
Message 22 of 27

Anonymous
Not applicable

Yes, one can use mmApi on WIN10. What happens on your side if you're running code? Which errors do you get in the Python Shell?

0 Likes
Message 23 of 27

prazmjou
Observer
Observer

Hello, here is an example when I used the code you placed in this thread:

 

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 "C:/Users/prazm/Downloads/Win 10 mmapi Python2-20211017T225337Z-001/Win 10 mmapi Python2/hollowask.py", line 23, in Load_File
mm.append_objects_from_file(remote,input_dir+'/'+i)
File "C:/Users/prazm/Downloads/Win 10 mmapi Python2-20211017T225337Z-001/Win 10 mmapi Python2\mm\scene.py", line 26, in append_objects_from_file
key = cmd.AppendSceneCommand_AppendMeshFile(filename);
File "C:/Users/prazm/Downloads/Win 10 mmapi Python2-20211017T225337Z-001/Win 10 mmapi Python2\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 *'

 

0 Likes
Message 24 of 27

Anonymous
Not applicable

Seems you are on WIN

On WIN one needs to convert OS paths to a string explicitly. One doesn't need to do this on MAC.

So you need to replace line 23:

mm.append_objects_from_file(remote,input_dir+'/'+i)

with:

mm.append_objects_from_file(remote,str(input_dir+'/'+i))

AND to replace line 51:

mm.export_mesh(remote,save_path)

with:

mm.export_mesh(remote,str(save_path))

 

0 Likes
Message 25 of 27

nmhoogeweg
Explorer
Explorer

Hi! Is there a way to autmatically select a boundary of an object? So without having to click on it myself. I have automated a lot of steps with the mm api, however I cannot find a way to do this. Thanks!

0 Likes
Message 26 of 27

Anonymous
Not applicable

yep, there's select_hole:

import mmapi
from mmRemote import *
import mm

remote = mmRemote()
remote.connect()

# get number of holes
holes = mm.list_number_of_holes(remote)

# launch SELECT
mm.begin_tool(remote, "select")

# select all boundary loops
## replace an existing selection for the first hole index
i=0
mm.select_hole(remote, i, mode = 0) # The modes are 0=Replace 1=Append 2=Remove
## append selections for further holes
i+=1
while i < holes:
    mm.select_hole(remote, i, mode = 1) 
    i+=1

remote.shutdown()
0 Likes
Message 27 of 27

nmhoogeweg
Explorer
Explorer

Thank you so much!! It worked perfectly. 

0 Likes