def main():
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    doc.StartUndo()  # Start recording undos
    global hieararchy  # Access to global dictionary (hierarchy)
    hierarchy = BuildHierarchy()
    selection = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)
    keyMod = GetKeyMod()  # Get keymodifier

    if keyMod == "None":
        for obj in selection:  # Loop through selection
            Deselect(obj)  # Deselect selected object
            Select(FindChildren(obj, 0, True))  # Select chldren object(s)
    elif keyMod == "Shift":
        for obj in selection:  # Loop through selection
            Select(FindChildren(obj, 0, True))
    elif keyMod == "Ctrl":
        inp = int(gui.InputDialog('Child level', "2"))
        for obj in selection:  # Loop through selection
            Deselect(obj)  # Deselect selected object
            Select(FindChildren(obj, inp, True))
    elif keyMod == "Ctrl+Shift":
        inp = int(gui.InputDialog('Child level', "2"))
        for obj in selection:  # Loop through selection
            Select(FindChildren(obj, inp, True))
    elif keyMod == "Alt":
        inp = int(gui.InputDialog('Child level', "2"))
        for obj in selection:  # Loop through selection
            Select(FindChildren(obj, inp, False))
    elif keyMod == "Alt+Shift":
        inp = int(gui.InputDialog('Child level', "2"))
        for obj in selection:  # Loop through selection
            Select(FindChildren(obj, inp, False))

    doc.EndUndo()  # Stop recording undos
    c4d.EventAdd()  # Refresh Cinema 4D
Exemple #2
0
def CanvasSequence(coloverride):
    img = storage.LoadDialog() 
    if not img:
        return 'Canvas Cancelled.'
    else:
        path, filename = os.path.split(img)
        #gets directory and lists all images - helps calculate total frames.
        imgSeq = os.listdir(path)
        #gets length of frames
        frames = len(imgSeq)
        #user input framerate
        fps = gui.InputDialog('Framerate')
        #get filename
        fname, ext = filename.split('.')
        name = gui.InputDialog('Material Name')
        m = Material(img,coloverride)
        ms = materialShader(m,img,True,frames,fps,coloverride)
        p = ImagePlane(m,name,ms)
        if name in(None,'Material Name?'):
            m[c4d.ID_BASELIST_NAME] = fname
            p[c4d.ID_BASELIST_NAME] = fname
           
        else:
            m[c4d.ID_BASELIST_NAME] = name
            p[c4d.ID_BASELIST_NAME] = name
def SequenceTracks(keyMod):
    tracks = GetTracks()  # Get selected tracks
    prevTrack = tracks[0]  # Get the first selected track
    prevOut = prevTrack.GetCurve().GetEndTime()  # Get out time

    if keyMod == "None":
        gap = c4d.BaseTime(1.0 / doc.GetFps())
    elif keyMod == "Shift":
        inp = gui.InputDialog('Gap')  # Store user given value
        gap = c4d.BaseTime(1.0 / doc.GetFps() * float(inp))  # Gap
    elif keyMod == "Ctrl":
        tracks.reverse()
        gap = c4d.BaseTime(1.0 / doc.GetFps())
    elif keyMod == "Ctrl+Shift":
        tracks.reverse()
        inp = gui.InputDialog('Gap')  # Store user given value
        gap = c4d.BaseTime(1.0 / doc.GetFps() * float(inp))  # Gap

    for i in range(1, len(tracks)):  # Iterate through tracks
        curve = tracks[i].GetCurve()  # Get current curve
        startTime = curve.GetStartTime()
        endTime = curve.GetEndTime()
        sub = prevOut - (startTime - gap)  # Get time subtraction
        if sub.Get() < 0:  # If subtraction is negative
            sub = (startTime - gap) - prevOut  # New subtraction
            for i in range(0, sub.GetFrame(doc.GetFps())):
                MoveKeys(curve, -1)  # Move keys one frame to the left
        else:  # Otherwise
            for i in range(0, sub.GetFrame(doc.GetFps())):
                MoveKeys(curve, 1)  # Move keys one frame to the right
        prevOut = curve.GetEndTime()  # Get new out time
def main():
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    bd = doc.GetActiveBaseDraw()  # Get active basedraw
    bc = c4d.BaseContainer()  # Initialize base container
    path, fn = os.path.split(__file__)  # Get path of the script
    data = os.path.join(path, 'AR_ToggleTintedBorder.txt')  # data file path
    #try: # Try to execute following script
    f = open(data.decode('utf-8'))  # Open file for reading
    value = float(f.readline())  # Get value from data file
    f.close()  # Close file
    keyMod = GetKeyMod()  # Get keymodifier
    if keyMod == "Shift":
        userValue = gui.InputDialog('Value')  # Store user given value
        if userValue is not '':
            userValue = userValue.replace(
                ',', '.')  # Replace comma to dot, if found
            numbers = re.compile('\d+(?:\.\d+)?')  # Regular expression
            userValue = float(numbers.findall(userValue)
                              [0])  # Strip anything else but numbers
            if userValue > 1:  # If value is bigger than one
                value = userValue / 100.0  # Divide value by 100
            else:  # If value is not bigger than one
                value = userValue  # Set value to userValue
            f = open(data.decode('utf-8'), 'w')  # Open file for writing
            f.write(str(value))  # Write value to file
            f.close()  # Close file
            bd[c4d.
               BASEDRAW_DATA_TINTBORDER_OPACITY] = value  # Set opacity to custom
    elif keyMod == "None":
        if bd[c4d.
              BASEDRAW_DATA_TINTBORDER_OPACITY] == 0:  # If tinted border's opacity is 0
            bd[c4d.BASEDRAW_DATA_TINTBORDER_OPACITY] = value  # Set opacity
        else:  # If tinted border's opacity is not 0
            f = open(data.decode('utf-8'), 'w')  # Open file for writing
            f.write(str(bd[c4d.BASEDRAW_DATA_TINTBORDER_OPACITY])
                    )  # Write current value to file
            f.close()  # Close file
            bd[c4d.BASEDRAW_DATA_TINTBORDER_OPACITY] = 0  # Set opacity to 0
    elif keyMod == "Ctrl":
        bd[c4d.BASEDRAW_DATA_TINTBORDER] = not bd[
            c4d.BASEDRAW_DATA_TINTBORDER]  # Toggle 'Tinted Border' checkbox
    elif keyMod == "Alt":  # Change border color
        userColor = gui.InputDialog('Value',
                                    '#000000')  # Store user given value
        if userColor is not '':
            rgb = HexToRgb(userColor)
            color = c4d.Vector(
                float(rgb[0]) / 255,
                float(rgb[1]) / 255,
                float(rgb[2]) / 255)  # Convert rgb to c4d form
            bd[c4d.BASEDRAW_DATA_TINTBORDER_COLOR] = color  # Set border color

    #except: # If something went wrong
    #pass # Do nothing
    c4d.EventAdd()  # Refresh Cinema 4D
