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: 

makeSolid python - setting cell size?

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
gf645ZCFV
257 Views, 2 Replies

makeSolid python - setting cell size?

Hey there!

 

I am attempting to create a Python automation script that reconstructs a series of meshes using the makeSolid tool set to a certain cell size. I have a script I have used before to remesh objects and was going to update that. Basically, I want to open a mesh and use the makeSolid tool in Fast mode with the cell size set to 2.5mm. However, when I look at the mm-api documentation python_html (GitHub version linked here), I don't see all the parameters I think I need.

 

I can see I would want to set solidType to 1 for Fast Mode (with closeHoles = T and transferFaceGroups = F, which I presume are the defaults). But it seems that with solidResolution and meshResolution both taking integers, these are referring to the Solid Accuracy and Mesh Density sliders in MM. So does that mean it is impossible to set the cell size through python scripting?

 

I notice that when you type in a certain cell size in MM itself, it basically calculates the integers for Solid Accuracy and Mesh Density that would give you the closest value to the desired cell size. Perhaps is there a way to calculate what these values would be and then I could set my values to those?

 

At the moment, here is the basic code I have and I would be super keen to hear any and all ideas!

 

 

import os
import datetime

from Tkinter import *
from tkFileDialog import askdirectory
import Tkinter as tk

import mmapi
from mmRemote import *
import mm

remote = mmRemote()
remote.connect()

# Make Solid settings
stype = 1 # solid type - 1=fast?
sres = 2.5 # solid resolution - 2.5mm???
mres = 2.5 # mesh resolution - 2.5mm???
hole = True # close holes - True
#offset = 0 # offset distance - 0mm
#minthic = 0 # minimum thickness - 0mm
fg = False # transfer face groups - False

def Load_File():
    #print("Load_File method start")
    input_dir = askdirectory(parent = root)
    #print(str(input_dir))
    if input_dir is "":
        return
    #print("supported extensions")
    supported_extensions = ['ply'] # can I import ply?
    file_List = [fn for fn in os.listdir(input_dir)if any(fn.endswith(ext) for ext in supported_extensions)]
    #print("file_List: " + str(len(file_List)))
    for i in file_List:
        #print("in the loop: " + str(input_dir+'/'+i))
        ct = datetime.datetime.now()
        print("**Starting new model " + i + " at " + str(ct))
        mm.append_objects_from_file(remote,str(input_dir+'/'+i))
        #print("appended")
        makeSolid()
        ct = datetime.datetime.now()
        print("*****Model " + i + " completed at " + str(ct))
        Save_File(i, input_dir)

def makeSolid():
    #print("Remesh method start")
    mm.select_all(remote)
    mm.begin_tool(remote, "makeSolid")
    mm.set_toolparam(remote, "solidType", stype)
    mm.set_toolparam(remote, "solidResolution", sres)
    mm.set_toolparam(remote, "meshResolution", mres)
    mm.set_toolparam(remote, "closeHoles", hole)
    #mm.set_toolparam(remote, "offsetDistance", offset)
    #mm.set_toolparam(remote, "minThickness", minthic)
    mm.set_toolparam(remote, "transferFaceGroups", fg)
    # edgeCollapseThreshold
    mm.accept_tool(remote)

def Save_File(i, input_dir):
    out_dir = input_dir + '/Solidified/'
    try:
        os.mkdir(input_dir + '/Solidified')
    except:
        None
    ext = i.split('.') # splits string to elements at fullstop
    suffix = ext[-1] # extracts last element as suffix
    save_path = out_dir + ext[0] + 'R.' + suffix
    mm.export_mesh(remote,str(save_path))
    cmd = mmapi.StoredCommands()
    cmd.AppendSceneCommand_DeleteSelectedObjects();
    remote.runCommand(cmd)

# Setup a tiny GUI window:    
root = Tk()
root.title("Make Solid")
w = 240 
h = 30 
ws = root.winfo_screenwidth() 
x = ws - w
y = 0
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.attributes("-topmost", True)

button_makeSolid = tk.Button(root, text="Solidify All", command = Load_File) 
button_makeSolid.pack()

def on_closing():
    remote.shutdown()
    root.destroy()    

root.protocol("WM_DELETE_WINDOW", on_closing)
root.mainloop()

 

2 REPLIES 2
Message 2 of 3
MagWeb
in reply to: gf645ZCFV

mmApi's documentation isn't complete.

To find available parameters search in "StoredCommands.h" for the tool of interest.

 

mm.set_toolparam(remote, "solidCellSize", 2.5)
mm.set_toolparam(remote, "meshCellSize", 2.5)

 

"solidResolution" and "meshResolution" are updated along. Note: You'll get only possible CellSizes as close to your input value as possible (same as you would get inputting a value via UI). As the Resolutions are integers only it's not possible to get a fixed CellSize.



Gunter Weber
Triangle Artisan

Message 3 of 3
gf645ZCFV
in reply to: MagWeb

Thank you so much! I hadn't found that yet. Will be super useful as I push this code further!

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

Post to forums  

Autodesk Design & Make Report