Exemplo n.º 1
0
    def buttonsChangeState(self, btnState):
        """
        Changes the Images when Given a Boolean
        Used to Allow the User to know when the command is still loading
        """
        c4d.StatusClear()
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        c4d.DrawViews(
            c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW
            | c4d.DRAWFLAGS_NO_THREAD
            | c4d.DRAWFLAGS_STATICBREAK
        )
        c4d.DrawViews(c4d.EVMSG_CHANGEDSCRIPTMODE)
        c4d.EventAdd(c4d.EVENT_ANIMATE)
        c4d.StatusClear()
        if btnState == False:
            self.main_logo.SetImage(self.img_loading, False)
            self.auto_import_fig_but.SetImage(self.img_btnAutoImportOff_FIG, True)
            self.auto_import_prop_but.SetImage(self.img_btnAutoImportOff_PROP, True)
            self.convert_mat_but.SetImage(self.img_btnConvertMaterialsOff, True)
            self.auto_ik_but.SetImage(self.img_btnAutoIKOff, True)

        if btnState == True:
            self.main_logo.SetImage(self.img_d2c4dLogo, True)
            self.auto_import_fig_but.SetImage(self.img_btnAutoImport_FIG, True)
            self.auto_import_prop_but.SetImage(self.img_btnAutoImport_PROP, True)
            self.convert_mat_but.SetImage(self.img_btnConvertMaterials, True)
            self.auto_ik_but.SetImage(self.img_btnAutoIK, True)

        try:
            self.main_logo.LayoutChanged()
            self.main_logo.Redraw()
        except:
            print("DazToC4D: LayoutChanged skip...")
        c4d.StatusClear()
        c4d.EventAdd()
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        c4d.DrawViews(
            c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW
            | c4d.DRAWFLAGS_NO_THREAD
            | c4d.DRAWFLAGS_STATICBREAK
        )
        c4d.DrawViews()
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)
        bc = c4d.BaseContainer()
        c4d.gui.GetInputState(c4d.BFM_INPUT_MOUSE, c4d.BFM_INPUT_CHANNEL, bc)
        return True
Exemplo n.º 2
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
Exemplo n.º 3
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)
Exemplo n.º 4
0
def main():
    # Saves current time
    ctime = doc.GetTime()

    # Retrieves BaseTime of frame 5, 20
    start = 5
    end = 20

    # Loops through the frames
    for frame in range(start, end + 1):

        # Sets the Status Bar
        c4d.StatusSetBar(100.0 * float(frame - start) / float(end - start))

        # Changes the time of the document
        doc.SetTime(c4d.BaseTime(frame, doc.GetFps()))

        # Updates timeline
        c4d.GeSyncMessage(c4d.EVMSG_TIMECHANGED)

        # Redraws the viewport and regenerate the cache object
        c4d.DrawViews(c4d.DRAWFLAGS_ONLY_ACTIVE_VIEW | c4d.DRAWFLAGS_NO_THREAD
                      | c4d.DRAWFLAGS_STATICBREAK)

        # Do the stuff for each frame here you may be interested in BaseDocument.Polygonize()
        print("Frame {0}".format(frame))

    # Sets the time back to the original time.
    doc.SetTime(ctime)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd(c4d.EVENT_ANIMATE)

    # Clears the Status Bar
    c4d.StatusClear()
Exemplo n.º 5
0
def main():    
    # file location on computer
    fopen = open("C:\L4212G.asc")

    points = []
    lineNb = 0
    rowNb = 0.0
    first = fopen.readline()
    size = int(first[13:])

    for line in fopen:
        if lineNb > 6:
            ptnum = 0.0
            posz = rowNb / float(size -1) * size
            line = line[1:]

            for i in line.split(" "):
                posx = ptnum / float(size - 1) * size
                posy = float(i)
                pos = c4d.Vector(posx, posy, posz)
                c4d.StatusSetBar((lineNb/30))
                points.append(pos)
                ptnum += 1 

            rowNb += 1
        lineNb += 1
    
    poly = c4d.PolygonObject(len(points),0)
    poly.SetAllPoints(points)    
    doc.InsertObject(poly)
    c4d.StatusClear()
    fopen.close
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')
Exemplo n.º 7
0
    def CoreMessage(self, id, msg):
        """Override this function if you want to react
		to C4D core messages. The original message is stored in msg.
		"""
        if id == __exporter_id__:
            c4d.StatusSetBar(100)

            if g_uploaded:
                result = gui.MessageDialog(
                    "Your model was uploaded to Sketchfab.com.\nClick OK to open it in your browser.",
                    c4d.GEMB_OKCANCEL)
                if result == c4d.GEMB_R_OK:
                    webbrowser.open(Config.SKETCHFAB_URL + '/models/' +
                                    model_id)
            else:
                print("Unable to upload model to Sketchfab.com. Reason: {0}".
                      format(g_error))
                gui.MessageDialog(
                    "Unable to upload model to Sketchfab.com. Reason: {0}".
                    format(g_error), c4d.GEMB_OK)

            self.draw_upload_button()
            self.Enable(BTN_PUBLISH, True)
            self.SetTitle("Upload status")
            c4d.StatusClear()

        return True
