New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

I've just put together a rudimentary script that will allow you to add variables/properties to an object in FreeCAD, (such as infill density) which will export these objects to a .3mf file, and when loaded into Cura, they will be applied immediately to the imported object!

With this script, you can import multiple different objects, each one having its own settings (most notably and sought after infill density!) So you no longer have to constantly tweak the settings in your slicer every time you want to print or reprint an item created in FreeCAD!

Here's the link to my script. Check it out and see what you think?
https://github.com/Malendryn/Enhanced-F ... f-Exporter

Major update released! This script now supports the Part object, and keeps children as seperate meshes with their own properties, instead of one big mesh! see https://github.com/Malendryn/Enhanced-F ... /README.md for more details!

Another major update: Script now honors placement and rotation of Part objects, including multiple parents.
Last edited by Malendryn on Mon Apr 10, 2023 10:17 am, edited 2 times in total.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by mario52 »

Hi

thanks for your contribution

you can create one icon

i have an error in import ptvsd and i see
README.md


11:15:49 Traceback (most recent call last):
File "C:/Users/User/AppData/Roaming/FreeCAD/Macro/Enhanced-FreeCAD-3mf-Exporter.FCMacro", line 17, in <module>
remote(); # enable debugger, start listening on port 5678
File "C:/Users/User/AppData/Roaming/FreeCAD/Macro/Enhanced-FreeCAD-3mf-Exporter.FCMacro", line 9, in remote
import ptvsd
File "C:\FreeCAD_weekly-builds-32532-2023-03-26-conda-Windows-x86_64-py310\bin\Lib\site-packages\shiboken2\files.dir\shibokensupport\feature.py", line 139, in _import
return original_import(name, *args, **kwargs)
<class 'ModuleNotFoundError'>: No module named 'ptvsd'

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.32532 (Git)
Build type: Release
Branch: master
Hash: 20e44eba50e1365b9e7bb9c5c244afe96a627a28
Python 3.10.10, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: French/Mars (fr_MA)

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.
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

Ahh I thought there was a new one, it's been a long time since I delved into writing python for apps like FreeCAD and Blender!

For all practical purposes you can just comment out all the debug stuff, it's not needed for a release product! I'll have to look into both factoring that out of the released .py, AND switching away from ptvsd, Thanks for the heads up!
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

Just made a change to the .py file to test for the existence of a file '3mfExporter_debug_enabled' in the same directory as this script, and if not present it will bypass ptvsd altogether. (for now) ... it's a quick hack, but it should prevent further errors until I switch over to debugpy!
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

I just created a video explaining how this script can be used, and uploaded it to youtube. Here's a link to it:



https://youtu.be/YgbacugzE6c



Hopefully this will make more sense as it's just not easy to describe what it does and how to use it in a few short paragraphs :)

Bear with me, this is the first time I've EVER put a project up on github, and ALSO the very first time I've ever created an instruction video, and ALSO the very first time I've ever made anything available on Youtube! (A lot of firsts for me today! :)

But I think (I hope!) the video will clear up a lot of questions and give you some other insights on how it can be used!



(BTW just for the curious: I used OBS Studio to make the video, and Blender to edit it!)
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

One more update, I just went through ALL of Cura's settings and extracted all the variable names which Cura (5.2.1) will recognize and can be set in objects in FreeCAD.

Here's the link to that file:
https://github.com/Malendryn/Enhanced-F ... perties.md
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by mario52 »

Hi

the file 3mf is not opened without error ! in FreeCAD

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.32532 (Git)
Build type: Release
Branch: master
Hash: 20e44eba50e1365b9e7bb9c5c244afe96a627a28
Python 3.10.10, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
 
the .zip contain 3 files
Fusion_CubeCylinder.FCStd
with_FreeCAD_Fusion_CubeCylinder.3mf
with_Enhanced-FreeCAD-3mf-Exporter_Fusion_CubeCylinder.3mf


Fusion_CubeCylinder_To_3mf.zip
(18.14 KiB) Downloaded 9 times

you can also add the header as describe here Add header information before your actual code.

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.
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

I don't see any problem with these files. the .FCStd file loaded up just fine for me in FreeCAD, and both .3mf files also loaded up just fine in Cura. (If you're importing the .3mf file back into FreeCAD, that's not what my script was made to do!, and you'd be using a 3rd party addon for that purpose anyway as FreeCAD doesn't inherently support importing .3mf files. At least not as of version 0.20.2)

So if you're seeing an error somewhere, could you please be more descriptive of how to reproduce it?

I'll have a look at the header link you dropped too, thanks!
Malendryn
Posts: 14
Joined: Wed Apr 06, 2016 6:44 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by Malendryn »

If by chance you had been trying to import this into Prusa, then it would have failed. I discovered a bug in the export that wasn't a problem for Cura, but caused Prusa to reject the file. That's been fixed now and pushed up to github.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: New Script! Export values for 3d slicers (like infill density) FROM FreeCad Objects!

Post by mario52 »

Hi
Malendryn wrote: Mon Apr 03, 2023 6:59 am could you please be more descriptive of how to reproduce it?
just create the object (my .FCstd file) select the object run the macro and open or import the .3mf file created

work fine ver: 0.0.4

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.32532 (Git)
Build type: Release
Branch: master
Hash: 20e44eba50e1365b9e7bb9c5c244afe96a627a28
Python 3.10.10, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
 
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