コード例 #1
0
def main():
    oplist = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_SELECTIONORDER)

    #Quit early if nothing is selected
    if len(oplist) == 0:
        print 'Please apply the "bend chain" script to a Bend object.'
        gui.MessageDialog(
            'Please apply the "bend chain" script to a Bend object.')
        return None

    oplist = filterlist(oplist, c4d.Obend)

    #apply the rig to selected bend objects
    rigcount = 0
    existingcount = 0
    doc.StartUndo()
    for index, op in enumerate(oplist):
        applytag = True

        #Test for existing rig - if there is one, don't add the tag again
        #The test looks for any Python tag starting with the teststring ("#bendchain tagcode")
        pythontags = getTagsByType(op.GetTags(), c4d.Tpython)
        teststring = "#bendchain tagcode"

        rigtag = None

        for tag in pythontags:
            if tag[c4d.TPYTHON_CODE][:len(teststring)] == teststring:
                applytag = False
                existingcount += 1
                rigtag = tag
                break

        #If there isn't already a rig, create one
        if applytag:
            rigtag = new_rig(op)
            rigcount += 1

        #currently the rig only works if 'Keep Y-Axis Length' is on, so we set that here
        op[c4d.BENDOBJECT_KEEPYAXIS] = True

        #If this isn't the first selected bend, set the 'Previous Bend' user data
        #to the bend that was selected before this one - you can quickly create a
        #chain of linked bends this way
        if (index > 0):
            rigtag[c4d.ID_USERDATA, 1] = oplist[index - 1]

    doc.EndUndo()
    if rigcount == 0 and existingcount == 0:
        print 'Please apply the "bend chain" script to a Bend object.'
        gui.MessageDialog(
            'Please apply the "bend chain" script to a Bend object.')
        return None
    else:
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        msg = "Bend chain rig added " + str(rigcount) + " times!"
        if existingcount > 0:
            msg += " Rig already exists on " + str(
                existingcount) + " bend objects."
        print msg
コード例 #2
0
def main():
    # BaseDraw
    bd = doc.GetActiveBaseDraw()

    # The camera view
    view = bd.GetSafeFrame()

    # Check if poly object
    if op is None:
        gui.MessageDialog('Please select an objcet')
        return
    if op.GetType() != c4d.Opolygon:
        gui.MessageDialog('Objcet needs to be of type polygon')
        return

    # Get all points in object
    bs = op.GetPointS()

    for pt in xrange(op.GetPointCount()):

        # Get global position of point 'pt'
        pointGlobal = op.GetMg() * op.GetPoint(pt)

        # Split pointGlobal
        pointX = bd.WS(pointGlobal)[0]
        pointY = bd.WS(pointGlobal)[1]

        # Check if point is inside SafeFrame 'view'
        if pointX > 0 and pointX < view['cr']:
            if pointY > view['ct'] and pointY < view['cb']:
                bs.Select(pt)

    c4d.EventAdd()
コード例 #3
0
ファイル: c4d-copy-paste.py プロジェクト: zhekui/c4d-scripts
def Copy(tmppath, converted):
    sel = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_CHILDREN)
    if not sel:
        gui.MessageDialog('Select some Objects first.')
        return

    c4d.StopAllThreads()
    c4d.StatusSetSpin()

    export = []
    for obj in sel:
        #Convert Current State to Object for all selected Objects
        if converted:
            obj = Command_CSTO(obj)
        export.append(obj)

    if export == []:
        message = 'Sorry, nothing to Export.'
        gui.MessageDialog(message)
        return

    iso_objs=c4d.documents.IsolateObjects(doc, export)
    c4d.documents.SaveDocument(iso_objs, tmppath, c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, c4d.FORMAT_C4DEXPORT)

    c4d.StatusClear()

    message = 'Copied Object(s).'
    if converted:
        message = 'Copied converted Object(s).'

    gui.MessageDialog(message)