Exemplo n.º 8
0
def main(undo = True):
    now = c4d.GeGetTimer() # start stopwatch
    c4d.CallCommand(13957) # Konsole löschen
    # c4d.CallCommand(12305) # Konsole...

    if GetActiveDocument():
        doc     = GetActiveDocument()
        if doc.GetFirstObject():
            c4d.StatusSetSpin()
            op = doc.GetFirstObject()
            myobject = op
            counter = numberofobjects(op)
            secondcounter = 0
            c4d.StatusSetText ('%s Objects are processed.' %(counter))
            opactive = None
        else:
            print "Error: No Objects"
            return False
    else:
        print "Error: No Document"
        return False
    
    #doc.StartUndo() # Start undo support
    # iterate over all objects in the document
    c4d.CallCommand(12113) # Alles deselektieren
    
    while op:
        
        optemp = op
        op = GetNextObject(op) # get next object    
            
        secondcounter += 1        
        statusbar(counter, secondcounter)

        if optemp.CheckType(c4d.Opolygon):
            optemp.SetBit(c4d.BIT_ACTIVE)
  
            if selchildren(optemp,optemp.GetNext()):
                c4d.CallCommand(16768) #Connect And Delete
                c4d.CallCommand(16768) #Connect And Delete
            
            opactive = doc.GetActiveObject()
            opactive.DelBit(c4d.BIT_ACTIVE)
                    
        optemp.DelBit(c4d.BIT_ACTIVE)
            

    c4d.StatusClear()
    #doc.EndUndo() # Do not forget to close the undo support
    c4d.EventAdd()        # update cinema 4d
    print 'END OF SCRIPT %s ms ' %(c4d.GeGetTimer() - now)
    return 
Exemplo n.º 9
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()
Exemplo n.º 10
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' )
def ReplaceRendersettingsFromScene(scene, append=True):
    c4d.StatusSetSpin()
    message = """Replacing current Render-Settings from: %s""" % (scene)
    c4d.StatusSetText(message)

    tdoc = c4d.documents.LoadDocument(
        scene, c4d.SCENEFILTER_ONLY_RENDERDATA
        | c4d.SCENEFILTER_IGNOREMISSINGPLUGINSINNONACTIVERENDERDATA, None)
    if tdoc is None:
        return

    trd = tdoc.GetFirstRenderData()
    active = tdoc.GetActiveRenderData()

    clones = list()
    while trd:
        clones.append(trd.GetClone())
        trd = trd.GetNext()

    rd = doc.GetFirstRenderData()
    current_rd = list()
    while rd:
        current_rd.append(rd)
        rd = rd.GetNext()

    doc.StartUndo()

    if not append:
        for rd in current_rd:
            doc.AddUndo(c4d.UNDOTYPE_DELETE, rd)
            rd.Remove()

    for trd in reversed(clones):
        doc.AddUndo(c4d.UNDOTYPE_NEW, trd)
        doc.InsertRenderDataLast(trd)
        if trd.GetData() == active.GetData():
            doc.SetActiveRenderData(trd)

    doc.EndUndo()
    c4d.EventAdd()

    c4d.StatusSetBar(0)
    c4d.StatusClear()