def SplineFromObjects(objects, keyMod):
    if keyMod == "None":
        pointPositions = CollectPositions(objects)
        pointCount = len(pointPositions)
        spline = CreateSpline(pointCount, pointPositions)
        InsertObject(spline)
        CenterAxis(spline)  # Center spline's axis

    if keyMod == "Alt":
        pointPositions = CollectPositions(
            doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN))
        pointCount = len(pointPositions)
        spline = CreateSpline(pointCount, pointPositions)
        InsertObject(spline)
        CenterAxis(spline)  # Center spline's axis

    if keyMod == "Shift":
        cnt = len(objects)  # Count of the objects
        for i in range(0, cnt - 1):  # Iterate through objects
            objA = objects[i]
            objB = objects[i + 1]
            posA = objA.GetMg().off
            posB = objB.GetMg().off
            spline = CreateSpline(2, [posA, posB])
            InsertObject(spline)
            CenterAxis(spline)  # Center spline's axis

    if keyMod == "Ctrl":
        subd = gui.InputDialog('Subdivide', "0")
        pointPositions = CollectPositions(objects)
        pointCount = len(pointPositions)
        spline = CreateSpline(pointCount, pointPositions)
        InsertObject(spline)
        CenterAxis(spline)  # Center spline's axis
        CreateDynamics(spline, objects, int(subd))  # Create spline dynamic

    if keyMod == "Ctrl+Shift":
        subd = gui.InputDialog('Subdivide', "0")
        cnt = len(objects)  # Count of the objects
        for i in range(0, cnt - 1):  # Iterate through objects
            objA = objects[i]
            objB = objects[i + 1]
            posA = objA.GetMg().off
            posB = objB.GetMg().off
            spline = CreateSpline(2, [posA, posB])
            InsertObject(spline)
            CenterAxis(spline)  # Center spline's axis
            CreateDynamics(spline, [objA, objB],
                           int(subd))  # Create spline dynamic
Exemple #6
0
def CanvasVideo(coloverride):
    img = storage.LoadDialog() 
    if not img:
        return 'Canvas Cancelled.'
    else:
        path, filename = os.path.split(img)
        #get filename
        fname, ext = filename.split('.')

        #load movie
        if not ext in ('mp4','avi'):
            gui.MessageDialog('file format .' + ext +'  not supported!')
        else:
            mov = c4d.bitmaps.MovieLoader()
            mov.Open(img)

            frame, fps = mov.GetInfo()
            name = gui.InputDialog('Material Name')
            m = Material(img,coloverride)
            ms = materialShader(m,img,True,frame,fps,coloverride)
            p = ImagePlane(m,name,ms)
            if name in(None,'Material Name?'):
                m[c4d.ID_BASELIST_NAME] = fname
                p[c4d.ID_BASELIST_NAME] = fname

            else:
                m[c4d.ID_BASELIST_NAME] = name
                p[c4d.ID_BASELIST_NAME] = name
def main():
    doc.StartUndo()  # Start recording undos
    try:  # Try to execute following script
        keyMod = GetKeyMod()  # Get keymodifier
        inp = 0
        if keyMod == "Shift":
            inp = int(gui.InputDialog('Step'))  # Store user given value
        DistributeKeys(keyMod, inp)  # Do the thing
    except:  # If something went wrong
        pass  # Do nothing
    doc.EndUndo()  # Stop recording undos
    c4d.EventAdd()  # Update Cinema 4D
def main():
    name = gui.InputDialog("Matte name", "") # Input dialog
    if name is None: return
    if name is "": return

    doc = c4d.documents.GetActiveDocument() # Get active document
    doc.StartUndo() # Start recording undos

    theList = [] # Collect all items for matte creation

    selection = doc.GetSelection() # Get active selection (objects and tags)

    for s in selection: # Loop through selected objects
        if not isinstance(s, c4d.BaseTag): # If object
            tags = s.GetTags() # Get object's tags
            for t in tags: # Loop through tags
                if isinstance(t, c4d.TextureTag): # If texture tag
                    mat = t[c4d.TEXTURETAG_MATERIAL] # Get material
                    m = checkRedshiftMaterial(mat)
                    theList.append(m)

        if isinstance(s, c4d.TextureTag): # If texture tag
            mat = s[c4d.TEXTURETAG_MATERIAL] # Get material
            m = checkRedshiftMaterial(mat)
            theList.append(m)

    materials = doc.GetMaterials() # Get materials
    for mat in materials: # Iterate through materials
        if mat.GetBit(c4d.BIT_ACTIVE): # If material is selected
            m = checkRedshiftMaterial(mat)
            theList.append(m)

    theList = [i for i in theList if i]  # Remove Nones
    finalList = [] # Init the final list for items
    names = [] # Init list for collecting material names
    for item in theList: # Iterate through the list
        if item.GetName() not in names:
            names.append(item.GetName())
            finalList.append(item)

    for item in finalList:
        renderdata = doc.GetActiveRenderData()
        vprs = redshift.FindAddVideoPost(renderdata, redshift.VPrsrenderer)
        if vprs is None:
            return
        rsnm = redshift.GetRSMaterialNodeMaster(item) # Get Redshift material node master
        AddMatte(rsnm, vprs, name) # Run the main function

    doc.EndUndo() # Stop recording undos

    c4d.EventAdd() # Refresh Cinema 4D