コード例 #4
0
    def CoreMessage(self, id, msg):
        """Override this function if you want to react
		to C4D core messages. The original message is stored in msg.
		"""
        if id == __exporter_id__:
            c4d.StatusSetBar(100)

            if g_uploaded:
                result = gui.MessageDialog(
                    "Your model was uploaded to Sketchfab.com.\nClick OK to open it in your browser.",
                    c4d.GEMB_OKCANCEL)
                if result == c4d.GEMB_R_OK:
                    webbrowser.open(Config.SKETCHFAB_URL + '/models/' +
                                    model_id)
            else:
                print("Unable to upload model to Sketchfab.com. Reason: {0}".
                      format(g_error))
                gui.MessageDialog(
                    "Unable to upload model to Sketchfab.com. Reason: {0}".
                    format(g_error), c4d.GEMB_OK)

            self.draw_upload_button()
            self.Enable(BTN_PUBLISH, True)
            self.SetTitle("Upload status")
            c4d.StatusClear()

        return True
コード例 #5
0
def main():
    #Quit early if nothing is selected or if the selection isn't a spline, polygon or FFD
    if op == None:
        print 'Please apply the "point-autorig" script to an editable spline, polygon or FFD object.'
        gui.MessageDialog(
            'Please apply the "point-autorig" script to an editable spline, polygon or FFD object.'
        )
        return None
    if not (op.GetType() == c4d.Ospline or op.GetType() == c4d.Offd
            or op.GetType() == c4d.Opolygon):
        print 'Please apply the "point-autorig" script to an editable spline, polygon or FFD object.'
        gui.MessageDialog(
            'Please apply the "point-autorig" script to an editable spline, polygon or FFD object.'
        )
        return None

    #Test for existing rig - if there is one, update it (this allows us to keep any
    #existing animation, although you might have to manually change the order of nulls
    #depending on where your new points are)
    #The test looks for any Python tag starting with the teststring ("#pointrig tagcode")
    pythontags = getTagsByType(op.GetTags(), c4d.Tpython)
    teststring = "#pointrig tagcode"
    for tag in pythontags:
        if tag[c4d.TPYTHON_CODE][:len(teststring)] == teststring:
            update_rig(op)
            return

    #If there isn't already a rig, create one
    new_rig(op)
コード例 #6
0
ファイル: ue4exporter.py プロジェクト: alex4wtr/scripts
    def Command(self, id, msg):
        path = ""
        #handle user input

        # GROUP 1
        if id == ETEX_MAPNAME:
            mapname = self.GetString(ETEX_MAPNAME)

        # GROUP 2
        if id == ETEX_PACKAGENAME:
            package = self.GetString(ETEX_PACKAGENAME)

        # GROUP 3
        if id == ETEX_PACKAGENAME:
            layer = self.GetString(ETEX_LAYERNAME)

        if id == BTN_LAYER:
            if active.GetActiveObject():
                self.SetString(ETEX_LAYERNAME,
                               active.GetActiveObject().GetName())
            else:
                gui.MessageDialog('Nothing selected')

        if id == BTN_FILE:
            if active.GetActiveObject():
                self.SetString(ETEX_FILENAME,
                               active.GetActiveObject().GetName())
            else:
                gui.MessageDialog('Nothing selected')
        # Group 5
        if id == BTN_OPEN:
            self.SetString(
                ETEX_PATH,
                c4d.storage.LoadDialog(title="Select output folder...",
                                       flags=c4d.FILESELECT_DIRECTORY))
            path = self.GetString(ETEX_PATH)
            checkPath(path, self)

        if id == ETEX_PATH:
            path = self.GetString(ETEX_PATH)
            checkPath(path, self)

        # Group 6
        if id == BTN_EXPORT:
            mapname = self.GetString(ETEX_MAPNAME)
            package = self.GetString(ETEX_PACKAGENAME)
            layer = self.GetString(ETEX_LAYERNAME)
            if layer == "": layer = "None"
            filename = self.GetString(ETEX_FILENAME)
            if filename == "": filename = "Unnamed"
            path = self.GetString(ETEX_PATH)

            dissolve(active, mapname, package, layer, path, filename)
            export(active, path, filename)

        return True
コード例 #7
0
ファイル: proteinRig_v1.0.py プロジェクト: skcsd/ePMV
def main():  #Gives feedback to user based on user interaction
    op = doc.GetActiveObject()
    if doc.GetActiveObject() == None:
        gui.MessageDialog("Please select a molecule")
    else:
        atom_list = FindAtoms(op)
        if atom_list == []:
            gui.MessageDialog("Please enable atoms in ePMV")
        else:
            main1(op)
