Macro: Cost to 3D Print

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
LedbetterAlex
Posts: 2
Joined: Sat Jul 17, 2021 3:55 am

Macro: Cost to 3D Print

Post by LedbetterAlex »

Hi All,

Just bought a 3D Resin Printer and so wanted to get a macro to find the volume so I could calculate the cost to print the part and ended up with this. Simple, but maybe it sparks the idea for someone.

Note! The code assumes you are running FreeCAD in Metric mm/kg/s units. If you'd like to be, go to Edit>Preferences>General>Units and under Unit System: select Standard (mm/kg/s/degree) and we'll have one less Imperial minion. Cheers!

Macro:

Code: Select all

print(" ")
print("----- Physical Properties of Selected Object for 3D Resin Printing -----")
target_object = App.ActiveDocument.ActiveObject
model_volume = target_object.Shape.Volume/(10**3)
print("Model Volume: " + str(round(model_volume, 3)) + " cm^3")
dollars_per_gram_eSun3D_Hard_Tough = 40/1000 # $ / g
density_eSun3D_Hard_Tough = 1.15 # g / cm^3
print("3D Printer Resin Density (eSun3D Hard Tough): " + str(round(density_eSun3D_Hard_Tough, 3)) + " g/cm^3")
model_mass = density_eSun3D_Hard_Tough*model_volume
print("Model Mass: " +str(round(model_mass, 3)) + " g")
print("Dollars per Gram (eSun3D Hard Tough): $" + str(round(dollars_per_gram_eSun3D_Hard_Tough, 2)))
total_cost = model_mass*dollars_per_gram_eSun3D_Hard_Tough
print("Cost to Print (eSun3D Hard Tough): $" + str(round(total_cost, 2)))
Physical_Properties_Example.png
Physical_Properties_Example.png (339.62 KiB) Viewed 2117 times
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: Macro: Cost to 3D Print

Post by chrisb »

Hi and welcome to the forum!

Thanks for starting with a contribution. You may consider to include the price information e.g. inMacro FCInfo?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
LedbetterAlex
Posts: 2
Joined: Sat Jul 17, 2021 3:55 am

Re: Macro: Cost to 3D Print

Post by LedbetterAlex »

:) Thank you Chris - I did look into the FCInfo Macro. If there is interest, I can integrate. I would add several different printing materials to select from. However, I realize now that without the sometimes necessary support structures which count as waste material, the result will not always be accurate, but depending on the part, it can give an idea.

Thanks again for the warm welcome, see you around,

Alex
chrisb
Veteran
Posts: 53785
Joined: Tue Mar 17, 2015 9:14 am

Re: Macro: Cost to 3D Print

Post by chrisb »

LedbetterAlex wrote: Sun Aug 01, 2021 6:40 am If there is interest, I can integrate.
Mario may answer this.
mario52 wrote: pinged by pinger macro
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
User avatar
onekk
Veteran
Posts: 6098
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Macro: Cost to 3D Print

Post by onekk »

LedbetterAlex wrote: Sun Aug 01, 2021 6:40 am :) Thank you Chris - I did look into the FCInfo Macro. If there is interest, I can integrate. I would add several different printing materials to select from. However, I realize now that without the sometimes necessary support structures which count as waste material, the result will not always be accurate, but depending on the part, it can give an idea.

Thanks again for the warm welcome, see you around,

Alex
It would be a however a good idea to have it in the "design phase", in printing phase, more accurate information could be obtained from the slicer ot even for the printer itself.

But when designing a part, it could be interesting and useful to know how the "design choices" will affect the "use of material" of the final part, and having also an idea of the cost of material could be a good help to not "waste money" and "scarce resources".

Good work.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
mario52
Veteran
Posts: 4672
Joined: Wed May 16, 2012 2:13 pm

Re: Macro: Cost to 3D Print

Post by mario52 »

hi
chrisb wrote: Sun Aug 01, 2021 9:55 am Mario may answer this.
yes i will add the cost (after adapt the macro for the Body and the GlobalPlacement)

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
mario52
Veteran
Posts: 4672
Joined: Wed May 16, 2012 2:13 pm

Re: Macro: Cost to 3D Print

Post by mario52 »

Hi
chrisb wrote: Sun Aug 01, 2021 9:55 am
LedbetterAlex wrote: Sun Aug 01, 2021 6:40 am If there is interest, I can integrate.
Mario may answer this.
done

enter the new material in this format:

newNameMaterial,Density,Price (by kg),Info

for change (modify) data, change it in the LineEdit

if you change the name one new material is saved

for new material, delete the line and create new line in the format above

the file is saved when you leave the macro

10/12/2021 ver "01.25 rmu" PySide2 and add comboBox materials

MaterialCost00.png
MaterialCost00.png (17.03 KiB) Viewed 1412 times
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply