Ejemplo n.º 1
0
    def run(self):
        doc = documents.GetActiveDocument()
        doc.StartUndo()

        sel = doc.GetSelection()
        if sel is None:
            return False

        c4d.StatusSetSpin()
        timestart = c4d.GeGetMilliSeconds()

        c4d.StopAllThreads()

        # loop through all objects
        for op in sel:
            print op.GetName()
            # and do something with op #
            op.Message(c4d.MSG_UPDATE)

        c4d.StatusClear()

        # tell C4D to update internal state
        c4d.EventAdd()
        doc.EndUndo()

        timeend = int(c4d.GeGetMilliSeconds() - timestart)
        timemsg = u"MakeAwesomeButton: finished in " + str(
            timeend) + " milliseconds"
        print(timemsg)

        return True
Ejemplo n.º 2
0
def Copy(tmppath, converted):
    sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
    if not sel:
        gui.MessageDialog('Select some Objects first.')
        return

    c4d.StopAllThreads()
    c4d.StatusSetSpin()

    export = []
    for obj in sel:
        #Convert Current State to Object for all selected Objects
        if converted:
            obj = Command_CSTO(obj)
        export.append(obj)

    if export == []:
        message = 'Sorry, nothing to Export.'
        gui.MessageDialog(message)
        return

    iso_objs=c4d.documents.IsolateObjects(doc, export)
    c4d.documents.SaveDocument(iso_objs, tmppath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_C4DEXPORT)

    c4d.StatusClear()

    message = 'Copied Object(s).'
    if converted:
        message = 'Copied converted Object(s).'

    gui.MessageDialog(message)
def main():
    c4d.StopAllThreads()
    doc = c4d.documents.GetActiveDocument()
    fps = doc.GetFps()
    fromTime = doc.GetMinTime().GetFrame(fps)
    toTime = doc.GetMaxTime().GetFrame(fps)
    animLength = toTime - fromTime + 1
    filePath = c4d.storage.SaveDialog()
    filePath, objName = os.path.split(filePath)
    objName = objName + "_"
    filePath = filePath + "\\"

    for f in range(0, animLength):
        doc.SetTime(c4d.BaseTime(fromTime, fps) + c4d.BaseTime(f, fps))
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)

        c4d.StatusSetText("Exporting " + str(f) + " of " + str(animLength))
        c4d.StatusSetBar(100.0 * f / animLength)

        c4d.CallCommand(16768, 16768)
        c4d.CallCommand(100004794, 100004794)
        c4d.CallCommand(100004787)

        fileName = filePath + objName + str(f) + ".obj"
        savingresult = c4d.documents.SaveDocument(doc, fileName,
                                                  c4d.SAVEDOCUMENTFLAGS_0,
                                                  c4d.FORMAT_OBJ2EXPORT)

        c4d.CallCommand(12105, 12105)
        c4d.CallCommand(12105, 12105)
        c4d.CallCommand(12105, 12105)

    c4d.StatusClear()
    gui.MessageDialog('Exporting to' + filePath + ' done')
Ejemplo n.º 4
0
def Paste(tmppath):
    c4d.StopAllThreads()
    c4d.StatusSetSpin()

    merge = c4d.documents.MergeDocument(doc, tmppath, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS | c4d.SCENEFILTER_MERGESCENE, None)

    c4d.StatusClear()
    if not merge:
        message = "Couldn't find Objects to paste...\nMake sure to export first."
        gui.MessageDialog(message)
        return

    c4d.EventAdd()
Ejemplo n.º 5
0
def main():
    #stop all threads and clear console
    c4d.StopAllThreads()
    c4d.CallCommand(13957)

    #fileselector and execute main function
    myFile = c4d.storage.LoadDialog(
        title="Open MagicaVoxel .VOX Voxel File...")
    importVox(myFile)

    #fileselector and execute main function
    myFile = c4d.storage.LoadDialog(
        title="Open MagicaVoxel .PNG Palette File...")
    importPalette(myFile)

    #update scene
    c4d.EventAdd()
Ejemplo n.º 6
0
 def Command(self,id,msg): #listen for user clicks
     c4d.StopAllThreads()
     doc.StartUndo()
     checkbox = self.GetBool(103)
     if id==1004:
         print('video')
         CanvasVideo(checkbox)
         self.Close()
     elif id ==1003:
         print('image')
         CanvasImage(checkbox)
         self.Close()
     elif id ==1005:
         print('image sequence')
         CanvasSequence(checkbox)
         self.Close()
     doc.EndUndo()
     return True