コード例 #8
0
 def update(self):
     self.render()
     self.SetString(MinesweeperGui.TXT_SCORE_ID,
                    'SCORE : %s' % self.game.score)
     if not self.game.can_play:
         if self.game.is_victory:
             gui.MessageDialog('VICTORY :) \nFinal score %s' %
                               self.game.score)
         else:
             gui.MessageDialog('GAME OVER :( \nFinal score %s' %
                               self.game.score)
コード例 #9
0
def main():
    #get selected object
    obj = doc.GetActiveObject()
    if obj is None:
        gui.MessageDialog("An object must be selected")
        return
    #finding where to save json file
    filePath = storage.LoadDialog(
        title="Save JSON file with Objects Positions",
        flags=c4d.FILESELECT_SAVE,
        force_suffix="json")
    if filePath is None:
        return

    #open file
    f = open(filePath, "w")

    #begin Json formatting
    f.write("{")
    #get the children
    children = obj.GetChildren()
    print obj.GetName() + " has " + str(len(obj.GetChildren())) + " children"
    f.write('"name":' + '"' + obj.GetName() + '",\n')
    f.write('\t"objects":[\n')
    for i in range(0, len(children)):
        pos = children[i].GetAbsPos()
        rot = children[i].GetRelRot()
        name = children[i].GetName()
        print "+ " + children[i].GetName()
        print "   +Position:( " + str(pos.x) + "," + str(pos.y) + "," + str(
            pos.z) + ")"
        print "   +Rotation:( " + str(pos.x) + "," + str(pos.y) + "," + str(
            pos.z) + ")"
        f.write('\t{\n')
        f.write('\t\t"name":"' + name + '",')
        f.write('\n\t\t"position":[' + str(pos.x) + ',' + str(pos.y) + ',' +
                str(pos.z) + '],')
        f.write('\n\t\t"rotation":[' + str(rot.x) + ',' + str(rot.y) + ',' +
                str(rot.z) + ']')
        if i == len(children) - 1:
            f.write('\n\t}\n')
        else:
            f.write('\n\t},\n')
    f.write('\t]\n')
    #get path to sive file
    # Get a path to save the exported file

    #saving file
    f.write("}")
    f.close()

    c4d.CopyStringToClipboard("hi")
    gui.MessageDialog(".json file exported with success")
    pos = obj.GetRelPos()
コード例 #10
0
def main():
    tag = doc.GetActiveTags()
    if not tag:
        gui.MessageDialog('No texture tag selected.')

    for t in tag:
        if not (t.GetType() == 5616):
            gui.MessageDialog('Error: Non-Texture Tag Selected.')
        t[c4d.TEXTURETAG_OFFSETX] = random.uniform(-1, 1)
        t[c4d.TEXTURETAG_OFFSETY] = random.uniform(-1, 1)
    c4d.EventAdd()
コード例 #11
0
def main():
    oplist = doc.GetActiveObjects(c4d.GETACTIVEOBJECTFLAGS_0)

    #Quit early if nothing is selected
    if len(oplist) == 0:
        print 'Please apply the "splinewrap-autorig" script to a Spline Wrap object.'
        gui.MessageDialog(
            'Please apply the "splinewrap-autorig" script to a Spline Wrap object.'
        )
        return None

    #apply the rig to all selected splinewrap objects
    rigcount = 0
    existingcount = 0
    doc.StartUndo()
    for op in oplist:
        if op.GetType() == 1019221:
            applyrig = True

            #Test for existing rig - if there is one, return without doing anything
            #The test looks for any Python tag starting with the teststring ("#splinewrap rig tagcode")
            pythontags = getTagsByType(op.GetTags(), c4d.Tpython)
            teststring = "#splinewrap rig tagcode"

            for tag in pythontags:
                if tag[c4d.TPYTHON_CODE][:len(teststring)] == teststring:
                    applyrig = False
                    existingcount += 1
                    break

            #If there isn't already a rig, create one
            if applyrig:
                new_rig(op)
                rigcount += 1

    doc.EndUndo()
    if rigcount == 0 and existingcount == 0:
        print 'Please apply the "splinewrap-autorig" script to a Spline Wrap object.'
        gui.MessageDialog(
            'Please apply the "splinewrap-autorig" script to a Spline Wrap object.'
        )
        return None
    else:
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        msg = "Spline wrap rig added " + str(rigcount) + " times!"
        if existingcount > 0:
            msg += " Rig already exists on " + str(
                existingcount) + " spline wraps."
        print msg
