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()
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
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')
def updateCanvas(mainDialog,exportData): doc=c4d.documents.GetActiveDocument() if doc is None: statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE1) mainDialog.userarea.draw([statusStr,0,0]) return if doc is not None: if doc.GetDocumentPath() is None or doc.GetDocumentPath()=="": statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE1) mainDialog.userarea.draw([statusStr,0,0]) return if exportData is None: statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE2) mainDialog.userarea.draw([statusStr,0,0]) return if exportData.status==0: statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE3) mainDialog.userarea.draw([statusStr,0,0]) return curPercent=float(float(exportData.allStatus)/float(exportData.allStatusLength)) c4d.StatusSetBar(curPercent) if exportData.status==1: statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE4)+" "+str(int(curPercent*100))+" %" mainDialog.userarea.draw([statusStr,curPercent,0]) return if exportData.status==2: statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE5)+" "+str(int(curPercent*100))+" %" mainDialog.userarea.draw([statusStr,curPercent,float(exportData.subStatus)]) return if exportData.status==3: statusStr=c4d.plugins.GeLoadString(ids.STATUSMESSAGE)+c4d.plugins.GeLoadString(ids.STATUSMESSAGE6)+" "+str(int(curPercent*100))+" %" mainDialog.userarea.draw([statusStr,curPercent,0]) return
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()
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
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
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
def statusbar (counter, secondcounter): # c4d.StatusSetText ('%s - %s Objects are processed.' %(secondcounter, counter)) c4d.StatusSetBar(100*secondcounter/counter) #statusbar