Jump to content

kalugin

Premium Member
  • Posts

    361
  • Joined

  • Last visited

  • Days Won

    15

Everything posted by kalugin

  1. unzip in your plugins folder :) Spacer.zip
  2. @Vizn Yeah, that's the idea :) I just need to fix some things and I'll share it.
  3. I've just started playing with the idea. I'll share the result when it's ready. But it is really basic cloner anyways. If it has some potential, maybe I'll invest more time to make it a full featured plugin.
  4. @Hrvoje this is not what @Vizn and @Cerbera are talking about. Or maybe I didn't understand :) I thought the idea was to get a result similar to this:
  5. if it's just a linear cloner it sounds like a fun little task :) I'll do it. Grid and radial will take more time.
  6. It's link is in the downloads section from quite some time, but i think that i've forgotten to make a topic here :D https://www.c4dcafe.com/ipb/files/file/1103-group-object/
  7. i don't think hiding polygons will optimize your workflow a lot. If it's the visual effect you are looking for, then OK. C4D can handle many polys with no problem. The issue comes with a lot of objects.
  8. import c4d from c4d import gui #Welcome to the world of Python def main(): camera = c4d.BaseObject(c4d.Ocamera) # this creates the object in the memory, but does not add it to the scene tag = c4d.BaseTag(c4d.Ttargetexpression) # this creates the tag in memory null = c4d.BaseObject(c4d.Onull) # create the null in memory doc.InsertObject(camera) # insert the camera object in the scene doc.InsertObject(null) # insert the null camera.InsertTag(tag) # apply the tag to the camera tag[c4d.TARGETEXPRESSIONTAG_LINK] = null # set the target object in the tag to be the null bd = doc.GetActiveBaseDraw() # get the active base draw object (This class represents a Cinema 4D window) currentCam = bd.GetEditorCamera() # get the "point" you are looking from camMatrix = currentCam.GetMg() # get the matrix of that point (position, rotation, scale) camera.SetMg(camMatrix) # apply that matrix to your newly created camera editor_size = bd.GetFrame() # gets the borders of the editor window in pixels x_center = editor['cr']/2 # 'cr' is the right border, divide by 2 and we get the x center y_center = editor['cb']/2 # 'cb' is the bottom border, divide by 2 and we get the y center center_point = bd.ProjectPointOnPlane(c4d.Vector(0, 0, 0), c4d.Vector(0, 1, 0), x_center, y_center)[0] # this function generates a 3D position on a virtual floor object, based on screen coordinates in x,y matrix = c4d.Matrix() # create an empty matrix matrix.off = center_point # set that matrix position to the center point null.SetMg(matrix) # set the null's matrix to the new matrix (with the center position) c4d.EventAdd() # inform cinema that something has happend, so it updates. if __name__=='__main__': main()
  9. null is created at 0,0,0. You didn't say that you want to create it somewhere else :)
  10. import c4d from c4d import gui #Welcome to the world of Python def main(): camera = c4d.BaseObject(c4d.Ocamera) # this creates the object in the memory, but does not add it to the scene tag = c4d.BaseTag(c4d.Ttargetexpression) # this creates the tag in memory null = c4d.BaseObject(c4d.Onull) # create the null in memory doc.InsertObject(camera) # insert the camera object in the scene doc.InsertObject(null) # insert the null camera.InsertTag(tag) # apply the tag to the camera tag[c4d.TARGETEXPRESSIONTAG_LINK] = null # set the target object in the tag to be the null bd = doc.GetActiveBaseDraw() # get the active base draw object (This class represents a Cinema 4D window) currentCam = bd.GetEditorCamera() # get the "point" you are looking from camMatrix = currentCam.GetMg() # get the matrix of that point (position, rotation, scale) camera.SetMg(camMatrix) # apply that matrix to your newly created camera c4d.EventAdd() # inform cinema that something has happend, so it updates. if __name__=='__main__': main()
  11. ah, I get it. Hang on. ;)
  12. this is not really pythonic way to write a script :) Using callcommand will not get you very far in scripting. Try this. import c4d from c4d import gui #Welcome to the world of Python def main(): camera = c4d.BaseObject(c4d.Ocamera) # this creates the object in the memory, but does not add it to the scene tag = c4d.BaseTag(c4d.Ttargetexpression) # this creates the tag in memory null = c4d.BaseObject(c4d.Onull) # create the null in memory doc.InsertObject(camera) # insert the camera object in the scene doc.InsertObject(null) # insert the null camera.InsertTag(tag) # apply the tag to the camera tag[c4d.TARGETEXPRESSIONTAG_LINK] = null # set the target object in the tag to be the null c4d.EventAdd() # inform cinema that something has happend, so it updates. if __name__=='__main__': main()
  13. That's strange. It should work. Try with a .tiff file
  14. save the icon with the same name as the script and place it in the same folder as the script ;)
  15. Hahaha, no, it does not matter in which line you define the functions. :) But I would suggest using this as a script. Not in Xpresso, cause it will iterate every object in scene, every frame.
  16. this is the code in the node for everyone interested import c4d def main(): global result # sets a global output variable, cause the xpresso needs it :) result = state # sets the same output to the input state obj = doc.GetFirstObject() # this assigns the first object in the object manager to a variabale named "obj" while obj: # while there is an object returned if obj.GetType() == c4d.Osds: # if the object is a SDS object obj[c4d.ID_BASEOBJECT_GENERATOR_FLAG] = state # toggle it based on the null's object enabled's state obj = walker(obj) # keep checking all the objects in the scene. c4d.EventAdd() def walker(obj): if not obj: return elif obj.GetDown(): return obj.GetDown() while obj.GetUp() and not obj.GetNext(): obj = obj.GetUp() return obj.GetNext()
  17. well, if you are Ok with some Python - this a solution. But keep in mind that it will iterate over every object in the scene. It should be quite fast anyway :) sds xpresso python.c4d
  18. @Eterea you can ask anything man, just put it in different topic. I remember when py4d came out and there was no one to ask :) it was horrible
  19. The way I do it is not recommended :) But for monitoring only the ctrl alt shift, which is the most common case, it's quite easy to use.
  20. @jed That's the case if you want to confirm for a single key, or you should nest a couple of "if" statements if you want to check that shift and ctrl are pressed at the same time. That's cause "&" doesn't actually work as the "==" operator. It copies the bits that are at the same position and returns the result. so : shift = 001 (int 1) ctrl = 010 (int 2) alt = 100 (int 4) so if you press shift+ctrl the result is 011 (3), but 001 & 011 results to 001, which will be seen as if you were pressing only the shift key. That's cause my first 'if' condition is checking for the 'shift' key. If the first 'if' was checking for 'ctrl' it would be like: 010 & 011 = 010 , which would be interpreted as if you have pressed only 'ctrl'. A bit abstract and I'm not sure if I'm explaining it quite well, sorry for that :D in other words the "&" operator does not return True or False. It returns SOMENUMBER or 0. That's why I find it easier to read when using the integer value and the "==" operator. And for this example, that is aimed at general users or code beginners, I think using binary is not really necessary. Hope that helps at least a 'bit'
  21. here are some additions to the educational script :) @Eterea There actually is more simple way to transfer the PSR of the object @Hofmann Manuel Check out the part about holding "CTRL" import c4d from c4d import gui # Welcome to the world of Python # Created and shared by Kalugin here: # https://www.c4dcafe.com/ipb/forums/topic/104182-create-instances-from-selected-objects/ def main(): mod_key = getModKey() doc.StartUndo() # this generates an UNDO stack, every "AddUndo" between .StartUndo() and .EndUndo() will be "undoable" in a single "Ctrl+Z" objects = doc.GetActiveObjects(0) # this get's currently active objects in a list. The "0" parameter means that we don't want to select the children of the objects and we don't care about the oreder of the returned selection for obj in objects: # this iterates over the list of active objects. So for each object: instance = c4d.BaseObject(c4d.Oinstance) # create a new instance object instance.SetName(obj.GetName() + '_inst') # set it's name to the object's name + "_inst" # YOU CAN TRANSFER ALL OF THIS IN ONE LINE # instance.SetRelPos(obj.GetRelPos()) # set it's Relative Position to the object's Relative Position # instance.SetRelScale(obj.GetRelScale()) # set it's Relative Scale to the object's Relative Scale # instance.SetRelRot(obj.GetRelRot()) # set it's Relative Rotation to the object's Relative Rotation # LIKE THIS # instance.SetMl(obj.GetMl()) # this uses the matrix of the object directly. It contains all the information about the PSR of an object. instance[c4d.INSTANCEOBJECT_LINK] = obj # set the instance's source object instance.InsertAfter(obj) # insert the instance object in the object manager, right after the source object. You can use other options. Like .InsertBefore(obj), if you want it before the source object. doc.AddUndo(c4d.UNDOTYPE_NEW, instance) # this adds the insertion of our new instance to the undo stack. # here is an example how to use the modifier keys. In this case, as Hofmann Manuel asked - holding ctrl while executing the script will deselect the source objects and select the instances. if 'ctrl' in mod_key: # if you are holding CTRL while executing the script doc.AddUndo(c4d.UNDOTYPE_CHANGE, obj) # we add the deselection of the source object to the undo stack. Notice that different undo operations sometimes are called before the action and sometimes after that. Check the SDK. obj.DelBit(c4d.BIT_ACTIVE) # we delete the BIT (actually sets it to 0), that tells cinema if the object is selected or not instance.SetBit(c4d.BIT_ACTIVE) # and we set the BIT to 1 for the instance if 'shift' in mod_key: # here we test if shift is included in the combination, so this works with or without using other keys instance.SetMl(obj.GetMl()) # if shift was pressed, we transfer the object's matrix to the instance doc.EndUndo() # this ends the undo stack c4d.EventAdd() # we infrom C4D that something has occured, otherwise it will not refresh until you click something or do something else # some helper functions, this is really usefull for all kind of tasks, so I've decided to share it in this script :) def getModKey(): bc = c4d.BaseContainer() # we create a container object to hold the data returned from the GetInputState() if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.BFM_INPUT_CHANNEL, bc): # we check if the keyboard has any keys pressed and return the result to the bc if bc[c4d.BFM_INPUT_QUALIFIER] == c4d.QSHIFT: # the c4d.BFM_INPUT_QUALIFIER is a the place in the bc where the key pressed is stored, we check if the key pressed was shift return "shift" # if it was, we return that as a string. You can do it in different ways. I did it like this in this example to make it more readable if bc[c4d.BFM_INPUT_QUALIFIER] == (c4d.QSHIFT + c4d.QCTRL): return "shift+ctrl" if bc[c4d.BFM_INPUT_QUALIFIER] == (c4d.QSHIFT + c4d.QALT): return "shift+alt" if bc[c4d.BFM_INPUT_QUALIFIER] == (c4d.QSHIFT + c4d.QCTRL + c4d.QALT): return "shift+ctrl+alt" if bc[c4d.BFM_INPUT_QUALIFIER] == c4d.QCTRL: return 'ctrl' if bc[c4d.BFM_INPUT_QUALIFIER] == (c4d.QCTRL + c4d.QALT): return 'ctrl+alt' if bc[c4d.BFM_INPUT_QUALIFIER] == c4d.QALT: return 'alt' else: return '' # if non of the keys that we are checking for was pressed, we return an empty result if __name__=='__main__': main()
  22. @bezo Yeah, man, you are right. I usually do comment them, but this time I got lazy ;) FIXED
  23. a bit late but anyway :) import c4d from c4d import gui #Welcome to the world of Python def main(): doc.StartUndo() # this generates an UNDO stack, every "AddUndo" between .StartUndo() and .EndUndo() will be "undoable" in a single "Ctrl+Z" objects = doc.GetActiveObjects(0) # this get's currently active objects in a list. The "0" parameter means that we don't want to select the children of the objects and we don't care about the oreder of the returned selection for obj in objects: # this iterates over the list of active objects. So for each object: instance = c4d.BaseObject(c4d.Oinstance) # create a new instance object instance.SetName(obj.GetName() + '_instance') # set it's name to the object's name + "_instance" instance[c4d.INSTANCEOBJECT_LINK] = obj # set the instance's source object instance.InsertBefore(obj) # insert the instance object in the object manager, right before the source object. You can use other options. Like .InsertAfter(obj), if you want it after the source object. doc.AddUndo(c4d.UNDOTYPE_NEW, instance) # this adds the insertion of our new instance to the undo stack. doc.EndUndo() # this ends the undo stack c4d.EventAdd() # we infrom C4D that something has occured, otherwise it will not refresh until you click something or do something else if __name__=='__main__': main()
  24. i guess this could help a bit import c4d def main(): obj = doc.GetActiveObject() # gets the current active object parent = obj # stores the active object in a 'parent' variable, so it always stays the same if obj: # if there is a object selected children = [] # create an empty list to store children while obj: # while there is a object (the "walker" function will return None at some point and that will exit the while loop) obj = walker(parent, obj) # set the obj to the result of the walker function if obj: # if obj is not None children.append(obj) # append that object to the children list print children # print the list def walker(parent, obj): if not obj: return # if obj is None, the function returns None and breaks the while loop elif obj.GetDown(): # if there is a child of obj return obj.GetDown() # the walker function returns that child while obj.GetUp() and not obj.GetNext() and obj.GetUp() != parent: # if there is a parent of the obj and there isn't another object after the obj and the parent object is not the same object stored in "parent" obj = obj.GetUp() # it set's the current obj to that parent return obj.GetNext() # and return the object that's after that parent, not under, after :) if __name__=='__main__': main()
×
×
  • Create New...