コード例 #12
0
ファイル: c4d-copy-paste.py プロジェクト: zhekui/c4d-scripts
def main():
    tmp = tempfile.gettempdir()
    tmppath = os.path.join(tmp, 'c4d_copypaste.c4d')

    result = PopupMenu(tmppath)

    #Copy selected Objects
    if result == c4d.FIRST_POPUP_ID + 1:
        Copy(tmppath, False)
        return

    #Copy (converted) selected Objects
    if result == c4d.FIRST_POPUP_ID + 2:
        Copy(tmppath, True)
        return

    #Paste Objects
    if result == c4d.FIRST_POPUP_ID + 3:
        Paste(tmppath)
        return

    #Delete Temporary Files
    if result == c4d.FIRST_POPUP_ID + 4:
        os.remove(tmppath)
        gui.MessageDialog('Deleted Temporary File!')
        return
コード例 #13
0
def main():
    obj = doc.GetActiveObject()

    if obj == None:
        gui.MessageDialog('=(')
    else:
        pc = c4d.PointObject.GetPointCount(obj)
        sel = obj.GetPointS()
        sel.DeselectAll()

        itr2 = 0
        while itr2 <= pc:
            itr2 += 1
            pc = c4d.PointObject.GetPointCount(obj)  #point count
            pp = tuple(c4d.PointObject.GetAllPoints(obj))
            for i in range(pc):
                if i == range(pc)[-1]:
                    break
                elif pp[i] == pp[i + 1]:
                    sel = obj.GetPointS()
                    sel.Select(i)
                    sel.Select(i + 1)
                    c4d.CallCommand(12568)
                    sel.DeselectAll()
                    c4d.EventAdd()
                    break
                else:
                    continue
def main():
    c4d.StopAllThreads()
    doc = c4d.documents.GetActiveDocument()
    fps = doc.GetFps()
    fromTime = doc.GetMinTime().GetFrame(fps)
    toTime = doc.GetMaxTime().GetFrame(fps)
    animLength = toTime - fromTime + 1
    filePath = c4d.storage.SaveDialog()
    filePath, objName = os.path.split(filePath)
    objName = objName + "_"
    filePath = filePath + "\\"

    for f in range(0, animLength):
        doc.SetTime(c4d.BaseTime(fromTime, fps) + c4d.BaseTime(f, fps))
        c4d.EventAdd(c4d.EVENT_FORCEREDRAW)
        c4d.DrawViews(c4d.DRAWFLAGS_FORCEFULLREDRAW)

        c4d.StatusSetText("Exporting " + str(f) + " of " + str(animLength))
        c4d.StatusSetBar(100.0 * f / animLength)

        c4d.CallCommand(16768, 16768)
        c4d.CallCommand(100004794, 100004794)
        c4d.CallCommand(100004787)

        fileName = filePath + objName + str(f) + ".obj"
        savingresult = c4d.documents.SaveDocument(doc, fileName,
                                                  c4d.SAVEDOCUMENTFLAGS_0,
                                                  c4d.FORMAT_OBJ2EXPORT)

        c4d.CallCommand(12105, 12105)
        c4d.CallCommand(12105, 12105)
        c4d.CallCommand(12105, 12105)

    c4d.StatusClear()
    gui.MessageDialog('Exporting to' + filePath + ' done')
コード例 #15
0
def main():
    # get folder path
    folder = c4d.storage.LoadDialog(type=c4d.FILESELECTTYPE_ANYTHING,
                                    title="Select RS Tex Folder:",
                                    flags=c4d.FILESELECT_DIRECTORY,
                                    force_suffix="")

    # get files only
    folder_files = [
        f for f in os.listdir(folder)
        if os.path.isfile(os.path.join(folder, f))
    ]

    # main conversion loop
    for file in folder_files:
        # get full file path
        file_path = '"' + os.path.join(folder, file) + '"'

        # get RS texure processor file_path
        rs_tex_processor = 'C:\\ProgramData\\Redshift\\bin\\redshiftTextureProcessor.exe'
        cmd = rs_tex_processor + ' ' + file_path

        exe = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
        info = ""
        info = exe.communicate()[0]
        print info

    gui.MessageDialog('Converted: ' + str(len(folder_files)) +
                      ' Textures into .rstexbin format sucessfully.')