def main():
    td = doc.GetTakeData()
    mt = td.GetMainTake()
    take_list = td.GetTakeSelection(True)
    #cam = main.GetEffectiveCamera(td)
    #camname=c4d.BaseList2D.GetName(cam)
    c4d.StatusSetText("updating")
    print("status update")
    #print(cam.getType())
    #print(cam.getTypeName())
    #print(cam.GetObjectName())
    c4d.StatusSetBar(0)
    for i in take_list:
        if not i.IsMain():
            print(i)
            tempCam = i.GetEffectiveCamera(td)
            print(tempCam)
            cn = tempCam[0].GetName()
            print(cn)
            i.SetName(cn)
            #td.(i)
    c4d.StatusClear()
Exemplo n.º 13
0
def main():
    
    # get active document
    doc = c4d.documents.GetActiveDocument()

    # retrieve an instance of render data
    renderSettings = doc.GetActiveRenderData()

    # retrieve fps
    docFps = doc.GetFps()
    
    # Get Animation Length
    fromTime = renderSettings[c4d.RDATA_FRAMEFROM].GetFrame(docFps)
    toTime = renderSettings[c4d.RDATA_FRAMETO].GetFrame(docFps)
    animLength = toTime - fromTime + 1
    
    # prompt user for directory
    filePath = c4d.storage.SaveDialog()
    filePath, objName = os.path.split(filePath)
    objName = objName + "_"
    filePath = filePath + "\\"
    # Check for confirmation
    questionDialogText = "Obj Sequence will be saved as:\n\n"\
        "" + filePath + objName + "####.obj\n\n"\
        "From frame " + str(fromTime) + " to " + str(toTime) + " for " + str(animLength) + " frames.\n"
    proceedBool = c4d.gui.QuestionDialog(questionDialogText)
    
    if proceedBool == True:
        
        # Loop through animation and export frames
        for x in range(0,animLength):
            
            # change frame, redraw view
            moveTime = c4d.BaseTime(fromTime,docFps) + c4d.BaseTime(x,docFps)
            doc.SetTime(moveTime)
            c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
            c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)
            
            # progress bar
            c4d.StatusSetText("Exporting " + str(x) + " of " + str(animLength))
            c4d.StatusSetBar(100.0*x/animLength)
            
            # add buffer 0001
            bufferedNumber = str(doc.GetTime().GetFrame(docFps))
            if len(bufferedNumber)<4:
                for x in range(len(bufferedNumber),4):
                    bufferedNumber = "0" + bufferedNumber
            
            #save file   
            fileName = filePath+objName+bufferedNumber+".obj"
            print fileName
            c4d.documents.SaveDocument(doc,fileName,c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,c4d.FORMAT_OBJEXPORT)
        
    else: print "User directed cancel"
        
    c4d.StatusClear()
    
    # ask to open containing folder
    viewFilesBool = c4d.gui.QuestionDialog("Do you want to open containing folder?")
    if viewFilesBool == True:
        ('explorer "C:\path\of\folder"')
        subprocess.Popen('explorer ' + '"' + filePath + '"' )
    else:
        return None
Exemplo n.º 14
0
 def Main(self):
     global exportData
     doc = c4d.documents.GetActiveDocument()
     if doc is not None:
         workerExporter.startWorkerExport(exportData, self)
         c4d.StatusClear()
