Script to export a list of objects


That is weird, I don’t have 2023 to test it so, sorry!


Could you try this script?

import c4d, os
import c4d.documents as docs
from c4d import gui
# Welcome to the world of Python

# Main function
def main():

    # the doc
    doc = docs.GetActiveDocument()
    docPath = doc.GetDocumentPath()
    docName = doc.GetDocumentName()
    # list-stuff
    objList = doc.GetSelection()
    tmpList= []
    itemCounter = 0

    # check if anything is selected
    if not objList:
        gui.MessageDialog('Nothing selected -> nothing saved')
        # create folder, if not present
        setupFolder = docPath + "\\" + docName[0:len(docName)-4] + "_objExport" + "\\"
        if not os.path.exists(setupFolder):
        # check each obj in selection and save in file after type-check
        for obj in objList:
            # check type
            if not isinstance(obj, c4d.BaseObject):
                print ("Expected c4d.BaseObject, got %s." % obj.__class__.__name__ + " attached to: "\
                      + obj.GetObject().GetName())
                # some list-stuff
                # create temp doc and insert selected obj into it
                theTempDoc = docs.IsolateObjects(doc, tmpList)
                # save temp doc in folder using the original project-filename & objectname
                path = str(setupFolder + obj.GetName() + ".stl")
                docs.SaveDocument(theTempDoc, path, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, format=c4d.FORMAT_STL_EXPORT)
                # some list-stuff
                # kill temp doc
                itemCounter += 1

        gui.MessageDialog(str(itemCounter) + '  selected items saved to: ' + setupFolder)

# Execute main()
if __name__=='__main__':


OK. Many thanks for help on this… its been bugging me for years.

So it didn’t work but the output path looked odd so I changed:

setupFolder = docPath + “\” + docName[0:len(docName)-4] + “_objExport” + “\”
setupFolder = docPath + “/” + docName[0:len(docName)-4] + “_objExport” + “/”

And that worked! ( is that Mac vs PC File naming thing?)

The other plugin I mentioned “Select’n’go” has not parsed the Volume objects since r22…Which made me think the Dev documentation says:

FORMAT_STL_EXPORT - New in version S22: STL export.

So I guess they have not updated that bit their code? I’ll try and make contact with them again.

Many thanks again.


If you are working with file system paths, it is recommendable that you don’t use hardcoded strings at all. If you import os, the separator can be found as os.sep, or you use os.path.join() to connect directories.