Exemple #1
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
Exemple #2
0
 def Command(self, id, msg):
     if id in [self.BTN_CONVERT_COPY, self.BTN_CONVERT]:
         string = self.GetString(self.EDT_SOURCE).decode("utf-8")
         output = unicode_refreplace(string)
         self.SetString(self.EDT_OUTPUT, output)
     if id == self.BTN_CONVERT_COPY:
         c4d.CopyStringToClipboard(output)
     return True
Exemple #3
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()
def main():
    o = doc[CONTAINER_ORIGIN]
    pos = op.GetMg().off
    mp = op.GetMp()
    rad = op.GetRad()

    centre = o + pos + mp

    c4d.CopyStringToClipboard(str(centre.x - rad.x))
    print('min.x :')
    print(str(centre.x - rad.x))
    print('min.y :')
    print(str(centre.z - rad.z))
    print('max.x :')
    print(str(centre.x + rad.x))
    print('max.y :')
    print(str(centre.z + rad.z))
    def Command(self, id, msg):

        if id == self.BTON_ORIGIN:
            doc = c4d.documents.GetActiveDocument()
            usdata = doc[c4d.DOCUMENT_DOCUNIT]
            scale, unit = usdata.GetUnitScale()
            if  unit!= c4d.DOCUMENT_UNIT_M:
                rep = c4d.gui.QuestionDialog(self.TXT_NOT_METER)
                if not rep : return True
                unit = c4d.DOCUMENT_UNIT_M
                usdata.SetUnitScale(scale, unit)
                doc[c4d.DOCUMENT_DOCUNIT] = usdata
            doc[CONTAINER_ORIGIN] = ORIGIN_DEFAULT
            c4d.EventAdd()

        # DEPUIS L'OBJET ACTIF
        # TODO : sélection multiple
        if id == self.BTON_FROM_OBJECT:
            doc = c4d.documents.GetActiveDocument()
            origine = doc[CONTAINER_ORIGIN]
            if not origine:
                c4d.gui.MessageDialog(self.TXT_NO_ORIGIN)
                return True
            op = doc.GetActiveObjects(0)
            if not op:
                c4d.gui.MessageDialog(self.TXT_NO_SELECTION)
                return True
            if len(op) > 1:
                c4d.gui.MessageDialog(self.TXT_MULTI_SELECTION)
                return True
            obj = op[0]

            mini, maxi = empriseObject(obj, origine)
            self.SetMeter(self.N_MAX, maxi.z)
            self.SetMeter(self.N_MIN, mini.z)
            self.SetMeter(self.E_MIN, mini.x)
            self.SetMeter(self.E_MAX, maxi.x)

        # DEPUIS LA VUE DE HAUT
        if id == self.BTON_FROM_VIEW:
            doc = c4d.documents.GetActiveDocument()
            origine = doc[CONTAINER_ORIGIN]
            if not origine:
                c4d.gui.MessageDialog(self.TXT_NO_ORIGIN)
                return True

            bd = doc.GetActiveBaseDraw()
            camera = bd.GetSceneCamera(doc)
            if not camera[c4d.CAMERA_PROJECTION] == c4d.Ptop:
                c4d.gui.MessageDialog(self.TXT_NOT_VIEW_TOP)
                return True

            mini, maxi, larg, haut = empriseVueHaut(bd, origine)
            self.SetMeter(self.N_MAX, maxi.z)
            self.SetMeter(self.N_MIN, mini.z)
            self.SetMeter(self.E_MIN, mini.x)
            self.SetMeter(self.E_MAX, maxi.x)

        # COPIER LES VALEURS (et print)
        if id == self.BTON_COPY_ALL:
            n_max = self.GetFloat(self.N_MAX)
            n_min = self.GetFloat(self.N_MIN)
            e_max = self.GetFloat(self.E_MAX)
            e_min = self.GetFloat(self.E_MIN)
            txt = "{0},{1},{2},{3}".format(e_min,n_min,e_max,n_max)
            print(txt)
            c4d.CopyStringToClipboard(txt)

        # CREER UN PLAN
        if id == self.BTON_PLANE:

            mini, maxi = self.getBbox()

            if mini == c4d.Vector(0) or maxi == c4d.Vector(0):
                return True
            doc = c4d.documents.GetActiveDocument()
            doc.StartUndo()
            origine = doc[CONTAINER_ORIGIN]
            if not origine:
                origine = (mini + maxi) / 2
                # pas réussi à faire un undo pour le doc !
                doc[CONTAINER_ORIGIN] = origine

            plane = self.planeFromBbox(mini, maxi, origine)
            doc.AddUndo(c4d.UNDOTYPE_NEW, plane)
            doc.InsertObject(plane)
            doc.EndUndo()
            c4d.EventAdd()

        # EXPORT SHAPEFILE
        if id == self.BTON_EXPORT_SHP:
            mini, maxi = self.getBbox()
            if mini == c4d.Vector(0) or maxi == c4d.Vector(0):
                return True

            bbox2shapefile(mini, maxi)

        # BOUTONS COPIE COORDONNEEs
        if id == self.BTON_N_MIN:
            c4d.CopyStringToClipboard(str(self.GetFloat(self.N_MIN)))

        if id == self.BTON_N_MAX:
            c4d.CopyStringToClipboard(self.GetFloat(self.N_MAX))

        if id == self.BTON_E_MIN:
            c4d.CopyStringToClipboard(str(self.GetFloat(self.E_MIN)))

        if id == self.BTON_E_MAX:
            c4d.CopyStringToClipboard(str(self.GetFloat(self.E_MAX)))


        #AFFICHER RASTER
        if id == self.BTON_DISPLAY_RASTER:
            doc = c4d.documents.GetActiveDocument()

            if verifDocSaved(doc):
                origine = doc[CONTAINER_ORIGIN]
                bd = doc.GetActiveBaseDraw()
                camera = bd.GetSceneCamera(doc)
                mini, maxi, larg, haut = empriseVueHaut(bd, origine)
                path_doc = doc.GetDocumentPath()

                fn_img = getFileName(path_doc, ext='.jpg', prefixe = 'raster')

                if api_raster.extract(self.url,mini,maxi,larg,haut,fn_img, calage = False):
                    modifDisplay(bd,fn_img, mini,maxi,origine)
            #vue_haut.main()

        #EXTRAIRE RASTER
        if id == self.BTON_EXTRACT_RASTER:
            print('BTON_EXTRACT_RASTER')

        #EXTRAIRE MNA
        if id == self.BTON_EXTRACT_MNA:
            mini,maxi = self.getBbox()
            mnt.main(mini.x,mini.z, maxi.x,maxi.z)

        #CHOIX RASTER
        if id == self.ID_COMBO_FAMILLE:
            self.majComboServer()

        if id == self.ID_COMBO_SERVER:
            self.url = self.getURL()
            print(self.url)

        return True