Exemplo n.º 15
0
def main():
    """ Step 1 - Setup and export AI-sequence with Sketch and Toon """
    keyMod = GetKeyMod() # Get keymodifier

    doc = c4d.documents.GetActiveDocument() # Get active Cinema 4D document
    sketchTags = [] # Initialize list for 'Sketch Style' tags

    if keyMod == "None":
        fn = c4d.storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING, "Select Save Path") # Select path to save
        if not fn: return # If cancelled stop the script

        sketchMat = c4d.BaseMaterial(1011014) # Initialize 'Sketch Material'
        doc.InsertMaterial(sketchMat) # Insert material to document
        sntFound, sketchEffect = SetRender(doc) # Set render settings
        SetExporter(doc) # Set exporter settings

        selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0) # Get selected objects
        for i in range(0, len(selection)): # Loop through selected objects
            sketchTags.append(c4d.BaseTag(1011012)) # Insert 'Sketch Style' tag to sketchTags list
            sketchTags[i][c4d.OUTLINEMAT_LINE_DEFAULT_MAT_V] = sketchMat # Put sketch material to sketch tag
            sketchTags[i][c4d.OUTLINEMAT_LINE_SPLINES] = 1 # Enable splines
            sketchTags[i][c4d.OUTLINEMAT_LINE_FOLD] = 0 # Disable fold
            sketchTags[i][c4d.OUTLINEMAT_LINE_CREASE] = 0 # Disable crease
            sketchTags[i][c4d.OUTLINEMAT_LINE_BORDER] = 0 # Disable border
            selection[i].InsertTag(sketchTags[i]) # Insert sketch tag to selected object

        name = os.path.splitext(fn)[0]+".ai" # File name
        c4d.documents.SaveDocument(doc, name, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1012074) # Export AI-file

    elif keyMod == "Shift":
        fn = c4d.storage.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Select Save Path", flags=c4d.FILESELECT_DIRECTORY) # Select folder to save
        if not fn: return # If cancelled stop the script

        sketchMat = c4d.BaseMaterial(1011014) # Initialize 'Sketch Material'
        doc.InsertMaterial(sketchMat) # Insert material to document
        sketchTags = [] # Initialize list for 'Sketch Style' tags

        sntFound, sketchEffect = SetRender(doc) # Set render settings
        SetExporter(doc) # Set exporter settings

        # Handle selected objects
        selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0) # Get selected objects
        for i in range(0, len(selection)): # Loop through selected objects
            #sketchTags.append(c4d.BaseTag(1011012)) # Insert 'Sketch Style' tag to sketchTags list
            sketchTag = c4d.BaseTag(1011012) # Initialize a sketch tag
            sketchTag[c4d.OUTLINEMAT_LINE_DEFAULT_MAT_V] = sketchMat # Put sketch material to sketch tag
            sketchTag[c4d.OUTLINEMAT_LINE_SPLINES] = 1 # Enable splines
            sketchTag[c4d.OUTLINEMAT_LINE_FOLD] = 0 # Disable fold
            sketchTag[c4d.OUTLINEMAT_LINE_CREASE] = 0 # Disable crease
            sketchTag[c4d.OUTLINEMAT_LINE_BORDER] = 0 # Disable border
            selection[i].InsertTag(sketchTag) # Insert sketch tag to selected object

            folderPath = os.path.splitext(fn)[0] # Folder path
            objectName = selection[i].GetName() # Get object name
            os.mkdir(folderPath+"\\"+objectName) # Create new folders
            fullFilePath = folderPath+"\\"+objectName+"\\"+objectName+".ai" # Full file path
            c4d.documents.SaveDocument(doc, fullFilePath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1012074) # Export AI-file
            sketchTag.Remove() # Delete sketch tag

    # Remove unnecessary stuff
    for st in sketchTags: # Loop through sketchTags
        st.Remove() # Remove 'Sketch Style' tag
    sketchMat.Remove() # Remove 'Sketch Material'
    if sntFound == False: # If there was not 'Sketch and Toon' render effect already
        sketchEffect.Remove() # Remove 'Sketch and Toon' render effect

    # Rest of the stuff
    c4d.StatusClear() # Clear status bar
    c4d.StatusSetText("Export complete!") # Set status text
    c4d.EventAdd() # Refresh Cinema 4D
