-
Posts
361 -
Joined
-
Last visited
-
Days Won
15
Content Type
Profiles
Blogs
Forums
Gallery
Pipeline Tools
3D Wiki
Plugin List
Store
Downloads
Everything posted by kalugin
-
yeah, scripts are not meant to be used like that :) you can't do anything while the script is executing.
-
Well that was fun :) Here is a script that generates Conways game of live in the viewport :D Select some of the cells and there is a user data boolean named "alive". Check that and the cell will live :) import c4d def main(): grid_x = 20 grid_y = 20 cube_size = 10 spacing = 2 cubes = [] CreateMaterials() for x in xrange(grid_x): for y in xrange(grid_y): obj = c4d.BaseObject(5168) obj[c4d.PRIM_PLANE_WIDTH] = cube_size obj[c4d.PRIM_PLANE_HEIGHT] = cube_size obj[c4d.PRIM_PLANE_SUBW] = 1 obj[c4d.PRIM_PLANE_SUBH] = 1 obj.SetName(str(x) + " " + str(y)) matrix = c4d.Matrix() position = c4d.Vector(x*(cube_size+spacing), 0, y * (cube_size+spacing)) matrix.off = position obj.SetMg(matrix) cubes.append(obj) doc.InsertObject(obj) for cube in cubes: AddNeighbour(cube, "N", cube.GetName()) AddNeighbour(cube, "S", cube.GetName()) AddNeighbour(cube, "E", cube.GetName()) AddNeighbour(cube, "W", cube.GetName()) AddNeighbour(cube, "NE", cube.GetName()) AddNeighbour(cube, "SE", cube.GetName()) AddNeighbour(cube, "SW", cube.GetName()) AddNeighbour(cube, "NW", cube.GetName()) alive_data = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BOOL) alive_data[c4d.DESC_NAME] = 'alive' alive = cube.AddUserData(alive_data) cube[alive] = False dead_data = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BOOL) dead_data[c4d.DESC_NAME] = 'will die' will_die = cube.AddUserData(dead_data) cube[will_die] = True tex_tag = cube.MakeTag(5616) tex_tag.SetMaterial(doc.SearchMaterial("dead")) AddMainBrain(cubes) def AddMainBrain(cubes): null = c4d.BaseObject(c4d.Onull) null.SetName("brain") doc.InsertObject(null) selection = c4d.BaseObject(5190) selection.InsertUnder(null) s_list = c4d.InExcludeData() # s_list = selection[c4d.SELECTIONOBJECT_LIST] for cube in cubes: s_list.InsertObject(cube, 0) selection[c4d.SELECTIONOBJECT_LIST] = s_list tag = null.MakeTag(1022749) tag[c4d.TPYTHON_FRAME] = True tag[c4d.TPYTHON_CODE] = """ import c4d def main(): obj = op.GetObject() selection = obj.GetDown() s_list = selection[c4d.SELECTIONOBJECT_LIST] count = s_list.GetObjectCount() cubes = [] for i in xrange(1, count): cubes.append(s_list.ObjectFromIndex(doc, i)) for cube in cubes: my_tex_tag = cube.GetTag(5616) if cube[c4d.ID_USERDATA,9]: my_tex_tag.SetMaterial(doc.SearchMaterial('alive')) else: my_tex_tag.SetMaterial(doc.SearchMaterial('dead')) for cube in cubes: alive = 0 neighbours = [] for i in xrange(1, 9): if cube[c4d.ID_USERDATA,i]: neighbours.append(cube[c4d.ID_USERDATA,i]) for n in neighbours: if n[c4d.ID_USERDATA,9]: alive += 1 if alive < 2 and cube[c4d.ID_USERDATA,9]: cube[c4d.ID_USERDATA,10] = True if alive > 1 and alive < 4 and cube[c4d.ID_USERDATA,9]: cube[c4d.ID_USERDATA,10] = False if alive > 3 and cube[c4d.ID_USERDATA,9]: cube[c4d.ID_USERDATA,10] = True if not cube[c4d.ID_USERDATA,9] and alive == 3: cube[c4d.ID_USERDATA,10] = False for cube in cubes: if cube[c4d.ID_USERDATA,10]: cube[c4d.ID_USERDATA,9] = False else: cube[c4d.ID_USERDATA,9] = True """ def AddNeighbour(obj, name, obj_name): coords = obj_name.split(" ") x = int(coords[0]) y = int(coords[1]) if name == 'E': x += 1 elif name == 'W': x -= 1 elif name == 'N': y += 1 elif name == 'S': y -= 1 elif name == "NW": y += 1 x -= 1 elif name == "NE": y += 1 x += 1 elif name == "SE": y -= 1 x += 1 elif name == "SW": y -= 1 x -= 1 bc = c4d.GetCustomDataTypeDefault(c4d.DTYPE_BASELISTLINK) bc[c4d.DESC_NAME] = name element = obj.AddUserData(bc) neighbour = doc.SearchObject(str(x) + " " + str(y)) if neighbour: obj[element] = neighbour def CreateMaterials(): if not doc.SearchMaterial('dead'): dead_mat = c4d.BaseMaterial(5703) dead_mat[c4d.MATERIAL_USE_REFLECTION] = False dead_mat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(0.5) dead_mat.SetName("dead") doc.InsertMaterial(dead_mat) if not doc.SearchMaterial('alive'): alive_mat = c4d.BaseMaterial(5703) alive_mat[c4d.MATERIAL_USE_REFLECTION] = False alive_mat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(1, 1, 0) alive_mat.SetName("alive") doc.InsertMaterial(alive_mat) if __name__=='__main__': main() c4d.EventAdd()
-
doesn't Conway's game of life also account for the diagonals ?
-
Nice :)
-
is this something like what you are trying to achieve ? It's quick and dirty, so it may have some bugs. modify_userdata_another_group_kalugin.c4d
-
Like this ? object_list_from_material.c4d
-
well, it sound quite straight forward, but it depends how the plugin is writen. I did something like that in python a few years ago to learn some stuff inside Cinema4D.
-
There is actually some issue with the indexing, but I didn't found what it is. I tried making a separate tag for each object and it works.
-
the problem is that some of the data never is in the same place. If you have more actors listed, the genre, the country and the other info after the actors list, gets pushed back in the index of the csv file, so there is not consistent way to extract the data just from a place index. If you had some identifiers it would be super simple. Like Title:Something, Director:Someone, Actor:Someone, Actor:Someone, Actor:Someone, Country:Somewhere, Year:Sometime, Genre:Something .....
-
hm you are right, i haven't noticed. I'll check it out
-
clone speedScale_002_edit.c4d
-
well, this can work but there are some problems with the data organization. It's not consistant. What are you using to generate the .csv file ?
-
@lofqvist if you can share an example of your data - it will be easier to help you.
-
It starts at 0,0 :) Only in screen space that is your upper left corner
-
it's working exactly as it is supposed to. It takes coordinates in screenspace (pixels) you will need to check to conversions from world coordinates to screen space coordinates.
-
great news really :) I just wonder when developers will stop trying to sell the "unbiased" . There is no unbiased render engine. If there is - it will be slow to the point it's useless. Do you want your render to finish ? If the answer is "Yes" - then you are using a biased render engine. The difference is that some engines have more settings than others open to the user. The so called "unbiased" render engines just have most of the settings hard coded and leave a lot less control to the user. I'm talking about the high end engines. Almost everyone of them that has a QMC (brute force) option, should be called unbiased by the terms that they use.
-
the blog says "we won’t be delivering this as part of Release 18 " so don't jump on the hype train yet :) I can't wait to see what MAXON has in store for September
-
can you point out some usefull tutorial, I'm going to learn UE, but i always can't find enough time to sit and dig deep into it :) Your project turned out well, the only thing that bothers me is there is a bit too strong ambient occlusion on the edges and your camera seems to be crooked to the right, or if I have to say it in C4D terms - it seems rotated 1degree on B :)
-
Have fun my friend, note that, when you want to update the splines, you can't use "replace selected method" with the "import all files" checked on, it works for a single selected spline, and it doesn't check what's it's name. It simply will replace the spline you have selected with the spline that you open as a single file. I have an idea how to make it work to replace only the selected splines, based on the filenames, but for now, I think i helped you quite a lot and I have other things to do :) import c4d import os import glob from os.path import basename from c4d import gui,storage,documents RADIO_GROUP = 10000 RADIO_OPTIONS = 10001 RADIO_BY_SELECTION = 10002 RADIO_BY_NAME = 10003 RADIO_NEW_SPLINE = 10004 GROUP_BUTTONS = 10005 BTN_SELECT_FILE = 10006 BTN_CANCEL = 10007 CHK_ALL_FILES = 10008 class Settings(gui.GeDialog): def CreateLayout(self): self.SetTitle("Create spline from 'csv' file") self.AddRadioGroup(RADIO_GROUP, c4d.BFH_LEFT,1,1) self.AddChild(RADIO_GROUP,RADIO_NEW_SPLINE,"Create new spline") self.AddChild(RADIO_GROUP,RADIO_BY_SELECTION,"Replace selected") self.AddChild(RADIO_GROUP, RADIO_BY_NAME, "Replace by name") self.SetBool(RADIO_NEW_SPLINE,True) self.GroupEnd() self.AddSeparatorH(c4d.BFH_SCALE) self.AddCheckbox(CHK_ALL_FILES,c4d.BFH_SCALEFIT,initw=1,inith=1,name="Import all files in the directory") self.SetBool(CHK_ALL_FILES,False) self.AddSeparatorH(c4d.BFH_SCALE) self.GroupBegin(GROUP_BUTTONS,c4d.BFH_CENTER,2,1) self.AddButton(BTN_SELECT_FILE,c4d.BFH_SCALE,name="Select file") self.AddButton(BTN_CANCEL,c4d.BFH_SCALE,name="Cancel") self.GroupEnd() self.ok = False return True def Command(self,id,msg): if id==BTN_CANCEL: self.Close() elif id==BTN_SELECT_FILE: self.ok = True self.replace_by_name = self.GetBool(RADIO_BY_NAME) self.replace_by_selection = self.GetBool(RADIO_BY_SELECTION) self.create_new_spline = self.GetBool(RADIO_NEW_SPLINE) self.all_files = self.GetBool(CHK_ALL_FILES) self.Close() return True def splineCreator(lines,name,replace_method): pointCount = len(lines) Spline = c4d.SplineObject(pointCount,0) Spline[c4d.ID_BASELIST_NAME] = name n = 0 for line in lines: pos = c4d.Vector() pos.x = line[0] pos.y = line[1] pos.z = line[2] Spline.SetPoint(n,pos) n+=1 if replace_method == "new_spline": doc.InsertObject(Spline,checknames=True) elif replace_method == "by_selection": old_spline = doc.GetActiveObject() if not old_spline: gui.MessageDialog("No object is selected") return Spline.InsertAfter(old_spline) doc.AddUndo(c4d.UNDOTYPE_DELETE,old_spline) old_spline.Remove() elif replace_method == "by_name": old_spline = doc.SearchObject(name) if not old_spline: gui.MessageDialog("Cannot find a spline with the same name") return Spline.InsertAfter(old_spline) doc.AddUndo(c4d.UNDOTYPE_DELETE,old_spline) old_spline.Remove() Spline.Message(c4d.MSG_UPDATE) doc.AddUndo(c4d.UNDOTYPE_NEW, Spline) c4d.EventAdd() def csvReader(csvFile): csv = csvFile.read().splitlines() csvFile.close() lines = [] for line in csv: stringLine = line.split(",") n = 0 for value in stringLine: stringLine[n] = float(value) n+=1 lines.append(stringLine) return lines def main(): doc = c4d.documents.GetActiveDocument() c4d.EventAdd(flags = 1) doc.StartUndo() dlg = Settings() dlg.Open(c4d.DLG_TYPE_MODAL,defaultw=200,defaulth=50) if not dlg.ok: return if dlg.replace_by_selection: replace_method = "by_selection" elif dlg.replace_by_name: replace_method = "by_name" elif dlg.create_new_spline: replace_method = "new_spline" path = storage.LoadDialog(title = "Select a csv file") if path: directory = os.path.dirname(path) name = os.path.splitext(basename(path))[0] files = glob.glob(directory + "\*.csv") if dlg.all_files: for csv in files: fileName = os.path.splitext(basename(csv))[0] csvFile = open(csv,"r",1) lines = csvReader(csvFile) splineCreator(lines,fileName,replace_method) else: csvFile = open(path,"r",1) lines = csvReader(csvFile) splineCreator(lines,name,replace_method) doc.EndUndo() else: print "You must select a csv file." if __name__=='__main__': main()
-
There are two ways, if you don't have splines with the same names, when you load a file and the name of the file already exist in the scene, it will delete the current and replace it with the new one. The other way is to simply replace the selected spline. I will do something about it later ;)
-
import c4d import os from os.path import basename from c4d import gui,storage,documents #Welcome to the world of Python def splineCreator(lines,name): pointCount = len(lines) Spline = c4d.SplineObject(pointCount,0) Spline[c4d.ID_BASELIST_NAME] = name n = 0 for line in lines: pos = c4d.Vector() pos.x = line[0] pos.y = line[1] pos.z = line[2] Spline.SetPoint(n,pos) n+=1 doc.InsertObject(Spline,checknames=True) Spline.Message(c4d.MSG_UPDATE) doc.AddUndo(c4d.UNDOTYPE_NEW, Spline) c4d.EventAdd() def csvReader(csvFile): csv = csvFile.read().splitlines() csvFile.close() lines = [] for line in csv: stringLine = line.split(",") n = 0 for value in stringLine: stringLine[n] = float(value) n+=1 lines.append(stringLine) return lines def main(): doc = c4d.documents.GetActiveDocument() c4d.EventAdd(flags = 1) doc.StartUndo() path = storage.LoadDialog(title = "Select a csv file") name = os.path.splitext(basename(path))[0] if path: csvFile = open(path,"r",1) lines = csvReader(csvFile) splineCreator(lines,name) doc.EndUndo() else: print "You must select a csv file." if __name__=='__main__': main()
-
1. I don't know why is that, when I try it, it doesn't ask twice for a csv file. Also the code as it is should not ask twice :) and there is no empty spline 2.I can run it as many times as i want, it has no limit on that. 3.I will see if I have time to add the file name to the spline name Maybe your other files are different ? the sample that you attached works perfect
-
import c4d from c4d import gui,storage,documents #Welcome to the world of Python def splineCreator(lines): pointCount = len(lines) Spline = c4d.SplineObject(pointCount,0) Spline[c4d.ID_BASELIST_NAME] = "csv spline" n = 0 for line in lines: pos = c4d.Vector() pos.x = line[0] pos.y = line[1] pos.z = line[2] Spline.SetPoint(n,pos) n+=1 doc.InsertObject(Spline,checknames=True) Spline.Message(c4d.MSG_UPDATE) doc.AddUndo(c4d.UNDOTYPE_NEW, Spline) c4d.EventAdd() def csvReader(csvFile): csv = csvFile.read().splitlines() csvFile.close() lines = [] for line in csv: stringLine = line.split(",") n = 0 for value in stringLine: stringLine[n] = float(value) n+=1 lines.append(stringLine) return lines def main(): doc = c4d.documents.GetActiveDocument() c4d.EventAdd(flags = 1) doc.StartUndo() path = storage.LoadDialog(title = "Select a csv file") if path: csvFile = open(path,"r",1) lines = csvReader(csvFile) splineCreator(lines) doc.EndUndo() else: print "You must select a csv file." if __name__=='__main__': main() this works for your example, but it assumes that there is only 1 spline in the file Cheers :)
-
can you upload a sample txt file ?