How to create a button to clear generated mesh in a faster way?
Original question from customer: “When I'm meshing in Mechanical, I usually do many cycles of generate mesh, tweak parameters, delete mesh, generate mesh.To create the mesh, there is a big "Generate" button in the ribbon.To delete the mesh, I have to go to the tree, right click Mesh, and click Clear Generated Mesh, click OK. Many clicks, lots of fiddly mouse movements.Is there a way to add buttons to the ribbon, so I could add a "Clear Mesh" next to the Generate? Or is there an easier way to clear the generated mesh?”
Best Answer
-
The script is just one line: Model.Mesh.ClearGeneratedData().
Then it is saved as a button, button is given a keyboard shortcut (from “Home” menu, “Key assignments”). Possibly, button can be added to the Quick Access Toolbar.
I could not find a way to add it to the Meshing tab.
2
Answers
-
@Pierre Thieffry how to delete meshed geometry to import another geometry for meshing
0 -
@ramsaran not sure I'm following you. Can you describe a little more what you want to achieve?
0 -
@Pierre Thieffry i am meshing 100 geometry using for loop in mechanical so i import a geometry and mesh that geometry and then save. then i want to delete then meshed geometry to import another geometry to mesh
it is some code i written to do what is mentioned abovecode
for i in range(4):
ExtAPI.Application.ImportGeometry('E:\DC_geometry\len_geometry\save{j}.scdoc'.format(j=i+1))# importing geometrymesh_15 = Model.Mesh # meshing mesh_15.GenerateMesh() ExtAPI.DataModel.Project.Model.Mesh.InternalObject.WriteFluentInputFile(r"E:\\DC_geometry\\3_meshed_geometry\\sav{j}.msh".format(j=i+1)) # saving meshed geometry
0 -
I think the typical approach for something like this would be to run the script at the workbench level. You can record the user interface actions for replacing the geometry and refreshing the model, then simply send your basic, mechanical API commands to mesh it, and export the mesh file.
0 -
There is probably a way to do this in mechanical by setting the main geometry as a simple box, and adding/deleting additional geometry sources. Suppress the dummy box of the main, geometry import, leaving only the real geometry.
I don’t think there is an API to change the main geometry source, but there likely is for the additional geometry source objects.0 -
@ramsaran I agree with @Mike.Thompson that the most natural route would be at the project page level. Yet you can achieve what you want as follows:
# Start with first geometry ExtAPI.Application.ImportGeometry(r'D:\Support\forum\geo_import_mesh\geo1.scdocx') num_geom=2 # now mesh, export and replace geometry with the next one for i in range(num_geom): mesh_15 = Model.Mesh # meshing mesh_15.GenerateMesh() ExtAPI.DataModel.Project.Model.Mesh.InternalObject.WriteFluentInputFile(r'D:\Support\forum\geo_import_mesh\test{0}.msh'.format(i+1)) geometry_import = DataModel.GetObjectsByName('Geometry Import')[0] if i+1<num_geom: geometry_import.Import(r"D:\Support\forum\geo_import_mesh\geo{0}.scdocx".format(i+2)) # Primary Source!
The last 'Import' call is equivalent to "Replace With" in the UI.
For the above to work, simply create a Mechanical Model system in your project page, double click on 'Model' so as to start an empty Mechanical session without a geometry at the beginning. Then run the script from within Mechanical.
1