Exemplo n.º 16
0
    def Command(self, id, msg):

        self.common_commands(id, msg)

        if id == BTN_THUMB_SRC_PATH:
            selected = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING)
            if not selected:
                return False
            else:
                self.SetString(EDITXT_THUMB_SRC_PATH, selected)

        if id == CHK_PRIVATE:
            if self.GetBool(CHK_PRIVATE):
                self.Enable(EDITXT_PASSWORD, True)
            else:
                self.draw_private_options()
                self.Enable(EDITXT_PASSWORD, False)

        if id == BTN_PUBLISH:
            c4d.StatusSetBar(50)
            g_upload_message = "Uploading..."
            self.draw_upload_button()

            activeDoc = c4d.documents.GetActiveDocument()
            activeDocPath = activeDoc.GetDocumentPath()
            if not os.path.exists(activeDocPath):
                path = c4d.storage.SaveDialog(
                    type=c4d.FILESELECTTYPE_ANYTHING,
                    title="Please save your .c4d scene",
                    force_suffix="c4d")
                result = c4d.documents.SaveDocument(
                    activeDoc, path, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                    c4d.FORMAT_C4DEXPORT)
                c4d.documents.LoadFile(path)
                if not result:
                    gui.MessageDialog("Please save your .c4d scene first.",
                                      c4d.GEMB_OK)
                    c4d.StatusClear()
                    return False

            # Set document data with newly saved document
            activeDoc = c4d.documents.GetActiveDocument()
            activeDocPath = activeDoc.GetDocumentPath()

            self.Enable(BTN_PUBLISH, False)
            self.SetTitle("{0} uploading model...".format(__exporter_title__))

            title = self.GetString(EDITXT_MODEL_TITLE)
            description = self.GetString(EDITXT_DESCRIPTION)
            tags = self.GetString(EDITXT_TAGS)
            private = self.GetBool(CHK_PRIVATE)
            password = self.GetString(EDITXT_PASSWORD)
            enable_animation = self.GetBool(CHK_ANIMATION)
            auto_publish = not (self.GetBool(CHK_PUBLISHDRAFT))

            # Error messages
            if len(title) == 0 or len(title) > 48 or len(description) > 1024:
                error_message = ""
                if len(title) == 0:
                    error_message = "Please enter a title for your model"
                if len(title) > 48:
                    error_message = "The model title must be less than 48 characters long"
                if len(description) > 1024:
                    error_message = "The description must be less than 1024 characters long"
                gui.MessageDialog(error_message, c4d.GEMB_OK)
                self.Enable(BTN_PUBLISH, True)
                self.SetTitle(__exporter_title__)
                c4d.StatusClear()
                return False

            # populate data
            data = {"source": "cinema4d", "tags": "cinema4d ", "title": title}
            data['isPublished'] = auto_publish
            if len(description) != 0:
                data['description'] = description
            if len(tags) != 0:
                data['tags'] += " ".join(tags.split(" ")[:41]).strip()
            if private:
                data['private'] = private
            if private and len(password) != 0:
                data['password'] = password

            # Start Multithread operations
            self.publish = PublishModelThread(self.skfb_api, data, title,
                                              activeDoc, activeDocPath,
                                              enable_animation)
            self.publish.Start()
            self.publish.Wait(True)

        return True
Exemplo n.º 17
0
def main():
    colors_objects_mgs = {}

    doc.StartUndo()

    c4d.StatusSetText("[1/2]: Collating by color.")
    c4d.StatusSetSpin()

    # Store objects by color
    obj = doc.GetFirstObject()
    while obj:
        color = obj[c4d.ID_BASEOBJECT_COLOR]
        color_string = repr(color)
        mg = obj.GetMg()

        obj_mg = (obj, mg)

        if color_string in colors_objects_mgs.keys():
            colors_objects_mgs[color_string].append(obj_mg)
        else:
            colors_objects_mgs[color_string] = [obj_mg]

        obj = GetNextObject(obj)

    c4d.StatusSetText("[2/2]: Grouping Objects.")
    # Build groups of objects by color
    pred_null = None
    for color_string, obj_mg_list in colors_objects_mgs.iteritems():
        # Find the center position of the objects
        average_pos = c4d.Vector(0.0)

        for obj, mg in obj_mg_list:
            average_pos += mg.off

        average_pos /= float(len(obj_mg_list))

        # Create a null centered between the objects
        null_obj = c4d.BaseObject(c4d.Onull)

        # Make it the same color as the objects
        null_obj[c4d.ID_BASEOBJECT_USECOLOR] = 1  # Automatic Mode
        null_obj[c4d.ID_BASEOBJECT_COLOR] = eval("c4d." + color_string)
        null_obj[c4d.NULLOBJECT_ICONCOL] = True

        # Center the null
        center_mg = c4d.Matrix()
        mg.off = average_pos

        # Ensure nulls are inserted roughly in the same order colors first occurred in the scene.
        doc.InsertObject(null_obj, pred=pred_null)
        pred_null = null_obj

        # Center the null
        null_obj.SetMg(center_mg)
        doc.AddUndo(c4d.UNDOTYPE_NEW, null_obj)

        # Move objects of the came color under the new null
        pred = None
        for obj, mg in obj_mg_list:
            doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj)
            obj.Remove()
            doc.InsertObject(obj, parent=null_obj, pred=pred)
            obj.SetMg(mg)
            pred = obj

    doc.EndUndo()
    c4d.EventAdd()
    c4d.StatusClear()
