-
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
-
it was in this line while obj.GetUp() and not obj.GetNext() and obj.GetUp() != parent: I changed it to obj.GetUp() != parent so it doesn't go outside the selected object hierarchy
-
oops :) My bad, a stupid mistake import c4d def main(): obj = doc.GetActiveObject() parent = obj if obj: children = [] while obj: obj = walker(parent, obj) if obj: children.append(obj) print children def walker(parent, obj): if not obj: return elif obj.GetDown(): return obj.GetDown() while obj.GetUp() and not obj.GetNext() and obj.GetUp() != parent: obj = obj.GetUp() return obj.GetNext() if __name__=='__main__': main()
-
you can append the parent if you want it in the list :) just add children.append(parent) before the "while obj:" line
-
import c4d def main(): obj = doc.GetActiveObject() parent = obj if obj: children = [] while obj: obj = walker(parent, obj) if obj: children.append(obj) print children def walker(parent, obj): if not obj: return elif obj.GetDown(): return obj.GetDown() while obj.GetUp() and not obj.GetNext() and obj != parent: obj = obj.GetUp() return obj.GetNext() if __name__=='__main__': main()
-
here is a script version for anyone curious :) import c4d def main(): selected = doc.GetActiveObjects(0) # gets the current active objects parent = selected[0].GetUp() # gets the parent of the first object in the selection if parent: #if the object has a parent for obj in selected: obj.DelBit(c4d.BIT_ACTIVE) # the script deselects the active objects parent.SetBit(c4d.BIT_ACTIVE) # and selects the parent c4d.EventAdd() if __name__=='__main__': main()
-
I don't think it could be done with a script. Maybe a command data plugin is the way to go. The script can't 'wait' for other processes to finish. It is executed and after that Cinema continues with the other things. What exactly are you trying to do ? Maybe including a simple undo stack will be enough ?
-
import c4d from c4d import gui #Welcome to the world of Python #Unique id numbers for each of the GUI elements BACKGROUND = 1000 BACKGROUND_COLOR = 1001 GROUP_OPTIONS = 10000 OPTION_COLOR = 10001 OPTION_AO = 10002 GROUP_BUTTONS = 20000 BUTTON_OK = 20001 BUTTON_CANCEL = 20002 OPTION_WIDTH = 20003 OPTION_HIGHT = 20004 #This class defines the dialogue that pops up to request user options class OptionsDialog(gui.GeDialog): #Add all the items we want to show in the dialogue box def CreateLayout(self): #Bake cehck box self.GroupBegin(GROUP_OPTIONS, c4d.BFH_SCALE|c4d.BFH_LEFT, 1, 2) self.AddCheckbox(OPTION_COLOR, c4d.BFH_LEFT, 0,0, name="Color") self.AddCheckbox(OPTION_AO, c4d.BFH_LEFT, 0,0, name="AO") self.GroupEnd() #BG color self.AddStaticText(BACKGROUND, c4d.BFH_LEFT, name="Background Color") self.AddColorField(BACKGROUND_COLOR, c4d.BFH_SCALEFIT, 80, 12) #Group name self.GroupBegin(10000, c4d.BFH_SCALEFIT, 1, title = 'Texture size') self.GroupBorder(c4d.BORDER_GROUP_IN) self.GroupBorderSpace(20, 5, 20, 5) #Arrow numbers self.AddEditNumberArrows(OPTION_WIDTH, c4d.BFH_SCALEFIT, 50, 0) self.AddEditNumberArrows(OPTION_HIGHT, c4d.BFH_SCALEFIT, 50, 0) #Buttons - an OK and a CANCEL button self.GroupBegin(GROUP_OPTIONS, c4d.BFH_CENTER, 2, 1) self.AddButton(BUTTON_OK, c4d.BFH_SCALE, name="Set") self.AddButton(BUTTON_CANCEL, c4d.BFH_SCALE, name="Cancel") self.GroupEnd() return True #This is where we react to user input (eg button clicks) def Command(self, id, msg): if id==BUTTON_CANCEL: #The user has clicked the 'Cancel' button self.ok = False self.Close() elif id==BUTTON_OK: #The user has clicked the 'OK' button self.ok = True #Save the checkbox values so that the rest of the script can access them self.option_color = self.GetBool(OPTION_COLOR) self.option_AO = self.GetBool(OPTION_AO) self.option_BG = self.GetColorField(BACKGROUND_COLOR)['color'] # GetColorField returns a dictionary. The actual vector of the color is an item with the key 'color' self.option_width = self.GetInt32(OPTION_WIDTH) # the field in the BakeTexture tag expects integers, not floats ;) self.option_hight = self.GetInt32(OPTION_HIGHT) self.Close() return True #This is where the action happens def main(): #Open the options dialogue to let users choose their options optionsdialog = OptionsDialog() optionsdialog.Open(c4d.DLG_TYPE_MODAL, defaultw=300, defaulth=50) #Quit if the user has clicked cancel if not optionsdialog.ok: return #create tag def tool(): return plugins.FindPlugin(doc.GetAction(), c4d.PLUGINTYPE_TOOL) def object(): return doc.GetActiveObject() def tag(): return doc.GetActiveTag() def renderdata(): return doc.GetActiveRenderData() def prefs(id): return plugins.FindPlugin(id, c4d.PLUGINTYPE_PREFS) # c4d.CallCommand(100004788, 50005) # you should avoid using CallCommand if where you can. tag = doc.GetActiveObject().MakeTag(c4d.Tbaketexture) # this creates the tag and applies it to the active object tag[c4d.BAKETEXTURE_CHANNEL_COLOR] = optionsdialog.option_color # you don't need () around the variables tag[c4d.BAKETEXTURE_CHANNEL_AO] = optionsdialog.option_AO tag[c4d.BAKETEXTURE_WIDTH] = optionsdialog.option_width tag[c4d.BAKETEXTURE_HEIGHT] = optionsdialog.option_hight tag[c4d.BAKETEXTURE_BACKGROUND] = optionsdialog.option_BG c4d.EventAdd() if __name__=='__main__': main() Try this. I commented the changes :) Ask if you have questions.
-
I did it also for the deformers, they are now placed in the position of the parents. import c4d clonerObject = c4d.BaseObject(1018544) def addGenerator(generator, objs): selectedObjects = doc.GetActiveObjects(0) if len(selectedObjects) == 0: doc.InsertObject(generator) doc.AddUndo(c4d.UNDOTYPE_NEW, generator) else: for obj in selectedObjects: child_matrix = obj.GetMg() new_generator = generator.GetClone() new_generator.InsertBefore(obj) new_generator.SetMg(child_matrix) doc.AddUndo(c4d.UNDOTYPE_NEW, new_generator) doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj) obj.InsertUnder(new_generator) obj.SetMg(child_matrix) def main(): doc.StartUndo() selectedObjects = doc.GetActiveObjects(0) addGenerator(clonerObject, selectedObjects) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main() import c4d bendDeformer = c4d.BaseObject(c4d.Obend) def addDeformer(deformer, objs): selectedObjects = doc.GetActiveObjects(0) if len(selectedObjects) == 0: doc.InsertObject(deformer) doc.AddUndo(c4d.UNDOTYPE_NEW, deformer) else: for obj in selectedObjects: child_matrix = obj.GetMg() new_deformer = deformer.GetClone() new_deformer.InsertUnder(obj) new_deformer.SetMg(child_matrix) doc.AddUndo(c4d.UNDOTYPE_NEW, new_deformer) def main(): doc.StartUndo() selectedObjects = doc.GetActiveObjects(0) addDeformer(bendDeformer, selectedObjects) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main()
-
Well, I assumed that you will separate them :) I just included them in a single snippet so that I don't post twice almost identical code. I will add the positioning. In the meantime - you version doesn't work, because in the "main" function you are calling the "addGenerator" function and you are passing the "selectedObjects" argument, but you have deleted the definition of "selectedObjects" :) "selectedObjects = doc.GetActiveObjects(0)" must be declared before that.
-
I'm too sleepy now to comment it all out :) if you have any questions - I'll be glad to help.
-
@FloatinPoint import c4d bendDeformer = c4d.BaseObject(c4d.Obend) clonerObject = c4d.BaseObject(1018544) def addGenerator(generator, objs): selectedObjects = doc.GetActiveObjects(0) if len(selectedObjects) == 0: doc.InsertObject(generator) doc.AddUndo(c4d.UNDOTYPE_NEW, generator) else: for obj in selectedObjects: new_generator = generator.GetClone() new_generator.InsertBefore(obj) doc.AddUndo(c4d.UNDOTYPE_NEW, new_generator) doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj) obj.InsertUnder(new_generator) def addDeformer(deformer, objs): selectedObjects = doc.GetActiveObjects(0) if len(selectedObjects) == 0: doc.InsertObject(deformer) doc.AddUndo(c4d.UNDOTYPE_NEW, deformer) else: for obj in selectedObjects: new_deformer = deformer.GetClone() new_deformer.InsertUnder(obj) doc.AddUndo(c4d.UNDOTYPE_NEW, new_deformer) def main(): what_to_add = 'generator' doc.StartUndo() selectedObjects = doc.GetActiveObjects(0) if what_to_add == 'generator': addGenerator(clonerObject, selectedObjects) elif what_to_add == 'deformer': addDeformer(bendDeformer, selectedObjects) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main()
-
That's more complicated. You will need a recursive function to dig in the shader structure and check for textures everywhere. Also you would need a different code for the different shaders as they have different slots and ids. Creating the layer shader should not be that hard. It can be done - in theory :).
-
Yeah, hiding the code helps them learn a lot.
-
well, the script is a single click solution :) You just run the script, select the csv file and it will do all the keyframes for you tag. example:
-
this script will work only in specific case. You need to have an object selected, with an align to spline tag, which has a spline assigned. The second column in your csv file must be the position on the spline. Try it. Also It doesn't account for the frame number in the .csv. It just assumes that the second row is the 0 frame (first row are the names of the values/columns) coasterinc.py air fps limited.csv
-
for mat in materials: if mat.GetType() == 5703: if mat[c4d.MATERIAL_COLOR_SHADER] != None: filter_shader = c4d.BaseShader(1011128) texture = mat[c4d.MATERIAL_COLOR_SHADER].GetClone() ....
-
I got an answer on the plugin cafe http://www.plugincafe.com/forum/forum_posts.asp?TID=14052
-
import c4d def main(): doc.StartUndo() materials = doc.GetMaterials() for mat in materials: if mat.GetType() == 5703: filter_shader = c4d.BaseShader(1011128) texture = mat[c4d.MATERIAL_COLOR_SHADER].GetClone() filter_shader[c4d.SLA_FILTER_TEXTURE] = texture filter_shader[c4d.SLA_FILTER_LIGHTNESS] = 0.3 filter_shader.InsertShader(texture) doc.AddUndo(c4d.UNDOTYPE_CHANGE, mat) mat[c4d.MATERIAL_COLOR_SHADER] = filter_shader mat.InsertShader(filter_shader) if texture.GetType() == 5833: # checks if the diffuse slot is an bitmap shader #check if bump channel is active and if not - activate if not mat[c4d.MATERIAL_USE_BUMP]: mat[c4d.MATERIAL_USE_BUMP] = True bump_shader = filter_shader.GetClone() bump_shader[c4d.SLA_FILTER_SATURATION] = -1.0 mat[c4d.MATERIAL_BUMP_SHADER] = bump_shader mat.InsertShader(bump_shader) #check if reflectance is active and if not - activate if not mat[c4d.MATERIAL_USE_REFLECTION]: mat[c4d.MATERIAL_USE_REFLECTION] = True base = c4d.REFLECTION_LAYER_LAYER_DATA + c4d.REFLECTION_LAYER_LAYER_SIZE * 4 refl_shader = filter_shader.GetClone() refl_shader[c4d.SLA_FILTER_HUE] = 0.0 refl_shader[c4d.SLA_FILTER_SATURATION] = -1.0 refl_shader[c4d.SLA_FILTER_LIGHTNESS] = 0.0 refl_shader[c4d.SLA_FILTER_BRIGHNESS] = 0.0 refl_shader[c4d.SLA_FILTER_CONTRAST] = 0.0 refl_shader[c4d.SLA_FILTER_GAMMA] = 1.0 mat[base+c4d.REFLECTION_LAYER_COLOR_TEXTURE] = refl_shader mat.InsertShader(refl_shader) doc.EndUndo() c4d.EventAdd() if __name__=='__main__': main() Cheers :)
-
Hello fellow code crunchers :) I'm trying to drag and drop a custom extension file into the editor window. So far so good, but i can't figure out how to merge the file in the active document. It always creates a new doc. Where can i pass the flags for the Load() method ? I think i need to pass the c4d.SCENEFILTER_MERGESCENE. import c4d Plugin_ID = 123456 class dsLoader(c4d.plugins.SceneLoaderData): def Identify(self, node, name, probe, size): file_name = name.lower() if not file_name.endswith('.ds'): return False return True def ReadLines(self, file): with open(file, 'rU') as data: ds_file = data.read().splitlines() for line in ds_file: print line def Load(self, node, name, doc, filterflags, error, bt): self.ReadLines(name) c4d.EventAdd() return c4d.FILEERROR_NONE if __name__ == "__main__": c4d.plugins.RegisterSceneLoaderPlugin(id=Plugin_ID, str="dsLoader", g=dsLoader, info=c4d.PLUGINFLAG_SCENELOADER_MERGEORIGINAL, description="") does anyone have an idea how to tackle this ?
-
It depends on you programing skills and what is your intention. I prefer python, cause it's faster to learn and write, but it has some limitations. Not everything in Cinema is accessible via python. on the other hand - you can do anything with c++, but coding in c++ is a lot more tedious task. Melange is just a library for constructing c4d files without opening Cinema 4D. I'm not sure that is what you want to do.
-
why a MoSpline ? Can you give an example of the CSV structure ?
-
if you can share a part of the .csv file...
-
think of cycles as iterations of the formula, that generates the noise. It's like subdivisions, but iterations is more accurate term :)