Ejemplo n.º 7
0
def main():
    c4d.StopAllThreads()
    doc = c4d.documents.GetActiveDocument()
    fps = doc.GetFps()
    fromTime = doc.GetMinTime().GetFrame(fps)
    toTime = doc.GetMaxTime().GetFrame(fps)
    animLength = toTime - fromTime + 1
    filePath = c4d.storage.SaveDialog()
    filePath, objName = os.path.split(filePath)
    objName = objName + "_"
    filePath = filePath + "\\"


    for f in range(0,animLength):
        
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)
        c4d.StatusSetText("Exporting " + str(f) + " of " + str(animLength))
        c4d.StatusSetBar(100.0*f/animLength)
         
        objs = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
 
        # Get a fresh, temporary document with only the selected objects
        docTemp = c4d.documents.IsolateObjects(doc, objs)
        docTemp.SetTime(c4d.BaseTime(fromTime,fps) + c4d.BaseTime(f,fps))
        if docTemp == None:
            return
    
        # Set project scale
        unitScale = c4d.UnitScaleData()
        unitScale.SetUnitScale(1.0, c4d.DOCUMENT_UNIT_M)
    
        bc = c4d.BaseContainer()
        bc[c4d.DOCUMENT_DOCUNIT] = unitScale
        docTemp.SetDocumentData(c4d. DOCUMENTSETTINGS_DOCUMENT, bc)
        

        fileName = filePath+objName+str(f)+".obj"
        savingresult = c4d.documents.SaveDocument(docTemp,fileName,c4d.SAVEDOCUMENTFLAGS_0,c4d.FORMAT_OBJ2EXPORT)
        c4d.documents.KillDocument(docTemp)

    c4d.StatusClear()
    gui.MessageDialog( 'Exporting to'+filePath+' done' )
Ejemplo n.º 8
0
    def doSetup(self, **overridePlayblastParams):
        doc = c4d.documents.GetActiveDocument()

        if overridePlayblastParams.get('multilayer'):
            destination = "../images/$prj/$take/Main/$take_$prj_Main_"
            multilayer = 1
        else:
            destination = "../images/$prj/$take/$take_$prj"
            multilayer = 0

        rdata = doc.GetFirstRenderData()
        listOfRs = []
        while rdata:
            rdata = rdata.GetNext()
            if rdata:
                listOfRs.append(rdata.GetName())

        if 'Octane' in overridePlayblastParams.get('engine'):
            if 'shotgun_render' not in listOfRs:
                rd = c4d.documents.RenderData()
                rd_bc = rd.GetDataInstance()

                rd_bc[c4d.RDATA_RENDERENGINE] = 1029525

                octane_vp = c4d.BaseList2D(1029525)

                rd.InsertVideoPost(octane_vp)

                c4d.StopAllThreads()
                doc.InsertRenderDataLast(rd)
                rd.SetName('shotgun_render')
                rd[c4d.RDATA_SAVEIMAGE] = 0
                doc.SetActiveRenderData(rd)

                OctaneRenderer = rd.GetFirstVideoPost()
                OctaneRenderer[c4d.SET_PASSES_ENABLED] = 1
                OctaneRenderer[c4d.SET_PASSES_SAVE_MAINPASS] = 1
                OctaneRenderer[c4d.SET_PASSES_SAVEPATH] = destination
                OctaneRenderer[c4d.SET_PASSES_MULTILAYER] = multilayer
                OctaneRenderer[c4d.SET_PASSES_MAKEFOLDER] = 1
                OctaneRenderer[c4d.SET_PASSES_EXR_COMPR] = 3

                c4d.EventAdd()
Ejemplo n.º 9
0
def main():
    global path, jobname, ff, ft, fstr, rstr, server_ip, server_group, server_count, server_c4dloc, cmdjob
    path = doc.GetDocumentPath() + '/' + doc.GetDocumentName()
    if doc.GetDocumentPath() == '':
        dlg = errordialog()
        dlg.Open(c4d.DLG_TYPE_MODAL)
        return True

    if os.path.exists(
            os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + os.sep +
            'c4dbb.json'):
        f = open(
            os.getenv("HOMEDRIVE") + os.getenv("HOMEPATH") + os.sep +
            'c4dbb.json', 'r')
        s = json.load(f)
        f.close()

        fstr = s["fstr"]
        rstr = s["rstr"]
        server_ip = s["server_ip"]
        server_group = s["server_group"]
        server_count = s["server_count"]
        server_c4dloc = s["server_c4dloc"]
        cmdjob = s["cmdjob"]

    path = path.replace("/", os.sep).replace("\\", os.sep)

    jobname = doc.GetDocumentName().replace(".c4d", "")
    rd = doc.GetActiveRenderData()
    fps = doc.GetFps()
    ff = (rd[c4d.RDATA_FRAMEFROM]).GetFrame(fps)
    ft = (rd[c4d.RDATA_FRAMETO]).GetFrame(fps)

    dlg = settings()
    dlg.Open(c4d.DLG_TYPE_MODAL)
    if dlg.res:
        c4d.StopAllThreads()
        Execute()
Ejemplo n.º 10
0
    def AskClose(self):
        global exchangeData, workerThread
        #self.renderer.End()
        c4d.StopAllThreads()

        return False  #not c4d.gui.QuestionDialog(c4d.plugins.GeLoadString(ids.STR_TITLE))