コード例 #16
0
    def Convert():
        active_mat = doc.GetActiveMaterial()
        if active_mat == None:
            gui.MessageDialog("Please select at least one Material")

        c4d.CallCommand(1029770, 1029770)
        c4d.EventAdd()
コード例 #17
0
def main():
    sel = doc.GetActiveObjects(False)  # Get selected objects
    if sel is None:
        gui.MessageDialog("No Object Selected", c4d.GEMB_OK)
        return False
    bc = c4d.BaseContainer()
    doc.StartUndo()
    for op in sel:
        inst = instClone()  # Get Instance Object
        opN = op.GetName()  # Get Name
        if opN == "REF":
            break
        doc.InsertObject(inst, op)  # Insert into document
        opMatrix = op.GetMl()  # Get Matrix of Selected
        inst.SetMl(opMatrix)
        doc.AddUndo(c4d.UNDOTYPE_NEW, inst)  # Undo Instance Object

        target = op.GetDown()  # Select the Child (New Instance Ob)
        target.SetName(opN)  # Set Name
        target.InsertBefore(op)  # Insert Render Instance Above Selected

        for track in op.GetCTracks():  # Get Selected Tracks
            newTrack = track.GetClone()  # Clone the Tracks
            target.InsertTrackSorted(newTrack)  # Place the Tracks into Insts

        doc.AddUndo(c4d.UNDOTYPE_DELETE, op)
        op.Remove()  # Remove Selected Items
        doc.EndUndo()
    c4d.EventAdd()
コード例 #18
0
def main():
    if not op:
        return

    try:
        #Convert "Current State to Object"
        obj = Command_CurrentStateToObject(op)
        if obj is None:
            return

        #Get All Points of converted Spline and multiply by Scaling-Factor
        points = obj.GetAllPoints()
        scalefactor = float(0.01)
        points = [p * scalefactor for p in points]

        #Initiate Clipboard-String
        code = ""

        for p in points:
            code += """%s, %s, %s """ % (p.x, p.y, p.z)

        #Copy First Point at End of String to Close the Spline
        if obj.IsClosed():
            code += """%s, %s, %s""" % (points[0].x, points[0].y, points[0].z)

        #Copy Code to Clipboard
        c4d.CopyStringToClipboard(code)
        print "Spline-Info copied to Clipboard..!"

    except:
        message = "...N O T  a  S p l i n e  ! ! !"
        gui.MessageDialog(message)
        return
コード例 #19
0
    def SelectTopMix():
        mixlist = []
        i = 0
        matlist = doc.GetMaterials()

        SelMat = doc.GetActiveMaterial()

        for mat in matlist:
            if mat.GetType() == 1029622:  # MixMaterial type int
                mixlist.append(mat)

        # print mixlist
        while i < len(mixlist):
            for mat in mixlist:
                if SelMat == mat[c4d.MIXMATERIAL_TEXTURE1] or SelMat == mat[
                        c4d.MIXMATERIAL_TEXTURE2]:
                    SelMat = mat
            i = i + 1

        if SelMat == None:
            gui.MessageDialog('Not Mixed!')
        # print len(mixlist)
        c4d.CallCommand(300001026, 300001026)  # Deselect all mat

        SelMat.SetBit(c4d.BIT_ACTIVE)
        c4d.EventAdd()
コード例 #20
0
ファイル: ShowIndex.py プロジェクト: AsheAnn/ShowIndex_C4dpy
def main():
    # Large Icons
    c4d.CallCommand(100004708, 100004708)

    # Lines
    c4d.CallCommand(12540, 12540)

    # seleted object
    obj = doc.GetActiveObject()

    if obj == None:
        gui.MessageDialog('Please Select the Object!')
        return
    else:
        AddUserData(obj, "Show Points Index", True)
        AddUserData(obj, "Show Edge Index", False)
        AddUserData(obj, "Show Primitive Index", False)

    # Insert the cloner object
    displayEdgeIndex(obj)
    displayPrimIndex(obj)
    displayPntIndex(obj)
    doc.GetActiveObject()

    # Add python Tag
    c4d.CallCommand(100004788, 50056)
    c4d.EventAdd()
