Exemple #1
0
def main():
    obj = doc.GetActiveObject()
    if not isinstance(obj, c4d.PolygonObject):
        return 0

    uv_tag = obj.GetTag(c4d.Tuvw)
    neigh = Neighbor()
    neigh.Init(obj)
    polys = obj.GetAllPolygons()
    select = c4d.BaseSelect(neigh.GetEdgeCount() - 1)

    for ind, poly in enumerate(polys):
        data = neigh.GetPolyInfo(ind)
        for i in range(4):
            n_ind = data['face'][i]
            if data['mark'][i] or i == 2 and poly.c == poly.d:
                continue
            elif n_ind == -1 or check_edge(ind, n_ind, uv_tag, poly,
                                           polys[n_ind]):
                select.Select(data['edge'][i])

    doc.AddUndo(c4d.UNDOTYPE_CHANGE_SELECTION, obj)
    obj.SetSelectedEdges(neigh, select, c4d.EDGESELECTIONTYPE_SELECTION)
    if ctrl_hold():
        obj.SetSelectedEdges(neigh, select, c4d.EDGESELECTIONTYPE_PHONG)
        obj.SetPhong(1, 1, 40)
    doc.SetMode(c4d.Medges)
def MgSelTagsFromSelectedClones(obj):
    tag = obj.GetLastTag()  # Get object's last tag
    tags = obj.GetTags()  # Get object's tags
    md = mo.GeGetMoData(obj)  # Get object's MoGraph data
    cnt = md.GetCount()  # Get clone count
    selection = mo.GeGetMoDataSelection(
        tag)  # Get selection from MoGraph selection tag
    prefix = "ms"  # Prefix
    sep = "_"  # Separator
    x = 0  # Initialize iteration variable
    for k in tags:  # Loop through reversed list of tags
        if k.GetName().split("_")[0] == prefix:
            x = x + 1  # Increase iteration variable
    for i in range(0, cnt):  # Loop through reversed list of clones
        if selection.IsSelected(i) == True:
            t = c4d.BaseTag(1021338)  # Initialize MoGraph selection tag
            t[c4d.ID_BASELIST_NAME] = prefix + sep + str(x)  # Set tag name
            s = c4d.BaseSelect()  # Initialize BaseSelect
            s.Select(i)  # Select clone
            obj.InsertTag(t, obj.GetLastTag())  # Insert new tag to object
            doc.AddUndo(c4d.UNDOTYPE_NEW,
                        t)  # Add undo command for inserting new tag
            mo.GeSetMoDataSelection(t, s)  # Set MoGraph selection
            x = x + 1  # Increase iteration variable
    tag.Remove()  # Remove old tag
    doc.AddUndo(c4d.UNDOTYPE_DELETE, tag)  # Add undo command for removing tag
Exemple #3
0
def main():
    doc.StartUndo()
    tag = op.GetLastTag()
    tags = op.GetTags()
    md = mo.GeGetMoData(op)
    cnt = md.GetCount()
    selection = mo.GeGetMoDataSelection(tag)
    prefix = "ms"
    sep = "_"
    x = 0
    for k in reversed(tags):
        if k.GetName().split("_")[0] == prefix:
            x = x + 1
    for i in reversed(xrange(0, cnt)):
        if selection.IsSelected(i) == True:
            t = c4d.BaseTag(1021338)
            t[c4d.ID_BASELIST_NAME] = prefix + sep + str(x)
            s = c4d.BaseSelect()
            s.Select(i)
            op.InsertTag(t)
            doc.AddUndo(c4d.UNDOTYPE_NEW, t)
            mo.GeSetMoDataSelection(t, s)
            x = x + 1
    tag.Remove()
    doc.AddUndo(c4d.UNDOTYPE_DELETE, tag)
    doc.EndUndo()
    c4d.EventAdd()