Ejemplo n.º 11
0
    def Execute(self, filepath, exportanim, exportnulls, removexrefs,
                removetextags):
        self.doc = documents.GetActiveDocument()
        assert self.doc is not None

        c4d.StopAllThreads()

        # Get the COLLADA export plugin
        colladaPlugin = plugins.FindPlugin(colladaPluginId,
                                           c4d.PLUGINTYPE_SCENESAVER)
        assert colladaPlugin is not None

        # Perform requested geometry merges, can only be done on current document,
        # so this will be undone at the end.
        mergeObjects = self.GetMergeGeometryObjs(self.doc.GetFirstObject(), [])
        self.MergeGeometry(mergeObjects)

        # Clone the current document so the modifications aren't applied to the original scene
        self.docCopy = self.doc.GetClone(c4d.COPYFLAGS_DOCUMENT)
        assert self.docCopy is not None

        # Remove xrefs
        if removexrefs is True:
            self.RemoveXRefs(self.docCopy.GetFirstObject())

        # Remove objects that are on non-exporting layers
        removeObjects = self.RemoveNonExporting(self.docCopy.GetFirstObject(),
                                                [])
        for op in removeObjects:
            op.Remove()

        # Add object export settings as metadata appended to object names
        self.ExportDataToNameMeta(self.docCopy.GetFirstObject())

        # Add object GUIDs to object names, to force a unique name
        self.ExportGUIDToName(self.docCopy.GetFirstObject())

        # Collect warnings for names that are too long
        self.WarnIfLongName(self.docCopy.GetFirstObject())

        # Add empty polygon objects to childless null objects so that they are exported by the
        # COLLADA exporter
        if exportnulls is True:
            self.FixUpEmptyNulls(self.docCopy.GetFirstObject())

        # Remove teture tags
        if removetextags is True:
            self.RemoveTextureTags(self.docCopy.GetFirstObject())

        # Container for plugin object data
        op = {}

        # Configure COLLADA export plugin and export the modified scene
        assert colladaPlugin.Message(c4d.MSG_RETRIEVEPRIVATEDATA, op)
        assert 'imexporter' in op

        # Get the exporter settings from the plugin object
        colladaExport = op['imexporter']
        assert colladaExport is not None

        # Define the settings
        colladaExport[c4d.COLLADA_EXPORT_ANIMATION] = exportanim
        colladaExport[c4d.COLLADA_EXPORT_TRIANGLES] = True

        # Export without the dialog
        if c4d.documents.SaveDocument(
                self.docCopy, filepath,
                c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, colladaPluginId):

            # Parse the saved COLLADA data as XML
            colladaData = ET.parse(filepath)
            parentMap = dict(
                (c, p) for p in colladaData.getiterator() for c in p)

            # Construct geometry id map
            geomIdMap = dict()
            for node in colladaData.getiterator():
                if node.tag == ns + 'geometry':
                    geomIdMap[node.get('id')] = node

            # Get first effect and material nodes to prevent them from being deleted
            firstEffectNode = colladaData.find('.//' + ns + 'effect')
            firstMaterialNode = colladaData.find('.//' + ns + 'material')
            firstMaterialId = firstMaterialNode.get('id')

            # Iterate thru the hierarchy and deal with things
            for node in colladaData.getiterator():

                # Remove Polygon objects and associated geometry data
                if node.tag == ns + 'node':
                    if node.get('name') == polygonName:
                        geomId = node.find(ns +
                                           'instance_geometry').get('url')[1:]
                        geomNode = geomIdMap[geomId]
                        parentMap[geomNode].remove(geomNode)
                        parentMap[node].remove(node)

                # Remove library_images tags
                if node.tag == ns + 'library_images':
                    parentMap[node].remove(node)

                # Remove effect tags except for the first one
                if node.tag == ns + 'effect':
                    if node != firstEffectNode:
                        parentMap[node].remove(node)

                # Remove material tags except for the first one
                if node.tag == ns + 'material':
                    if node != firstMaterialNode:
                        parentMap[node].remove(node)

                # Set material target to the first material id
                if node.tag == ns + 'instance_material':
                    node.set('target', '#' + firstMaterialId)

            # Remove the namespace from all tags
            xmlString = ET.tostring(colladaData.getroot())
            xmlString = xmlString.replace(nsPrefix + ':', '')
            xmlString = xmlString.replace(':' + nsPrefix, '')

            # Write the modified COLLADA file
            colladaFile = open(filepath, 'w')
            colladaFile.write(xmlString)
            colladaFile.close()

            # Cleanup
            if len(mergeObjects) is not 0:

                for op in mergeObjects:
                    for x in range(0, 3):
                        self.doc.DoUndo(False)

                self.doc.DoUndo(False)
                self.doc.DoUndo(False)

            return 'Export complete\n\nRemoved %d xrefs\nFixed %d empty null objects' % (
                self.xrefCounter, self.polyCounter)
        else:
            return 'The document failed to save.'