コード例 #21
0
def main():

    obs = doc.GetActiveObjects(0)

    if not obs:
        gui.MessageDialog('Please select some objects!')
        return

    if len(obs) == 1:
        nullm = obs[0].GetMg()
    else:
        nullm = c4d.Matrix()
        nullm.off = sum([ob.GetMg().off for ob in obs]) / len(obs)

    doc.StartUndo()
    null = c4d.BaseObject(c4d.Onull)
    null.InsertBefore(obs[0])
    doc.AddUndo(c4d.UNDOTYPE_NEW, null)
    null.SetBit(c4d.BIT_ACTIVE)
    null.SetMg(nullm)

    for ob in obs:
        m = ob.GetMg()
        doc.AddUndo(c4d.UNDOTYPE_HIERARCHY_PSR, ob)
        ob.InsertUnderLast(null)
        ob.DelBit(c4d.BIT_ACTIVE)
        ob.SetMg(m)

    doc.EndUndo()
    c4d.EventAdd()
コード例 #22
0
def main():
    doc.StartUndo()
    mats = doc.GetActiveMaterials()
    first(mats)
    gui.MessageDialog("Done")
    doc.EndUndo()
    c4d.EventAdd()
コード例 #23
0
ファイル: core.py プロジェクト: worrytron/pipeline
def createChildRenderData(rd, suffix=False, set_active=False):
    ''' Inserts a new RenderData as a child to an existing one, including a name suffix.'''
    if rd.GetUp():
        msg = 'Warning: This Render Data is already a child of an existing one. Canceling operation...'
        gui.MessageDialog(msg)
        return False
    doc = c4d.documents.GetActiveDocument()
    doc.StartUndo()
    child_rdata = c4d.documents.RenderData()
    child_rdata.SetData(rd.GetData())
    doc.InsertRenderData(child_rdata, pred=rd)
    doc.AddUndo(c4d.UNDOTYPE_NEW, rd)
    child_rdata.InsertUnder(rd)

    for multipass in ObjectIterator(rd.GetFirstMultipass()):
        new_mpass = c4d.BaseList2D(c4d.Zmultipass)
        new_mpass.GetDataInstance()[
            c4d.MULTIPASSOBJECT_TYPE] = multipass.GetType()
        new_mpass.SetData(multipass.GetData())
        child_rdata.InsertMultipass(new_mpass)
    for videopost in ObjectIterator(rd.GetFirstVideoPost()):
        new_vpost = c4d.BaseList2D(videopost.GetType())
        new_vpost.SetData(videopost.GetData())
        child_rdata.InsertVideoPost(new_vpost)

    if (type(suffix) == str):
        name = '{} {}'.format(child_rdata.GetName(), suffix)
        child_rdata.SetName(name)
    if (set_active): doc.SetActiveRenderData(child_rdata)

    c4d.EventAdd()
    doc.EndUndo()
    return child_rdata
コード例 #24
0
def main():
    doc = c4d.documents.GetActiveDocument()  # Get active document
    bc = c4d.BaseContainer()  # Initialize a base container
    keyMod = "None"  # Initialize a keyboard modifier status
    # Button is pressed
    if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.BFM_INPUT_CHANNEL,
                             bc):
        if bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT:
            if bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QCTRL:  # Ctrl + Shift
                if bc[c4d.
                      BFM_INPUT_QUALIFIER] & c4d.QALT:  # Alt + Ctrl + Shift
                    keyMod = 'Alt+Ctrl+Shift'
                else:  # Shift + Ctrl
                    keyMod = 'Ctrl+Shift'
            elif bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QALT:  # Alt + Shift
                keyMod = 'Alt+Shift'
            else:  # Shift
                keyMod = 'Shift'
        elif bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QCTRL:
            if bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QALT:  # Alt + Ctrl
                keyMod = 'Alt+Ctrl'
            else:  # Ctrl
                keyMod = 'Ctrl'
        elif bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QALT:  # Alt
            keyMod = 'Alt'
        else:  # No keyboard modifiers used
            keyMod = 'None'

    # Now you can use keyMod variable to get status what keymodifiers are pressed
    if keyMod == "Ctrl":
        gui.MessageDialog('Ctrl pressed')