def main():
    fn = s.LoadDialog(c4d.FILESELECTTYPE_ANYTHING, "Select reference file",
                      c4d.FILESELECT_LOAD)
    if fn == None: return None
    res = g.InputDialog("Resolution", "1280x720")
    width = float(res.split("x")[0])
    height = float(res.split("x")[1])
    ren = doc.GetActiveRenderData()
    zpos = ren[c4d.RDATA_XRES_VIRTUAL]
    c4d.CallCommand(12544)  # Create new viewport
    bd = doc.GetActiveBaseDraw()
    cam = c4d.BaseObject(c4d.Ocamera)
    cam.SetName("REFERENCE_CAMERA")
    cam[c4d.CAMERAOBJECT_TARGETDISTANCE] = width
    cam[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2
    doc.InsertObject(cam)
    plane = c4d.BaseObject(c4d.Oplane)
    plane[c4d.ID_BASEOBJECT_VISIBILITY_RENDER] = 2
    plane.SetName("REFERENCE_PLANE")
    plane[c4d.PRIM_AXIS] = 5
    plane[c4d.PRIM_PLANE_SUBW] = 1
    plane[c4d.PRIM_PLANE_SUBH] = 1
    plane[c4d.PRIM_PLANE_WIDTH] = width
    plane[c4d.PRIM_PLANE_HEIGHT] = height
    plane[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_Z] = zpos
    plane.InsertUnder(cam)
    mat = c4d.BaseMaterial(c4d.Mmaterial)
    mat.SetName("REFERENCE_MATERIAL")
    mat[c4d.MATERIAL_USE_REFLECTION] = 0
    mat[c4d.MATERIAL_ANIMATEPREVIEW] = 1
    color = c4d.BaseShader(c4d.Xbitmap)
    color[c4d.BITMAPSHADER_FILENAME] = fn
    doc.ExecutePasses(None, 0, 1, 1, 0)
    c4d.CallButton(color, c4d.BITMAPSHADER_CALCULATE)
    mat[c4d.MATERIAL_COLOR_SHADER] = color
    mat.InsertShader(color)
    mat.Message(c4d.MSG_UPDATE)
    mat.Update(True, True)
    doc.InsertMaterial(mat)
    t = c4d.BaseTag(5616)
    plane.InsertTag(t)
    tag = plane.GetFirstTag()
    tag[c4d.TEXTURETAG_MATERIAL] = mat
    tag[c4d.TEXTURETAG_PROJECTION] = 6
    bd[c4d.BASEDRAW_DATA_TINTBORDER_OPACITY] = 1
    bd[c4d.BASEDRAW_DATA_CAMERA] = cam
    bd[c4d.BASEDRAW_TITLE] = "REFERENCE_VIEWPORT"
    cam[c4d.ID_BASEOBJECT_REL_POSITION, c4d.VECTOR_X] = 5000000
    c4d.EventAdd()
Exemple #10
0
def main():
    doc.StartUndo()
    s = doc.GetSelection()
    p = int(gui.InputDialog("Subd multiplier",0))    
    spline = c4d.SplineObject(len(s), c4d.SPLINETYPE_LINEAR)
    points = []        
    for x in s:
        pos = x.GetMg().off
        points.append(pos)
        x.DelBit(c4d.BIT_ACTIVE)
    spline.SetAllPoints(points)
    doc.InsertObject(spline)
    doc.AddUndo(c4d.UNDOTYPE_NEW, spline)    
    spline.SetBit(c4d.BIT_ACTIVE)
    for i in xrange(0, p):
        c4d.CallCommand(14047)
    c4d.EventAdd()
    doc.EndUndo()
Exemple #11
0
def CanvasImage(coloverride):
     img = storage.LoadDialog() 
     if not img:
        return 'Canvas Cancelled.'
     else:
        path, filename = os.path.split(img)
        #get filename
        fname, ext = filename.split('.')
        name = gui.InputDialog('Material Name')
        m = Material(img,coloverride)
        ms = materialShader(m,img,False,0,0,coloverride)
        p = ImagePlane(m,name,ms)
        if name in(None,'Material Name?'):
            m[c4d.ID_BASELIST_NAME] = fname
            p[c4d.ID_BASELIST_NAME] = fname
           
        else:
            m[c4d.ID_BASELIST_NAME] = name
            p[c4d.ID_BASELIST_NAME] = name
def MoGraphSelectionFromRange(obj):
    #try:
    tag = obj.GetLastTag()  # Get last tag of object
    tags = obj.GetTags()  # Get object's tags
    md = mo.GeGetMoData(obj)  # Get MoGraph data
    cnt = md.GetCount()  # Get clone count
    prefix = "ms"  # Prefix for selection tag
    sep = "_"  # Separator for selection tag
    p = 0  # Initialize iteration variable
    userInput = g.InputDialog("Selected IDs for " + obj.GetName(),
                              "")  # User input dialog
    baseList = userInput.split(",")  # Split user input to list
    add = []  # Initialize empty list
    finalList = []  # Initialize empty list
    for x in baseList:  # Loop through list items
        rng = x.split("-")  # Split range value (e.g. 5-15)
        if len(rng) > 1:
            for i in xrange(int(rng[0]), int(rng[1]) + 1):
                add.append(i)
    fullList = baseList + add
    for f in fullList:
        if type(f) is int:
            finalList.append(f)
        if type(f) is not int:
            if f.find("-") is -1:
                finalList.append(f)
    for k in reversed(tags):  # Loop through tags
        if k.GetName().split("_")[0] == prefix:
            p = p + 1  # Increase iteration
    t = c4d.BaseTag(1021338)  # Initialize MoGraph Selection tag
    t[c4d.ID_BASELIST_NAME] = prefix + sep + str(p)  # Set tag name
    s = c4d.BaseSelect()  # Initialize BaseSelect
    for f in finalList:  # Loop through list
        s.Select(int(f))  # Select items
    obj.InsertTag(t)  # Insert tag to object
    doc.AddUndo(c4d.UNDOTYPE_NEW, t)  # Add undo command for inserting new tag
    mo.GeSetMoDataSelection(t, s)  # Set MoGraph selection
def makeSpline():
    selo = doc.GetActiveObjects(0)
    points = []
    for o in selo:
        spline = c4d.SplineObject(2, c4d.SPLINETYPE_LINEAR)
        pos = o.GetMg().off
        points.append(pos)
    p = int(gui.InputDialog("Subd multiplier",4))
    
    for x in selo:
        x.DelBit(c4d.BIT_ACTIVE)
        
    spline.SetAllPoints(points)
    doc.InsertObject(spline)
    
    doc.AddUndo(c4d.UNDOTYPE_NEW, spline)
    spline.SetBit(c4d.BIT_ACTIVE)
        
    # subdivide spline
    for i in xrange(0, p):
        c4d.CallCommand(14047)
    c4d.EventAdd()
    
    return spline
Exemple #14
0
def popup( title='', msg='', type='ok', defaultInput='', pyside=False, _list=[], selNum=0, winPrnt=None ) :
    'Attempts to build a simple dialog window in either native application calls, or PySide'
    app=F.get_app()
    userInput=''
    
    #  Create PySide window :
    if pyside :
        try :
            if type=='comboBox' :
                userInput, ok=QtGui.QInputDialog.getItem( winPrnt, title, msg, _list, 0, False )
                if not ok :
                    userInput=None
        except :
            P.error( 'Sorry, problem loading the dialog.' )
    
    # Cinesync Window :        
    elif app == 'Cinesync':
        try:
            if type == 'input' or type == 'okCancel':
                userInput, ok = QtGui.QInputDialog.getText(winPrnt, title, msg, QtGui.QLineEdit.Normal, defaultInput)
                if not ok:
                    userInput = None

        except Exception as err:
            P.error('Error with dialog: %s' % str(err))
    
    #  Maya Window :
    elif app=='Maya' :
        import maya.cmds as mc
        if type=='ok' :
            userInput=mc.confirmDialog( title=title, message=msg, button=['OK'], \
                defaultButton='OK' )
        elif type=='okCancel' :
            userInput=mc.confirmDialog( title=title, message=msg, button=['OK', 'Cancel'], \
                defaultButton='OK', cancelButton='Cancel', dismissString='Cancel' )
        elif type=='input' :
            userInput=mc.promptDialog( title=title, message=msg, text=defaultInput, \
                button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel' )
            if userInput=='OK' :
                userInput=str(mc.promptDialog( query=True, text=True ))
            else :
                userInput=''
    
    #  Nuke Window :
    elif app=='Nuke' :
        import nuke
        if type=='ok' :
            userInput=nuke.message( msg )
        elif type=='okCancel' :
            userInput=nuke.ask( msg )
            if userInput :
                userInput='OK'
            else :
                userInput='Cancel'
        elif type=='input' :
            userInput=nuke.getInput( msg, defaultInput )
    
    #  Hiero Window :
    elif app=='Hiero' :
        import hiero.ui
        from hiero.core import log
        if type=='ok' :
            dialog=QtGui.QMessageBox.information( hiero.ui.mainWindow(), title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( hiero.ui.mainWindow(), title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            dialog=QtGui.QInputDialog.getText( QtGui.QInputDialog(), title, msg, \
                QtGui.QLineEdit.Normal )
            if dialog[1] :
                userInput=dialog[0]
            else :
                userInput=None
    
    #  C4D Window :
    elif app=='C4D' :
        import c4d
        from c4d import gui
        if type=='ok' :
            userInput=gui.MessageDialog( msg )
        elif type=='okCancel' :
            userInput=gui.QuestionDialog( text=msg )
            if userInput : userInput='OK'
        elif type=='input' :
            userInput=gui.InputDialog( msg )
    
    #  3dsMax :
    elif app=='3dsMax' :
        import MaxPlus
        #maxWin=MaxPlus.Win32_GetMAXHWnd()

        if type=='ok' :
            dialog=QtGui.QMessageBox.information( None, title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( None, title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            dialog=QtGui.QInputDialog.getText( QtGui.QInputDialog(), title, msg, \
                QtGui.QLineEdit.Normal )
            if dialog[1] :
                userInput=dialog[0]
            else :
                userInput=None

    #  Houdini :
    elif app=='Houdini' :
        import hou
        if type=='ok' :
            dialog=QtGui.QMessageBox.information( None, title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( None, title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            inputFont = QtGui2.QFont()
            inputFont.setFamily("Ariel")
            inputFont.setPointSize(20)
            inputDialog = QtGui.QInputDialog(None)
            inputDialog.setStyleSheet( "* {background-color: #333333; color: white;}" );
            inputDialog.setInputMode(QtGui.QInputDialog.TextInput)
            inputDialog.setWindowTitle(title)
            inputDialog.setLabelText(msg)
            inputDialog.setFont(inputFont)
            ok = inputDialog.exec_()
            if(ok):
                userInput = inputDialog.textValue()
            else :
                userInput = None

    #  Flame :
    elif app=='Flame' :
        if type=='ok' :
            dialog=QtGui.QMessageBox.information( None, title, msg, \
                QtGui.QMessageBox.Ok)
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
        elif type=='okCancel' :
            dialog=QtGui.QMessageBox.question( None, title, msg, \
                QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Ok )
            if dialog==QtGui.QMessageBox.Ok :
                userInput='OK'
            elif dialog==QtGui.QMessageBox.Cancel :
                userInput='Cancel'
        elif type=='input' :
            dialog=QtGui.QInputDialog.getText( QtGui.QInputDialog(), title, msg, \
                QtGui.QLineEdit.Normal )
            if dialog[1] :
                userInput=dialog[0]
            else :
                userInput=None

    #P.info('Returning PopUP INFO: %s' % userInput)
    return userInput
Exemple #15
0
            newTag = c4d.BaseTag(c4d.Tphong)
            extrude.InsertTag(newTag)
            doc.AddUndo(c4d.UNDOTYPE_NEW, newTag)

            extrude[c4d.ID_BASELIST_NAME] = 'splineExtrude ' + str(count)
            extrude[c4d.EXTRUDEOBJECT_MOVE] = c4d.Vector(0, 0, strength)
            extrude[c4d.ID_BASEOBJECT_REL_POSITION] = i[
                c4d.ID_BASEOBJECT_REL_POSITION]
            extrude[c4d.ID_BASEOBJECT_REL_SCALE] = i[
                c4d.ID_BASEOBJECT_REL_SCALE]
            extrude[c4d.ID_BASEOBJECT_REL_ROTATION] = i[
                c4d.ID_BASEOBJECT_REL_ROTATION]
            if parent != None:
                extrude.InsertUnder(parent)
            i.InsertUnder(extrude)
            i[c4d.ID_BASEOBJECT_REL_POSITION] = c4d.Vector(0, 0, 0)
            i[c4d.ID_BASEOBJECT_REL_SCALE] = c4d.Vector(1, 1, 1)
            i[c4d.ID_BASEOBJECT_REL_ROTATION] = c4d.Vector(0, 0, 0)
            count = count + 1


userInput = gui.InputDialog('strength', '5')
strength = float(userInput)

extrudeSplines()

doc.EndUndo()  #undo

c4d.EventAdd()
def main():
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    doc.StartUndo()  # Start recording undos
    keyMod = GetKeyMod()  # Get keymodifier
    editorMode = doc.GetMode()  # Get editor's active mode
    selection = doc.GetActiveObjects(
        c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)  # Get active objects
    cnt = len(selection)  # Count of selected objects

    # Edge selection
    if editorMode == c4d.Medges:
        edgeToSpline = c4d.MCOMMAND_EDGE_TO_SPLINE  # Mcommand 'Edge To Spline'
        modeEdgeSel = c4d.MODELINGCOMMANDMODE_EDGESELECTION  # Modeling command mode 'Edge Selection'
        createUndo = c4d.MODELINGCOMMANDFLAGS_CREATEUNDO  # Modeling command flag 'Create undo'
        bc = c4d.BaseContainer()  # Initialize base container
        u.SendModelingCommand(
            edgeToSpline, selection, modeEdgeSel, bc, doc,
            createUndo)  # Send modeling command 'Edge To Spline'

        obj = selection[0]
        spline = obj.GetDown()
        spline.InsertBefore(obj)
        spline.SetMg(obj.GetMg())
        CenterAxis(spline)

        doc.AddUndo(c4d.UNDOTYPE_BITS,
                    selection[0])  # Add undo command for changing bits
        selection[0].DelBit(c4d.BIT_ACTIVE)  # Deselect object
        doc.AddUndo(c4d.UNDOTYPE_BITS, spline)
        spline.SetBit(c4d.BIT_ACTIVE)
        doc.SetMode(c4d.Mmodel)

    # Object selection
    else:

        # No active objects
        if cnt == 0:
            if keyMod == "None":
                spline = CreateSpline(2, [
                    c4d.Vector(0, 0, 0),
                    c4d.Vector(0, 0, 100),
                ])
                InsertObject(spline)
            if keyMod == "Shift":
                spline = CreateSpline(2, [
                    c4d.Vector(0, 0, 0),
                    c4d.Vector(0, 100, 0),
                ])
                InsertObject(spline)
            if keyMod == "Ctrl":
                spline = CreateSpline(2, [
                    c4d.Vector(0, 0, 0),
                    c4d.Vector(100, 0, 0),
                ])
                InsertObject(spline)

        # Only one selected object
        elif cnt == 1:
            if selection[0].GetType() == 5101:  # If spline object
                subd = gui.InputDialog('Subdivide', "0")
                if keyMod == "None":
                    controllers = CreateControls(selection[0], "Ends")
                elif keyMod == "Shift":
                    controllers = CreateControls(selection[0], "All")
                CreateDynamics(selection[0], controllers, int(subd))
                doc.AddUndo(c4d.UNDOTYPE_BITS,
                            selection[0])  # Add undo command for changing bits
                selection[0].DelBit(c4d.BIT_ACTIVE)  # Deselect object

        # Multiple selected objects
        else:
            # If spline object
            if selection[0].GetType() == 5101:
                subd = gui.InputDialog('Subdivide', "0")
                for s in selection:
                    if keyMod == "None":
                        controllers = CreateControls(s, "Ends")
                    elif keyMod == "Shift":
                        controllers = CreateControls(s, "All")
                    CreateDynamics(s, controllers, int(subd))
                    doc.AddUndo(c4d.UNDOTYPE_BITS,
                                s)  # Add undo command for changing bits

            # No spline object
            else:
                if keyMod == "Alt+Shift" or keyMod == "Alt+Ctrl":
                    TracerFromObjects(selection, keyMod)
                else:
                    SplineFromObjects(selection, keyMod)

            # Deselect old selection
            for s in selection:  # Iterate through selection
                doc.AddUndo(c4d.UNDOTYPE_BITS,
                            s)  # Add undo command for changing bits
                s.DelBit(c4d.BIT_ACTIVE)  # Deselect object

    doc.EndUndo()  # Stop recording undos
    c4d.EventAdd()  # Refresh Cinema 4D
Exemple #17
0
def MoGraphSelectionFromRange(obj, keyMod):
    #try:
    userInput = g.InputDialog("Selected IDs for " + obj.GetName(),
                              "")  # User input dialog
    if userInput == "": return
    baseList = userInput.split(",")  # Split user input to list
    add = []  # Initialize empty list
    finalList = []  # Initialize empty list
    for x in baseList:  # Loop through list items
        rng = x.split("-")  # Split range value (e.g. 5-15)
        if len(rng) > 1:
            for i in xrange(int(rng[0]), int(rng[1]) + 1):
                add.append(i)
    fullList = baseList + add
    for f in fullList:
        if type(f) is int:
            finalList.append(f)
        if type(f) is not int:
            if f.find("-") is -1:
                finalList.append(f)

    if keyMod == "None":
        tags = obj.GetTags()  # Get object's tags
        prefix = "ms"  # Prefix for selection tag
        sep = "_"  # Separator for selection tag
        msNums = []
        for k in tags:  # Loop through tags
            if k.GetName().split("_")[0] == prefix:
                msNums.append(int(k.GetName().split("_")[1]))
        t = c4d.BaseTag(1021338)  # Initialize MoGraph Selection tag
        if len(msNums) != 0:
            num = max(msNums) + 1
        else:
            num = 0
        t[c4d.ID_BASELIST_NAME] = prefix + sep + str(num)  # Set tag name
        s = c4d.BaseSelect()  # Initialize BaseSelect
        for f in finalList:  # Loop through list
            s.Select(int(f))  # Select items
        obj.InsertTag(t, obj.GetLastTag())  # Insert tag to object
        doc.AddUndo(c4d.UNDOTYPE_NEW,
                    t)  # Add undo command for inserting new tag
        mo.GeSetMoDataSelection(t, s)  # Set MoGraph selection

    elif keyMod == "Shift":
        prefix = "ms"  # Prefix for selection tag
        sep = "_"  # Separator for selection tag
        msNums = []
        for i, f in enumerate(finalList):  # Loop through list
            tags = obj.GetTags()  # Get object's tags
            #for k in reversed(tags): # Loop through tags
            for k in tags:  # Loop through tags
                if k.GetName().split("_")[0] == prefix:
                    msNums.append(int(k.GetName().split("_")[1]))
            t = c4d.BaseTag(1021338)  # Initialize MoGraph Selection tag
            if len(msNums) != 0:
                num = max(msNums) + 1
            else:
                num = 0
            t[c4d.ID_BASELIST_NAME] = prefix + sep + str(num)  # Set tag name
            s = c4d.BaseSelect()  # Initialize BaseSelect
            s.Select(int(f))  # Select items
            obj.InsertTag(t, obj.GetLastTag())  # Insert tag to object

            doc.AddUndo(c4d.UNDOTYPE_NEW,
                        t)  # Add undo command for inserting new tag
            mo.GeSetMoDataSelection(t, s)  # Set MoGraph selection
Exemple #18
0
def main():
    #load image from file loaction
    img = storage.LoadDialog() 
    if not img:
        return 'Canvas Cancelled.'
    else:
        path, filename = os.path.split(img)
        #get filename
        fname, ext = filename.split('.')

        #load movie
        if not ext in ('mp4','avi'):
            gui.MessageDialog('file format .' + ext +'  not supported!')
        else:
            mov = c4d.bitmaps.MovieLoader()
            mov.Open(img)

            frame, fps = mov.GetInfo()
            

            #create material
            mat = c4d.BaseMaterial(5703)   
            msg = gui.InputDialog('Material Name')
            mat[c4d.MATERIAL_USE_COLOR] = False
            mat[c4d.MATERIAL_USE_LUMINANCE] = True
            mat[c4d.MATERIAL_USE_REFLECTION] = False
            mat[c4d.MATERIAL_PREVIEWSIZE] = + 12
            mat[c4d.MATERIAL_ANIMATEPREVIEW] = True
            doc.StartUndo()
            doc.InsertMaterial(mat)    


            #create shader & add movie file
            mov_texture = c4d.BaseList2D(c4d.Xbitmap)    
            mov_texture[c4d.BITMAPSHADER_FILENAME] = img
            mov_texture[c4d.BITMAPSHADER_TIMING_TO] = frame
            mov_texture[c4d.BITMAPSHADER_TIMING_FPS] = fps     
            mat[c4d.MATERIAL_LUMINANCE_SHADER]= mov_texture        
            mat.InsertShader(mov_texture)
            
            #load bitmap from movie
            bm = c4d.bitmaps.BaseBitmap()
            bm.InitWith(img)
            getsize = bm.GetSize()
            x = getsize[0]
            y = getsize[1]
            
            alphaCheck = bm.GetChannelCount()

            # check if image has alpha channel
            if alphaCheck > 0:
                # Create alpha shader
                alpha_texture = c4d.BaseList2D(c4d.Xbitmap) 
                alpha_texture[c4d.BITMAPSHADER_FILENAME] = img  
                mat[c4d.MATERIAL_USE_ALPHA] = True    
                mat[c4d.MATERIAL_ALPHA_SHADER]= alpha_texture        
                mat.InsertShader(alpha_texture)
                doc.AddUndo(c4d.UNDOTYPE_NEW, alpha_texture)
            else:
                pass

            # create plane
            plane = c4d.BaseObject(5168)
            plane[c4d.PRIM_PLANE_SUBW] = 1
            plane[c4d.PRIM_PLANE_SUBH] = 1
            plane[c4d.PRIM_PLANE_WIDTH] = x
            plane[c4d.PRIM_PLANE_HEIGHT] = y
            doc.InsertObject(plane)
            # assign texture tag to plane
            tag = plane.MakeTag(c4d.Ttexture)
            tag[c4d.TEXTURETAG_PROJECTION] = 6
            tag[c4d.TEXTURETAG_MATERIAL]= mat
            
            # edit name
            if msg in(None,'Material Name?'):
                mat[c4d.ID_BASELIST_NAME] = fname
                plane[c4d.ID_BASELIST_NAME] = fname
            else:
                mat[c4d.ID_BASELIST_NAME] = msg
                plane[c4d.ID_BASELIST_NAME] = msg
            
            # update undos
            doc.AddUndo(c4d.UNDOTYPE_NEW, plane)
            doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
            doc.AddUndo(c4d.UNDOTYPE_NEW, mov_texture)
            doc.EndUndo()
            # add to file
            c4d.EventAdd()
Exemple #19
0
def main():
    #get polygon object

    polyObject = doc.GetActiveObject()
    if polyObject is None:
        return

    if not polyObject.IsInstanceOf(c4d.Opolygon):
        return

    # settings for PolygonReduction.PreProcess()
    settings = c4d.BaseContainer()
    settings[c4d.POLYREDUXOBJECT_PRESERVE_3D_BOUNDARY] = True
    settings[c4d.POLYREDUXOBJECT_PRESERVE_UV_BOUNDARY] = True

    # data for PolygonReduction.PreProcess()
    data = {}
    data['_op'] = polyObject
    data['_doc'] = doc
    data['_settings'] = settings
    data['_thread'] = None  # synchronous pre-processing and reduction

    # create PolygonReduction object
    polyReduction = utils.PolygonReduction()
    if polyReduction is None:
        return

    # pre process
    if not polyReduction.PreProcess(data):
        return

    # ask for number of vertex level
    while True:
        input = gui.InputDialog("Enter number of vertex level:")
        if input == "":
            # operation was cancelled
            polyObject.Message(c4d.MSG_UPDATE)
            c4d.EventAdd()
            return
        # try to convert to integer
        try:
            vertexLevel = int(input)
            break
        except ValueError:
            gui.MessageDialog("Please enter a number.")

    # check entered number of vertex level is valid
    if vertexLevel < polyReduction.GetMinVertexLevel():
        return
    if vertexLevel > polyReduction.GetMaxVertexLevel():
        return

    # set vertex level
    polyReduction.SetVertexLevel(vertexLevel)

    # get number of vertex level after reduction
    realVertexResult = polyReduction.GetVertexLevel()
    print "Vertex Result: " + str(realVertexResult)

    # update original PolygonObject
    polyObject.Message(c4d.MSG_UPDATE)
    c4d.EventAdd()
Exemple #20
0
def main():

    # Initialize colors ----------------------
    gradients = [
        [c4d.Vector(0.2196, 0.2196, 0.2196),
         c4d.Vector(0.298, 0.298, 0.298)],  # 0 Cinema 4D
        [c4d.Vector(0.741, 0.773, 0.776),
         c4d.Vector(0.4, 0.494, 0.545)],  # 1 Houdini
        [c4d.Vector(0.082, 0.086, 0.09),
         c4d.Vector(0.525, 0.608, 0.69)],  # 2 Maya
        [c4d.Vector(0.357, 0.357, 0.357),
         c4d.Vector(0.525, 0.525, 0.525)],  # 3 Legacy
        [c4d.Vector(0.08, 0.08, 0.08),
         c4d.Vector(0, 0, 0)]
    ]  # 4 Dark

    presets = {
        'cinema 4d': gradients[0],
        'default': gradients[0],
        'new': gradients[0],
        'c4d': gradients[0],
        'houdini': gradients[1],
        'hou': gradients[1],
        'maya': gradients[2],
        'legacy': gradients[3],
        'old': gradients[3],
        'dark': gradients[4]
    }

    keyMod = GetKeyMod()  # Get keymodifier

    # Action
    if keyMod == "None":  # If there is no keymodifier

        # Get current color
        cg1 = c4d.GetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1)
        cg2 = c4d.GetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2)

        # Temporary change
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                         presets['houdini'][0])
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                         presets['houdini'][1])

        spot = None
        last = False
        for i, grad in enumerate(gradients):  # Iterate through colors
            if (cg1 == grad[0]) and (cg2 == grad[1]):
                spot = i
                if i == len(gradients) - 1:
                    last = True
        if spot == None:
            c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                             gradients[0][0])
            c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                             gradients[0][1])
        else:
            if last == False:
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                                 gradients[spot + 1][0])
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                                 gradients[spot + 1][1])
            if last == True:
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                                 gradients[0][0])
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                                 gradients[0][1])
        pass

    # If shift pressed
    if keyMod == "Shift":  # New Cinema 4D (Default gradient)
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                         presets['default'][0])
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                         presets['default'][1])

    # If control pressed
    if keyMod == "Ctrl":  # Dark theme
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1, presets['dark'][0])
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2, presets['dark'][1])

    # If alt pressed, cycle through user gradients
    if keyMod == "Alt":
        path, fn = os.path.split(__file__)  # Get path of the script
        data = os.path.join(path, 'AR_ViewportGradients.txt')  # data file path
        userGradients = []
        f = open(data.decode("utf-8"))  # Open the file for reading
        for line in f:  # Iterate through every row
            line = line.split(",")  # Split by comma
            rgbA = HexToRgb(str(line[0]))  # Get first rgb
            rgbB = HexToRgb(str(line[1]))  # Get last rgb
            colorA = c4d.Vector(
                float(rgbA[0]) / 255,
                float(rgbA[1]) / 255,
                float(rgbA[2]) / 255)  # Convert rgb to c4d form
            colorB = c4d.Vector(
                float(rgbB[0]) / 255,
                float(rgbB[1]) / 255,
                float(rgbB[2]) / 255)
            userGradients.append([colorA, colorB])  # Add colors to the list

        # Figure out current spot, if using user gradients
        cg1 = c4d.GetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1)
        cg2 = c4d.GetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2)
        spot = None
        last = False
        for i, grad in enumerate(userGradients):  # Iterate through colors
            if (cg1 == grad[0]) and (cg2 == grad[1]):
                spot = i
                if i == len(userGradients) - 1:
                    last = True
        if spot == None:
            c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                             userGradients[0][0])
            c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                             userGradients[0][1])
        else:
            if last == False:
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                                 userGradients[spot + 1][0])
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                                 userGradients[spot + 1][1])
            if last == True:
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1,
                                 userGradients[0][0])
                c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2,
                                 userGradients[0][1])
        f.close()  # Close the file
        pass

    # If alt + control + shift pressed, open dat-file
    if keyMod == "Alt+Ctrl+Shift":
        path, fn = os.path.split(__file__)  # Get path of the script
        data = os.path.join(path, 'AR_ViewportGradients.txt')  # data file path
        storage.GeExecuteFile(
            data)  # Open data file for editing user gradients
        pass

    # If alt + control + shift pressed, open dat-file
    if keyMod == "Alt+Ctrl":
        name = gui.InputDialog("Prestet name", "").lower()  # Input dialog
        if name is None: return
        if name is "": return

        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD1, presets[name][0])
        c4d.SetViewColor(c4d.VIEWCOLOR_C4DBACKGROUND_GRAD2, presets[name][1])
        pass

    c4d.EventAdd()  # Update