Exemple #4
0
def main():
    path = c4d.storage.SaveDialog()
    for child in op.GetChildren():
        count = 0
        tempSelectList = list()
        tempSelectName = list()
        for tag in child.GetTags():
            if isinstance(
                    tag,
                    c4d.SelectionTag) and tag.GetName().startswith("Piece"):
                count += 1
            elif isinstance(tag, c4d.SelectionTag
                            ) and not tag.GetName().startswith("Piece"):
                tempSelection = c4d.BaseSelect()
                tag.GetBaseSelect().CopyTo(tempSelection)
                tempSelectList.append(tempSelection)
                tempSelectName.append(tag.GetName())
                child.KillTag(c4d.Tpolygonselection, count)
        lastTag = child.GetLastTag()
        for index, selection in enumerate(tempSelectList):
            newTag = child.MakeTag(c4d.Tpolygonselection, lastTag)
            newTag.SetName(tempSelectName[index])
            selection.CopyTo(newTag.GetBaseSelect())

        count = 0
        for tag in child.GetTags():
            if isinstance(
                    tag,
                    c4d.SelectionTag) and tag.GetName().startswith("Piece"):
                newselection = child.GetPolygonS()
                newselection.DeselectAll()
                selection = tag.GetBaseSelect().CopyTo(newselection)

                secList = utils.SendModelingCommand(
                    command=c4d.MCOMMAND_SPLIT,
                    list=[child],
                    mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                    doc=doc)
                if secList:
                    sec = secList[0]
                    sec.SetName(tag.GetName())
                    sec.InsertAfter(op)
                    for i in range(count):
                        sec.KillTag(c4d.Tpolygonselection)

                    fbxPath = path + '_' + str(count) + '.fbx'
                    c4dPath = path + '_' + str(count) + '.c4d'
                    print(fbxPath)
                    newDoc = c4d.documents.IsolateObjects(doc, [sec])
                    obj = newDoc.GetFirstObject()
                    newDoc.SetSelection(obj, c4d.SELECTION_NEW)
                    c4d.documents.SaveDocument(
                        newDoc, fbxPath,
                        c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST, 1026370)
                    c4d.documents.SaveDocument(
                        newDoc, c4dPath,
                        c4d.SAVEDOCUMENTFLAGS_DONTADDTORECENTLIST,
                        c4d.FORMAT_C4DEXPORT)
                    sec.Remove()
                    count += 1
Exemple #5
0
def main():
    bs = c4d.BaseSelect()
    obj = doc.GetFirstObject()
    chunk = 0
    i = 0
    while obj:
        i += 1
        obj = obj.GetNext()
    obj = doc.GetFirstObject()
    j = 0
    save = 0

    while obj:

        j += 1
        if chunk < 256:
            doc.SetActiveObject(obj, c4d.SELECTION_ADD)
            chunk += 1
        else:
            save += 1
            c4d.CallCommand(16768)
            print 100.0 / float(i) * j, i, j
            doc.SetActiveObject(obj)
            chunk = 0

        if save == 8:
            save = 0
            c4d.documents.SaveDocument(doc, doc.GetDocumentName(),
                                       c4d.SAVEDOCUMENTFLAGS_0,
                                       c4d.FORMAT_C4DEXPORT)
        obj = obj.GetNext()
Exemple #6
0
def main():
    # Checks if selected object is valid
    if op is None:
        raise ValueError("op is none, please select one object.")

    # Checks if the selected object is a PolygonObject
    if not isinstance(op, c4d.PolygonObject):
        raise TypeError("op is not a c4d.PolygonObject.")

    # Retrieves teh first UVW tag on the current object
    uvwTag = op.GetTag(c4d.Tuvw)
    if uvwTag is None:
        raise RuntimeError("Failed to retrieves a uvw tag on the object.")

    # Retrieves the current Point Selection stored in the PointObject
    ptSelect = op.GetPointS()
    if ptSelect is None:
        raise RuntimeError("Failed to retrieves the selected point.")

    # Retrieves all elements, selected or not, as booleans in a list
    rawSelectionList = ptSelect.GetAll(op.GetPointCount())

    # Retrieves the point ID that are selected from the rawSelectionList
    pointIdSelected = [i for i, value in enumerate(rawSelectionList) if value]

    # Gets all CPolygon of the selected object
    polyList = op.GetAllPolygons()

    # Creates a new pinSelection To Set
    pinsToSet = c4d.BaseSelect()

    # For each CPolygon convert point selection to uv point id
    for polyId in range(op.GetPolygonCount()):
        # Get the CPolygon
        cPoly = polyList[polyId]

        # Iterate over each Point of a CPolygon (4 points), a, b ,c and d
        for polyPtId in range(4):
            # Selects the uv point pinned if PointId of the CPolygon is selected
            ptId = CPolygonGetItem(cPoly, polyPtId)
            if ptId in pointIdSelected:
                pinsToSet.Select(polyId * 4 + polyPtId)

    # Clears the current Pin Selection
    uvwTag.ClearPinSelection()

    # Adds the built selection to the current pin selection
    uvwTag.AddToPinSelection(pinsToSet)

    # Refresh the UV view
    c4d.modules.bodypaint.UpdateMeshUV(False)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