コード例 #25
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
コード例 #26
0
def main():

    doc = c4d.documents.GetActiveDocument()
    bc = c4d.BaseContainer()
    root = doc.GetLayerObjectRoot()
    layer = root.GetDown()
    toggled = 0

    if c4d.gui.GetInputState(c4d.BFM_INPUT_KEYBOARD, c4d.BFM_INPUT_CHANNEL,
                             bc):
        if not bc[c4d.BFM_INPUT_QUALIFIER] & c4d.QSHIFT:
            # Mute Selected Layers
            while layer:
                if layer.GetBit(c4d.BIT_ACTIVE):
                    layer_data = layer.GetLayerData(doc)
                    layer_data['view'] = not layer_data['view']
                    layer_data['render'] = not layer_data['render']
                    layer_data['manager'] = not layer_data['manager']
                    layer_data['locked'] = not layer_data['locked']
                    layer_data['generators'] = not layer_data['generators']
                    layer_data['expressions'] = not layer_data['expressions']
                    layer_data['animation'] = not layer_data['animation']
                    layer_data['deformers'] = not layer_data['deformers']
                    layer.SetLayerData(doc, layer_data)
                    toggled = 1

                if not layer.GetBit(c4d.BIT_ACTIVE):
                    toggled = 1

                layer = getNextLayer(layer)
        else:
            # Solo Selected Layers if Shift is pressed
            while layer:
                if not layer.GetBit(c4d.BIT_ACTIVE):
                    layer_data = layer.GetLayerData(doc)
                    layer_data['view'] = not layer_data['view']
                    layer_data['render'] = not layer_data['render']
                    layer_data['manager'] = not layer_data['manager']
                    layer_data['locked'] = not layer_data['locked']
                    layer_data['generators'] = not layer_data['generators']
                    layer_data['expressions'] = not layer_data['expressions']
                    layer_data['animation'] = not layer_data['animation']
                    layer_data['deformers'] = not layer_data['deformers']
                    layer.SetLayerData(doc, layer_data)
                    toggled = 1

                if layer.GetBit(c4d.BIT_ACTIVE):
                    layer_data = layer.GetLayerData(doc)
                    layer_data['solo'] = not layer_data['solo']
                    layer.SetLayerData(doc, layer_data)
                    toggled = 1

                layer = getNextLayer(layer)

    if toggled == 0:
        gui.MessageDialog("Select a layer")
        return False

    c4d.EventAdd()
コード例 #27
0
	def AskClose(self):
		if self.importer and not self.importer.is_done:
			answer = gui.MessageDialog(text='Are you sure you want to abort the import ?', type=c4d.GEMB_YESNO)
			if answer == c4d.GEMB_R_YES:
				self.importer.AbortImport()
			else:
				return
		return False
コード例 #28
0
ファイル: exportFBX.py プロジェクト: pyrrrrr/c4dScripts
    def save(self, selection):

        container = c4d.plugins.GetWorldPluginData(1026370)
        for id, value in container:
            if id == c4d.FBXEXPORT_ASCII: container[id] = 0
            elif id == c4d.FBXEXPORT_BAKE_ALL_FRAMES: container[id] = 1
            elif id == c4d.FBXEXPORT_SAVE_NORMALS: container[id] = 1
            elif id == c4d.FBXEXPORT_TRACKS: container[id] = 1
            elif id == c4d.FBXEXPORT_BAKE_ALL_FRAMES: container[id] = 1
            elif id == c4d.FBXEXPORT_TEXTURES: container[id] = 1
            elif id == c4d.FBXEXPORT_EMBED_TEXTURES: container[id] = 0
            elif id == c4d.FBXEXPORT_PLA_TO_VERTEXCACHE: container[id] = 0

        newdoc = doc
        newDocName = ""
        if selection is True:
            null = doc.GetSelection()
            if len(null) == 0:
                gui.MessageDialog(
                    'Your selection is bad und you should feel bad about it!')
                self.Close()
                return
            if len(null) > 1:
                gui.MessageDialog('Multiple objects selected')
                self.Close()
                return

            newdoc = c4d.documents.IsolateObjects(doc, null)

            newdoc.SetFps(doc.GetFps())
            newdoc.SetMinTime(doc.GetMinTime())
            newdoc.SetMaxTime(doc.GetMaxTime())

            newDocName = "_" + newdoc.GetFirstObject().GetName()
            print newDocName

        docPath = doc.GetDocumentPath()
        docName = docPath + "\\" + doc.GetDocumentName().replace(
            ".c4d", newDocName + ".fbx")
        print docPath
        print docName

        c4d.documents.SaveDocument(newdoc, docName,
                                   c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                                   1026370)
        self.Close()
