[Macro] Batch export to mesh (STL and OBJ)

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
pablogil
Posts: 881
Joined: Wed Nov 26, 2014 3:19 pm
Location: Badajoz (Spain)
Contact:

[Macro] Batch export to mesh (STL and OBJ)

Post by pablogil »

Hi,

I have opened this new thread to make it clear to general users the creation of this macro.
I has been developed to fit a user need but it has been quickly extended to other user needs.

The macro features:
  • FreeCAD "standard" meshing option
  • custom names
  • Converts/exports one or several objects at once (batch export)
  • Convert objects into the active FreeCAD project or
  • Export objects to .STL or .OBJ files
  • Absolute or relative paths allowed
export2.png
export2.png (231.94 KiB) Viewed 2328 times
I hope you find it useful.
Cheers

PS - anyone knows a place with the steps to "upload" macros to the official "Addon/macros repository"? thanks
Dark and Light stylesheets v2.0 to theme your FreeCAD UI, more information here
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Batch export to mesh (STL and OBJ)

Post by openBrain »

For the process of publishing the macro, this could be good to first attach it to the OP so it can be tested & reviewed.
Then you can read Macro documentation. AFAIK, as soon as a wiki page is created, the macro is available through the addon manager.
For further integration, you can make a PR to the FreeCAD macros GH repo (read the README first so your metadata and commit/PR messages are correct). ;)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Batch export to mesh (STL and OBJ)

Post by openBrain »

I think I managed to find the macro through the links your provided (but it would be simpler to get it here). :)
Some remarks :

* The way you use the QT class inheritance can IMO be improved. Rather than using a base QDockWidget and having a custom UI push inside it, it would be simpler to create your own class at widget level (eg. class ALGDockWidget) that will directly inherit QDockWidget class. So you can setup a custom UI, but also custom title, ... in this single class. You can have a look how I did it in this macro
* At the same link, you can be interested in using the QtCore.Qt.WA_DeleteOnClose attribute. That makes the widget to be automatically deleted when closed so memory is freed.
* On L54, I'm not sure I like that your macro clears the Report view while maybe I don't want it ;)
* On L78-88, better do PrintXXX(str(msg) + "\n"). The way it is now, messages will never appear in the status bar because immediately overwritten by a blank line with CRLF.
* On L61-63, following code seems totally useless to me :)

Code: Select all

    doc=FreeCAD.ActiveDocument
    if doc is not None:
        FreeCAD.setActiveDocument(doc.Name)
* On L69-75, the helper functions seems a bit harmful as they apply on a hard coded object. At least set object as argument. If you go for my first remark, you can (even better) integrate these functions in the class.
* On L389, your Alg_checkInstance function seems to be dead code as never called.
* On Alg_singleInstance function, you can directly use findChildren(QtGui.QDockWidget, 'exportSTL') so you get a list of only instances of your widget and delete it.
* More comment in the code may be appreciated. :P

Voila. :) This is a first quick review of the structure. If I have some more time and you're interested, I'll have a deeper look into it later. ;)
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: [Macro] Batch export to mesh (STL and OBJ)

Post by openBrain »

Some more remarks :
* On the export/save function, you don't really need to manage the selection length this way. Better use the pythonic for part in selection: so you don't care there is no, one or several selected objects ;)
* On the save function, it looks to me suboptimal to create an object => Generate the mesh of the object => Save the mesh => Delete the object. You can just generate the mesh with MeshPart.meshFromShape and save it to a file. No need to create an object that you will just delete after. ;)

To be continued...
PaulRdy
Posts: 1
Joined: Mon Oct 11, 2021 4:26 pm

Re: [Macro] Batch export to mesh (STL and OBJ)

Post by PaulRdy »

Hi! Bit of a late reply but I can't find the version of the macro which supports .obj export. Do you mind sharing it again?
Post Reply