Exemple #7
0
def selectEdges(obj, points, poly, selEdge, se, nbr):
    tuple(selEdge)
    if press_button() == 0:
        n = 2
    else:
        n = 0
    lenEdge = []

    bs = c4d.BaseSelect()
    p = []

    for z in selEdge:
        se.DeselectAll()
        obj.SetSelectedEdges(nbr, se, c4d.EDGESELECTIONTYPE_SELECTION)
        se.Select(z)
        obj.SetSelectedEdges(nbr, se, c4d.EDGESELECTIONTYPE_SELECTION)
        ptToEdg(obj, 1, 0)
        obj.GetPointS()
        selPt = []
        for pt in range(len(points)):  # get selected points
            if obj.GetPointS().IsSelected(pt):
                selPt.append(pt)
        lenEdge.append(
            round(
                (obj.GetPoint(selPt[1]) - obj.GetPoint(selPt[0])).GetLength(),
                n))
        se.DeselectAll()
        obj.SetSelectedEdges(nbr, se, c4d.EDGESELECTIONTYPE_SELECTION)
    for p in poly:
        if round((points[p.a] - points[p.b]).GetLength(), n) in lenEdge:
            indx = nbr.GetPolyInfo(poly.index(p))['edge'][p.FindEdge(p.a, p.b)]
            bs.Select(indx)
            obj.SetSelectedEdges(nbr, bs, c4d.EDGESELECTIONTYPE_SELECTION)
        if round((points[p.b] - points[p.c]).GetLength(), n) in lenEdge:
            indx = nbr.GetPolyInfo(poly.index(p))['edge'][p.FindEdge(p.b, p.c)]
            bs.Select(indx)
            obj.SetSelectedEdges(nbr, bs, c4d.EDGESELECTIONTYPE_SELECTION)
        if p.IsTriangle():
            if round((points[p.c] - points[p.a]).GetLength(), n) in lenEdge:
                indx = nbr.GetPolyInfo(poly.index(p))['edge'][p.FindEdge(
                    p.a, p.c)]
                bs.Select(indx)
                obj.SetSelectedEdges(nbr, bs, c4d.EDGESELECTIONTYPE_SELECTION)
        else:
            if round((points[p.c] - points[p.d]).GetLength(), n) in lenEdge:
                indx = nbr.GetPolyInfo(poly.index(p))['edge'][p.FindEdge(
                    p.c, p.d)]
                bs.Select(indx)
                obj.SetSelectedEdges(nbr, bs, c4d.EDGESELECTIONTYPE_SELECTION)
            if round((points[p.d] - points[p.a]).GetLength(), n) in lenEdge:
                indx = nbr.GetPolyInfo(poly.index(p))['edge'][p.FindEdge(
                    p.d, p.a)]
                bs.Select(indx)
                obj.SetSelectedEdges(nbr, bs, c4d.EDGESELECTIONTYPE_SELECTION)
Exemple #8
0
def MgSelTagForEveryClone(obj):
    doc = c4d.documents.GetActiveDocument()  # Get active Cinema 4D document
    try:  # Try to execute following
        md = mo.GeGetMoData(obj)  # Get MoGraph data
        cnt = md.GetCount()  # Get clone count
        for i in xrange(0, cnt):  # Loop through clones
            tag = c4d.BaseTag(1021338)  # Initialize MoGraph selection tag
            tag[c4d.ID_BASELIST_NAME] = "ms_" + str(i)
            s = c4d.BaseSelect()  # Initialize BaseSelect
            obj.InsertTag(tag, obj.GetLastTag())  # Insert tag to object
            doc.AddUndo(c4d.UNDOTYPE_NEW,
                        tag)  # Add undo command for inserting tag
            s.Select(i)  # Select clone
            mo.GeSetMoDataSelection(tag, s)  # Set selection to tag
    except:  # If something went wrong
        pass  # Do nothing
Exemple #9
0
def main():
    
    #validate object and selectiontag
    if not op:return
    if not op.IsInstanceOf(c4d.Opolygon):return
    tags = op.GetTags()

    #deselect current polygonselection and store a backup to reselect
    polyselection = op.GetPolygonS()
    store = c4d.BaseSelect()
    polyselection.CopyTo(store)
    
    #define the name to search for
    name = "Polygon Selection"
        
        
    #loop through the tags and check if name and type fits
    #if so split 
    t = op.GetFirstTag()
    while t:
        if t.GetType() == c4d.Tpolygonselection:
            if name in t.GetName():

                #select polygons from selectiontag
                tagselection  =  t.GetBaseSelect()
                tagselection.CopyTo(polyselection)

                #split: polygonselection to a new object
                sec = utils.SendModelingCommand(command=c4d.MCOMMAND_SPLIT,
                                  list=[op],
                                  mode=c4d.MODELINGCOMMANDMODE_POLYGONSELECTION,
                                  doc=doc)
             
                if not sec: return
                print sec
                sec[0].InsertAfter(op)
            
            
        t = t.GetNext()
            
    
    store.CopyTo(polyselection)
    c4d.EventAdd()
def main():
    # Checks if there is an active object
    if op is None:
        raise ValueError("op is None, please select one object.")

    # Checks if the active object is a MoGraph Cloner Object
    if not op.CheckType(1018544):
        raise TypeError("Selected object is not a Mograph Cloner Object.")

    # Builds list for clones selection states
    states = [1] * op[c4d.MG_LINEAR_COUNT]

    # Creates new BaseSelect and sets it to states list
    selection = c4d.BaseSelect()
    selection.SetAll(states)

    # Sets clones selection states
    c4d.modules.mograph.GeSetMoDataSelection(op, selection)

    # Pushes an update event to Cinema 4D
    c4d.EventAdd()
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
Exemple #12
0
def main():
    edges = c4d.BaseSelect()
    print edges.Select(0)
Exemple #13
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