コード例 #29
0
def main():
    path = storage.LoadDialog(type=c4d.FILESELECTTYPE_IMAGES, title="Please Choose a 32-bit Image:")
    if not path: return
    
    # Create and initialize selected image
    orig = bitmaps.BaseBitmap()
    if orig.InitWith(path)[0] != c4d.IMAGERESULT_OK:
        gui.MessageDialog("Cannot load image \"" + path + "\".")
        return
    
    # Check if channel depth is really 32 bit
    if orig.GetBt()/3 != 32:
        gui.MessageDialog("The image \"" + path + "\" is not a 32 bit per-channel image.")
        return
    
    # Get selected image infos
    width, height = orig.GetSize()
    bits = orig.GetBt()
    
    # Create the copy and initialize it
    copy = bitmaps.BaseBitmap()
    copy.Init(width, height, bits)
    
    # Calculate the number of bytes per pixel
    inc = orig.GetBt()/8 # Each pixel has RGB bits, so we need an offset of 'inc' bytes per pixel
                         # the image has 32 bits per-channel : (32*3)/8 = 12 bytes per pixel (1 byte = 8 bits)
                         # the image has 3 channels per pixel (RGB) : 12/3 = 4 bytes per component = 1 float
    
    # Create a byte sequence buffer large enough to store the copied image pixels
    sq = storage.ByteSeq(None, width*height*inc)
    
    for row in xrange(height):
        offset = sq.GetOffset(row*(width*inc)) # Offset on bitmap row + offset bytes per pixel
        orig.GetPixelCnt(0, row, width, offset, inc, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) # Read pixels from the original bitmap into the buffer
    
    #Example: RGB value of first pixel (only for 32 bits)
    #import struct
    #r, g, b = struct.unpack("fff", sq[0:12])
    #print r, g, b
    
    for row in xrange(height):
        offset = sq.GetOffset(row*(width*inc)) # Offset on bitmap row + offset bytes per pixel
        copy.SetPixelCnt(0, row, width, offset, inc, c4d.COLORMODE_RGBf, c4d.PIXELCNT_0) # Set pixels in bitmap copy
    
    bitmaps.ShowBitmap(orig) # Show original
    bitmaps.ShowBitmap(copy) # Show copied image
コード例 #30
0
def importVox(path):
    #parse file
    with open(path, 'rb') as f:

        #check filetype
        bytes = f.read(4)
        file_id = struct.unpack(">4s", bytes)
        if file_id[0] == 'VOX ':

            #init material list
            matlist = []
            BaseCube = c4d.BaseObject(c4d.Ocube)
            BaseCube[c4d.PRIM_CUBE_DOFILLET] = True
            BaseCube[c4d.PRIM_CUBE_FRAD] = 8
            BaseCube[c4d.PRIM_CUBE_SUBF] = 1
            doc.InsertObject(BaseCube)

            #skip header
            f.seek(56)

            #read number of voxels, stuct.unpack parses binary data to variables
            bytes = f.read(4)
            numvoxels = struct.unpack('<I', bytes)

            #iterate through voxels
            for x in range(0, numvoxels[0]):

                #read voxels, ( each voxel : 1 byte x 4 : x, y, z, colorIndex ) x numVoxels
                bytes = f.read(4)
                voxel = struct.unpack('<bbbB', bytes)

                #generate Cube and set position, change to 'Oinstance' for instances
                MyCube = c4d.BaseObject(c4d.Oinstance)
                MyCube[c4d.INSTANCEOBJECT_RENDERINSTANCE] = True
                MyCube[c4d.INSTANCEOBJECT_LINK] = BaseCube
                MyCube.SetAbsPos(
                    c4d.Vector(-voxel[1] * 200, voxel[2] * 200,
                               voxel[0] * 200))

                #update material list, generate new material only if it isn't in the list yet
                matid = voxel[3]
                if matid not in matlist:
                    matlist.append(matid)
                    myMat = c4d.BaseMaterial(c4d.Mmaterial)
                    myMat.SetName(str(matid))
                    myMat[c4d.MATERIAL_COLOR_COLOR] = c4d.Vector(
                        random.random(), random.random(), random.random())
                    doc.InsertMaterial(myMat)

                #assign material to voxel and insert everything into the scene
                mat = doc.SearchMaterial(str(matid))
                textag = c4d.TextureTag()
                textag.SetMaterial(mat)
                MyCube.InsertTag(textag)
                doc.InsertObject(MyCube)

        else:
            gui.MessageDialog('Not a .VOX file')