Exemplo n.º 18
0
def main():
    # ---------------------------------------------------------------------------------------------------
    # Setup and export AI-sequence with Sketch and Toon
    fn = c4d.storage.LoadDialog(
        c4d.FILESELECTTYPE_ANYTHING,
        "Select Save Path",
        flags=c4d.FILESELECT_DIRECTORY)  # Select path to save
    if not fn: return  # If cancelled stop the script
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    renderData = doc.GetActiveRenderData()  # Get document render data
    currVideoPost = renderData.GetFirstVideoPost()  # Get first render effect
    sntFound = False  # Initialize variable for storing info is 'Sketch and Toon' effect enabled already
    while currVideoPost is not None:  # Loop through render effects
        if currVideoPost.GetType(
        ) == 1011015:  # If 'Sketch and Toon' effect found
            sntFound = True  # Set variable to true
        currVideoPost = currVideoPost.GetNext(
        )  # Get next render effect on list
    if sntFound == False:  # If 'Sketch and Toon' effect is not enabled already
        sketchEffect = c4d.documents.BaseVideoPost(
            1011015)  # Initialize 'Sketch and Toon' effect
        renderData.InsertVideoPostLast(
            sketchEffect)  # Add 'Sketch and Toon' effect to render settings
    sketchMat = c4d.BaseMaterial(1011014)  # Initialize 'Sketch Material'
    doc.InsertMaterial(sketchMat)  # Insert material to document
    sketchTags = []  # Initialize list for 'Sketch Style' tags
    # ---------------------------------------------------------------------------------------------------
    # Export plug-in settings
    plug = plugins.FindPlugin(1012074, c4d.PLUGINTYPE_SCENESAVER)
    if plug is None:
        return
    data = {}
    if plug.Message(c4d.MSG_RETRIEVEPRIVATEDATA, data):
        if "imexporter" not in data:
            return
        aiExport = data["imexporter"]
        if aiExport is None:
            return
        # Change Illustrator export settings
        aiExport[c4d.TUAIEXPORT_OUTPUTSIZE] = 0  # Output: Render
        aiExport[c4d.TUAIEXPORT_ZSORT] = 0
        aiExport[c4d.TUAIEXPORT_SCALE] = 1  # Scale: 100%
        aiExport[c4d.TUAIEXPORT_EXPORTLINES] = 1  # Export lines
        aiExport[c4d.TUAIEXPORT_LINEOPACITY] = 0  # Disable line opacity
        aiExport[c4d.TUAIEXPORT_LINETHICKNESS] = 0  # Disable line thickness
        aiExport[c4d.TUAIEXPORT_LINEPATTERNS] = 0  # Disable line patterns
        aiExport[c4d.TUAIEXPORT_LINECONNECTIONS] = 1  # Enable line connections
        aiExport[c4d.TUAIEXPORT_EXPORTSURFACE] = 0  # Disable surface export
        aiExport[c4d.TUAIEXPORT_ANIMATION] = 1  # Export animation
        aiExport[c4d.TUAIEXPORT_ANIMTYPE] = 0  # Output As: Files
        aiExport[c4d.TUAIEXPORT_FRAMES] = 2  # Frames: Manual
        aiExport[c4d.TUAIEXPORT_FRAME_START] = doc.GetLoopMinTime(
        )  # Animation first frame
        aiExport[c4d.TUAIEXPORT_FRAME_END] = doc.GetLoopMaxTime(
        )  # Animation last frame
        aiExport[c4d.TUAIEXPORT_FRAME_RATE] = doc.GetFps()  # Frame rate
    # ---------------------------------------------------------------------------------------------------
    # Handle selected objects
    selection = doc.GetActiveObjects(
        c4d.GETACTIVEOBJECTFLAGS_0)  # Get selected objects
    for i in xrange(0, len(selection)):  # Loop through selected objects
        #sketchTags.append(c4d.BaseTag(1011012)) # Insert 'Sketch Style' tag to sketchTags list
        sketchTag = c4d.BaseTag(1011012)  # Initialize a sketch tag
        sketchTag[
            c4d.
            OUTLINEMAT_LINE_DEFAULT_MAT_V] = sketchMat  # Put sketch material to sketch tag
        sketchTag[c4d.OUTLINEMAT_LINE_SPLINES] = 1  # Enable splines
        sketchTag[c4d.OUTLINEMAT_LINE_FOLD] = 0  # Disable fold
        sketchTag[c4d.OUTLINEMAT_LINE_CREASE] = 0  # Disable crease
        sketchTag[c4d.OUTLINEMAT_LINE_BORDER] = 0  # Disable border
        selection[i].InsertTag(
            sketchTag)  # Insert sketch tag to selected object
        # ---------------------------------------------------------------------------------------------------
        folderPath = os.path.splitext(fn)[0]  # Folder path
        objectName = selection[i].GetName()  # Get object name
        os.mkdir(folderPath + "\\" + objectName)  # Create new folders
        fullFilePath = folderPath + "\\" + objectName + "\\" + objectName + ".ai"  # Full file path
        c4d.documents.SaveDocument(doc, fullFilePath,
                                   c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                                   1012074)  # Export AI-file
        sketchTag.Remove()  # Delete sketch tag
    # ---------------------------------------------------------------------------------------------------
    # Remove unnecessary stuff
    #for st in sketchTags: # Loop through sketchTags
    #st.Remove() # Remove 'Sketch Style' tag
    sketchMat.Remove()  # Remove 'Sketch Material'
    if sntFound == False:  # If there was not 'Sketch and Toon' render effect already
        sketchEffect.Remove()  # Remove 'Sketch and Toon' render effect
    # ---------------------------------------------------------------------------------------------------
    c4d.StatusClear()  # Clear status bar
    c4d.StatusSetText("Export complete!")  # Set status text
    c4d.EventAdd()  # Refresh Cinema 4D