Exemple #21
0
def main():
    #load image from file loaction
    img = storage.LoadDialog()
    if not img:
        return 'Canvas Cancelled.'
    else:
        path, filename = os.path.split(img)
        #gets directory and lists all images - helps calculate total frames.
        imgSeq = os.listdir(path)
        #gets length of frames
        frames = len(imgSeq)
        #user input framerate
        fps = gui.InputDialog('Framerate')
        #get filename
        fname, ext = filename.split('.')

        #create material
        mat = c4d.BaseMaterial(5703)
        msg = gui.InputDialog('Material Name')
        mat[c4d.MATERIAL_USE_COLOR] = False
        mat[c4d.MATERIAL_USE_LUMINANCE] = True
        mat[c4d.MATERIAL_USE_ALPHA] = True
        mat[c4d.MATERIAL_USE_REFLECTION] = False
        mat[c4d.MATERIAL_PREVIEWSIZE] = +12
        mat[c4d.MATERIAL_ANIMATEPREVIEW] = True
        doc.StartUndo()
        doc.InsertMaterial(mat)

        shdr_texture = c4d.BaseList2D(c4d.Xbitmap)
        shdr_texture[c4d.BITMAPSHADER_FILENAME] = img
        mat[c4d.MATERIAL_LUMINANCE_SHADER] = shdr_texture
        shdr_texture[c4d.BITMAPSHADER_TIMING_TO] = frames
        shdr_texture[c4d.BITMAPSHADER_TIMING_FPS] = float(fps)
        mat.InsertShader(shdr_texture)

        #create bitmap
        bm = c4d.bitmaps.BaseBitmap()
        bm.InitWith(img)
        getsize = bm.GetSize()
        x = getsize[0]
        y = getsize[1]

        alphaCheck = bm.GetChannelCount()

        ### check if image has alpha channel
        if alphaCheck > 0:
            ### Create alpha shader
            alpha_texture = c4d.BaseList2D(c4d.Xbitmap)
            alpha_texture[c4d.BITMAPSHADER_FILENAME] = img
            alpha_texture[c4d.BITMAPSHADER_TIMING_TO] = frames
            alpha_texture[c4d.BITMAPSHADER_TIMING_FPS] = float(fps)
            mat[c4d.MATERIAL_ALPHA_SHADER] = alpha_texture
            mat.InsertShader(alpha_texture)
            doc.AddUndo(c4d.UNDOTYPE_NEW, alpha_texture)
        else:
            pass

        ### create plane
        plane = c4d.BaseObject(5168)
        plane[c4d.PRIM_PLANE_SUBW] = 1
        plane[c4d.PRIM_PLANE_SUBH] = 1
        plane[c4d.PRIM_PLANE_WIDTH] = x
        plane[c4d.PRIM_PLANE_HEIGHT] = y
        doc.InsertObject(plane)
        ##assign texture tag to plane
        tag = plane.MakeTag(c4d.Ttexture)
        tag[c4d.TEXTURETAG_PROJECTION] = 6
        tag[c4d.TEXTURETAG_MATERIAL] = mat

        ## edit name
        if msg == None:
            mat[c4d.ID_BASELIST_NAME] = fname
            plane[c4d.ID_BASELIST_NAME] = fname
        else:
            mat[c4d.ID_BASELIST_NAME] = msg
            plane[c4d.ID_BASELIST_NAME] = msg

        ##update undos
        doc.AddUndo(c4d.UNDOTYPE_NEW, plane)
        doc.AddUndo(c4d.UNDOTYPE_NEW, mat)
        doc.AddUndo(c4d.UNDOTYPE_NEW, shdr_texture)
        doc.EndUndo()
        ##add to file
        c4d.EventAdd()
import c4d
from c4d import gui

#get selected objects and check if the list is larger than 1
allObjs = doc.GetActiveObjects(2)
if len(allObjs) < 2:
    gui.MessageDialog('Select at least 2 objects!')
else:
    #make lists with objects
    headObj = allObjs[0]
    childObjs = allObjs[1:]

    #get range from user
    maxFrame = doc.GetMaxTime().GetFrame(doc.GetFps())
    txtInput = gui.InputDialog('range', '0-' + str(maxFrame))
    keyFrameRangeStart = int(txtInput.split('-')[0])
    keyFrameRangeEnd = int(txtInput.split('-')[1])

    #calculate new keyframes
    for i in range(keyFrameRangeStart, keyFrameRangeEnd + 1):
        #set playhead
        doc.SetTime(c4d.BaseTime(i, doc.GetFps()))

        #get head tracks
        hxTrack = headObj.FindCTrack(
            c4d.DescID(
                c4d.DescLevel(c4d.ID_BASEOBJECT_POSITION, c4d.DTYPE_VECTOR, 0),
                c4d.DescLevel(c4d.VECTOR_X, c4d.DTYPE_REAL, 0)))
        hyTrack = headObj.FindCTrack(
            c4d.DescID(