Tag Archives: python

Combining 3D Printing and AI

As my faithful followers will know, I’ve been reconditioning some used 3d printers.  This week I’ve been working on an old Ultimaker 2+.  To get it to print something I had to load a file to a SD card, as this printer does not have the native ability to connect to the computer or network.  I did not have an SD card reader on my Mac at first, so I printed some files that were already on the card – and after some poking and prodding that did eventually work, but the files were uninteresting.  Around this time, my coworker, Victoria Pilato let me borrow her SD card reader, so I happily went looking for something to print from Thingiverse – found a cute little fancy statue and set to printing.

Then I stopped the print job…

Even though the files on the card had been boring, they were at least printing ok.  This time it was trying to print from a few mm above the print bed.  I readjusted the bed calibration (which seemed fine, as I had already done it earlier), and still had the problem.

Next morning. I’m feeling ready to tackle this.  I ask ChatGPT.  It suggests my bed could be off or POSSIBLY some weird thing could be in the G Code telling it to start the first row higher on the z axis.  I poke around in Ultimaker Cura, trying to find the issue, but I don’t see the problem.

  • AI Fixes the G CODE

It occurs to me the maybe ChatGPT can just read the G Code.  I dump it on the AI and turns out that it can.  It tells me mostly everything looks alright… BUT it says that it is configured for the Ultimaker 2+ Connect, which has auto leveling, where my model does not and that I should fix that in Cura.  Now in Cura, I can clearly see that I have it configured for the correct printer, not the Connect.  So, I ask GPT to fix the code directly, instead of me doing it in Cura.  And it does.

 

  • AI Suggests a New 3d Model

I have already skipped the fancy little model, and been working on a simple Benchy today.   After it provides me with the new code… and that code is happily chugging away on the printer, I ask GPT if it can alter the code to actually change the shape of the model.  It says it can not, tells me what programs to use… and yet, still offers to make a prototype.  I say sure. It says it will give me code, but instead gives me an image.  Again tells me it get generate an .stl file, but instead makes a placeholder, with another image.

Oh by the way, I’ve told it to merge the Benchy with an UFO – because, why not?

UFO infused benchy as created by GPT. It has saucer element both around the base of the boat and above almost like an umbrella.

This is an AI rendered image, not a picture of a printed model.

  • AI Converts a 2d Image into a 3d Render 

So at this point, I’m pretty happy with the cute Benchy from Outer Space, so I decide to download that image and bring it into Meshy.  Meshy is a browser based AI 3d model generator, that can either make a model from a text prompt or from an image.  I’ve previously made a little seawolf with it before, starting from an image.

original wolfie picture

image

3d creation by Meshy

meshy model from image

printed meshy model with no clean up attempted

printed meshy model

The one thing I wasn’t thrilled about the first time I printed Wolfie straight from Meshy, was that I thought it lost some of the detail and looked a bit blobby.

From inside Meshy, I loaded the picture I wanted it to generate a 3d model from.  Similar to when you ask any AI to make a model, it gives me 4 choices.  You can see that they are doing the usual AI thing, and not really, really, trying to just make what you gave it, but providing you with some creative adaptations.

AI created versions of UFO/Benchy

Some of the choices are already less blobby than others, but I really wanted the one that looked the most like what GPT had made, so I went with the one in the top left – which already looks lumpy.

UFO infused benchy as created by GPT. It has saucer element both around the base of the boat and above almost like an umbrella.

  • AI Makes Recommendations to Refine Meshy Model

Me: “I have brought in a model into Blendr from meshy. The model looks kind of globby. Is there an easy way to clean it up so it looks more defined?”

GPT:

Top Reasons for “Globby” Models from Meshy and How to Fix Them

🟠 1. Surface is Too Smooth (Normals or Shading)

  • Meshy sometimes auto-applies smooth shading, which can make details look melted or blobby.

✅ Fix in Blender:

  1. Select the model in Object Mode.

  2. Go to the left toolbar or press Right-clickShade Flat.

    • Instantly sharpens up the look by reverting from smooth shading.


🟠 2. Mesh is Over-Triangulated or Dense

  • Meshy-generated models often have millions of triangles, making them look blobby or noisy.

✅ Fix:

  • In Edit Mode, run:

    • F3 → search Decimate Geometry (non-destructive, try ratios like 0.2–0.6)

    • Or use Remesh Modifier (Voxel mode, low voxel size like 0.050.1)


🟠 3. Normals Are Messed Up

  • If the surface has weird lighting or jagged shading, the normals may be flipped.

✅ Fix:

  1. Go into Edit Mode (Tab)

  2. Press A to select all

  3. Press Shift + N to Recalculate Normals


🟠 4. Model Scale Is Off

  • Sometimes imported models are tiny or huge and look off.

✅ Fix:

  • Press N for the sidebar → check scale

  • Reset with Ctrl + AApply Scale


🧠 Tip: For 3D Printing

  • Use Mesh → Clean Up in Edit Mode to:

    • Delete loose geometry

    • Fill holes

    • Merge by distance

    • Remove doubles


If you want, you can send me a screenshot or description of what it looks like, and I’ll give you a specific cleanup sequence.

Or — I can write you a custom macro that does it all in one go!

Me: Macro???  Yes please!

Here is the gold — lol  (I didn’t know you could throw a python script into Blendr.  Even if you did, maybe you hadn’t thought to have AI make it for you)

—————————————————————–

import bpy
import bmesh

# Get active object and ensure it’s a mesh
obj = bpy.context.active_object
if obj and obj.type == ‘MESH’:

# Ensure we’re in Object Mode
bpy.ops.object.mode_set(mode=’OBJECT’)

# Shade Flat
bpy.ops.object.shade_flat()

# Add Subdivision Surface Modifier (non-destructive)
subdiv = obj.modifiers.new(name=”Subdivision”, type=’SUBSURF’)
subdiv.levels = 2
subdiv.render_levels = 2

# Enable Auto Smooth to preserve sharp edges
obj.data.use_auto_smooth = True
obj.data.auto_smooth_angle = 1.0472 # 60 degrees in radians

# Go into Edit Mode for cleanup
bpy.ops.object.mode_set(mode=’EDIT’)
bm = bmesh.from_edit_mesh(obj.data)

# Merge by distance to remove doubles
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)

# Recalculate normals
bmesh.ops.recalc_face_normals(bm, faces=bm.faces)

bmesh.update_edit_mesh(obj.data)
bpy.ops.object.mode_set(mode=’OBJECT’)

print(“✨ Cleaned, smoothed, and preserved edges!”)

else:
print(“⚠️ Error: Please select a mesh object in Object Mode.”)

—————————————————————–

Here is what it looks like after applying the script:

It isn’t perfect… but it is a whole lot better.  BTW – Blendr is free, Meshy has a paid version that very well make my models look better, but I am using the limited free version, the original Benchy model is free from Thiniverse as are many other items (though tips are encouraged (remember beerware??)). I pay for ChatGPT – but I suspect this could have been achieved from the free version as well.

After this, I brought it over to Formware to do some last minute manifold repairs on the stl file.

“You can use this free online tool without hassle to fix your stl files quickly. Files are deleted after download or otherwise after 6 hours to keep our systems clean. The fixer accepts binary and ascii .stl files.”

And here is the print after the supports are removed:

UFO/Benchy printed out