Exemplo n.º 19
0
def main():

    clone = op[c4d.ID_USERDATA, 2]
    mat1 = op[c4d.ID_USERDATA, 3]
    mat2 = op[c4d.ID_USERDATA, 4]

    x = op[c4d.ID_USERDATA, 6]
    y = op[c4d.ID_USERDATA, 7]
    z = op[c4d.ID_USERDATA, 8]

    if clone == None or mat1 == None or mat2 == None or x == 0 or y == 0 or z == 0:
        return

    scale = op[c4d.ID_USERDATA, 10]
    if scale != 0:
        scale = 1 - 1 / float(z / 2) * scale
    else:
        scale = 1

    wiggle = op[c4d.ID_USERDATA, 11]
    val = op[c4d.ID_USERDATA, 12]
    seed = op[c4d.ID_USERDATA, 13]
    speed = op[c4d.ID_USERDATA, 14]
    size = clone.GetRad()

    rnd = random.Random()
    frame = doc.GetTime().GetFrame(doc.GetFps())
    null = c4d.BaseObject(c4d.Onull)

    for i in xrange(0, x):

        for j in xrange(0, y):

            c4d.StatusSetBar(int(float(100) / (x * y) * (i + j)))

            par = c4d.BaseObject(c4d.Onull)
            par.InsertUnder(null)
            par.SetRelPos(
                c4d.Vector((i - x) * size.x * 2 + size.x * (x + 1),
                           (j - y) * size.y * 2 + size.y * (y + 1), -size.y))

            for k in xrange(0, z):

                cube2 = c4d.BaseObject(c4d.Oinstance)
                cube2[c4d.INSTANCEOBJECT_LINK] = clone
                cube2[c4d.INSTANCEOBJECT_RENDERINSTANCE] = True
                cube2.InsertUnder(par)

                mtag = cube2.MakeTag(c4d.Ttexture)

                rnd.seed((i, j, k, seed))

                if rnd.random() > 0.5:
                    mtag[c4d.TEXTURETAG_MATERIAL] = mat1
                else:
                    mtag[c4d.TEXTURETAG_MATERIAL] = mat2

                tmpval = val * .1 * k / z
                tx = wiggle * .01 * (math.sin(frame * speed + math.pi * k / z)
                                     ) + rnd.random() * tmpval * 2 - tmpval
                rnd.jumpahead(9999)
                ty = rnd.random() * tmpval * 2 - tmpval
                rnd.jumpahead(9999)
                tz = rnd.random() * tmpval * 2 - tmpval

                if k > 0:
                    cube2.SetRelPos(c4d.Vector(0, 0, size.z * 2))
                cube2.SetRelRot(c4d.Vector(tx, ty, tz))
                cube2.SetRelScale(c4d.Vector(scale))

                par = cube2

    c4d.StatusClear()
    return null