Jump to content

kalugin

Cafe Oldtimer
  • Content Count

    293
  • Joined

  • Last visited

  • Days Won

    7

kalugin last won the day on October 20

kalugin had the most liked content!

Community Reputation

66 Noble Beginner

Profile Information

  • First Name
    Alexander
  • Last Name
    Kalugin
  • C4D Ver
    16 Studio
  • Location
    Ruse, Bulgaria
  • Interests
    3D Visuals, Coding, CNC Machining, Off-grid living.

Recent Profile Visitors

2,837 profile views
  1. kalugin

    Assign object to target

    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()
  2. kalugin

    Assign object to target

    null is created at 0,0,0. You didn't say that you want to create it somewhere else :)
  3. kalugin

    Assign object to target

    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()
  4. kalugin

    Assign object to target

    ah, I get it. Hang on. ;)
  5. kalugin

    Assign object to target

    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()
  6. kalugin

    Custom button for Python script

    That's strange. It should work. Try with a .tiff file
  7. kalugin

    Custom button for Python script

    save the icon with the same name as the script and place it in the same folder as the script ;)
  8. kalugin

    Edit multiple nodes / Access all SDS

    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.
  9. kalugin

    Edit multiple nodes / Access all SDS

    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()
  10. kalugin

    Edit multiple nodes / Access all SDS

    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
  11. @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
  12. 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.
  13. @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'
  14. 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()
  15. @bezo Yeah, man, you are right. I usually do comment them, but this time I got lazy ;) FIXED

×