Exemplo n.º 1
0
def main():

    # create globally used array of copies
    copies = []
    biesse_layers = []

    # promt convert for biesse

    items = (
        ['convert_to_biesse_layers', 'no', 'yes'],
        ['export_clamex_txt', 'no', 'yes'],
        ['open_after_export', 'no', 'yes'],
    )

    default_values = getDefaultValues()

    options = rs.GetBoolean("conversion options", items, default_values)

    if not options or len(options) < 2:
        print "checkAndExport aborted"
        return

    convert_for_biesse = options[0]
    export_clamex_txt = options[1]
    open_after_export = options[2]

    storeDefaultValues(convert_for_biesse, export_clamex_txt,
                       open_after_export)

    # get objects to export
    objs = rs.GetObjects("select objects to export", 0, True, True)
    if not objs:
        print "checkAndExport aborted"
        return

    rs.EnableRedraw(False)

    # create copies of all block contents
    copies = rs.CopyObjects(objs)

    # explodeblock
    copies = explodeBlock(copies)

    copies = explodeTextObjects(copies)

    # filter objects to only curves and textobjects
    copies = filterObjects(copies)

    # check curves for deviation from c-plane
    if checkCurvePosition(copies):

        clamexdata = None
        if export_clamex_txt:
            clamexdata = extractClamexOrientation(copies)

        # obj properties are lost here
        copies = joinCurves(copies)

        simplify(copies)

        if checkCurveIntegrity(copies):

            # rs.UnselectAllObjects()

            # check curve dir
            if not setCurveDir(copies):
                print "checkAndExport aborted"
                return

            #get left bottom
            rs.EnableRedraw(True)
            selection_origin = rs.GetPoint("Pick export base point")
            rs.EnableRedraw(False)

            # move to origin
            result = moveToOrigin(copies, selection_origin)

            if convert_for_biesse:
                biesse_layers = convertLayers(copies)

            if result:

                # export
                rs.SelectObjects(copies)

                redraw()

                filename = rs.SaveFileName("Save", "dxf Files (*.dxf)|*.dxf||")
                if filename:

                    result = rs.Command('! _-Export "' + filename + '" _Enter',
                                        False)

                    if open_after_export:
                        if os.path.isfile(
                                'C:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe'
                        ):
                            print(
                                '"C:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe" /nosplash /runscript="_-open ""'
                                + filename + '"" _Enter"')
                            Popen(
                                '"C:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe" /nosplash /runscript="_-open ""'
                                + filename + '"" _Enter"')
                        else:
                            rs.MessageBox(
                                'dxf cannot be openened automatically. Could not find:\nC:\Program Files\Rhinoceros 5 (64-bit)\System\Rhino.exe'
                            )

                    filename_stripped, file_extension = os.path.splitext(
                        filename)

                    if clamexdata:
                        with open(filename_stripped + '.txt', 'w') as the_file:
                            the_file.write('')

                        with open(filename_stripped + '.txt', 'a') as the_file:
                            for line in clamexdata:
                                str = 'CLAMEX POSX=%.3f POSY=%.3f RICHTING="%s"\n' % (
                                    line[0], line[1], line[2])
                                print str
                                the_file.write(str)

                    if result: print 'exported succesfully'

    rs.DeleteObjects(copies)

    if biesse_layers and len(biesse_layers) > 0:
        for layer in biesse_layers:
            rs.PurgeLayer(layer)

    rs.EnableRedraw(True)
Exemplo n.º 2
0
import rhinoscriptsyntax as rs
import math

x1 = rs.GetPoint("Pick start point")
x2 = rs.GetPoint("Pick end point")
h = rs.GetPoint("Pick a point above deck")
n = rs.GetInteger("Number of stations", 30, 0)
dx = rs.Distance(x1, x2) / n

#  file for saving shf file
surface = rs.GetObject("Select surface to project onto", rs.filter.surface)
filter = "Text File (*.shf)|*.shf|All Files (*.*)|*.*||"
filename = rs.SaveFileName("Save point coordinates as", filter)
###

file = open(filename, "w")
file.write("hull \n")

for i in range(1, n):
    flg_stn = 1
    c1 = (x1[0] - i * dx, x1[1], x1[2])
    c2 = (x1[0] - i * dx, x1[1], h[2])
    curp1 = rs.AddPoint(c1)
    curp2 = rs.AddPoint(c2)
    curl = rs.AddLine(curp1, curp2)
    rs.DeleteObject(curp1)
    rs.DeleteObject(curp2)
    lstCur = rs.ProjectCurveToSurface(curl, surface, (0, 1, 0))
Exemplo n.º 3
0
#Python Workshop Lesson:15
#http://www.designalyze.com/int2pythonscripting15_ExportPts2CSV

#Export Points to CSV

import rhinoscriptsyntax as rs

#Select our points
pts = rs.GetObjects("Select Points for CSV Export", 1)

#create a filename variable
filename = rs.SaveFileName("Save CSV file", "*.csv||", None, "ptExport", "csv")

#open the file for writing
file = open(filename, 'w')

#create and write a headerline for our CSV
headerline = "X,Y,Z,R,G,B\n"
file.write(headerline)

#print pts
for pt in pts:
    ptCoord = rs.PointCoordinates(pt)
    x = ptCoord[0]
    y = ptCoord[1]
    z = ptCoord[2]
    color = rs.ObjectColor(pt)
    print color
    r = color.R
    g = color.G
    b = color.B
Exemplo n.º 4
0
    def slice(self):

        print("Slicing starts")
        print("It may take a long time")
        deleteItem = []

        self.gcoder.initGcode()

        tmpText = ""

        multiplier = float(self.gcoder.getLayerHeight() *
                           math.cos(math.radians(self.angleOfSurface)))

        print('multiplier')
        print(multiplier)

        #layer by layer
        layer = 0
        for layer in range(int(self.distancePrinting / multiplier) + 1):
            #while(True):

            tmpText = "; layer " + str(layer) + "\n"
            #init evalue
            tmpText += "G92 E0\n"
            self.gcoder.addGcode(tmpText)
            self.gcoder.initEValue()

            nextVec = (0, 0, float(multiplier * layer))
            slicer = rs.CopyObject(self.sliceSurface, nextVec)

            slicedCurves = rs.IntersectBreps(self.addtiveObj, slicer)
            #deleteItem.append(slicedCurves)

            rs.DeleteObject(slicer)

            if slicedCurves == None:
                print('slicing done')
                self.gcoder.finishGcode()
                fileN = rs.SaveFileName(
                    "Output file",
                    "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|",
                    None, self.fileName)
                self.gcoder.outputFile()

                return

            #slicedCurve one by one

            for slicedCurve in slicedCurves:

                self.makeGcodeFromSlicedCurve(slicedCurve, layer, nextVec,
                                              multiplier)

            layer += 1

            rs.DeleteObjects(slicedCurves)

        self.gcoder.finishGcode()
        fileN = rs.SaveFileName(
            "Output file",
            "G-Code Files (*.gcode)|*.gcode|All Files (*.*)|*.*|")
        self.gcoder.outputFile(fileN)

        return True
Exemplo n.º 5
0
import rhinoscriptsyntax as rs

curves=rs.GetObjects('select Lines',4)
filename = rs.SaveFileName()
file = open(filename, "w")

for curve in curves:
    layername=rs.ObjectLayer(curve)
    points = rs.CurvePoints(curve)
    file.write(layername+" ")
    for pt in points:
        file.write(str(pt[0])+","+str(pt[1])+" ")
    file.write("\n")
file.close()
Exemplo n.º 6
0
def write_G(path, par):
    #
    # G code output
    #

    # get variables
    sfeed = par['feedrate_cut']
    efeed = par['feedrate_engrave']
    sspindle = par['intensity_cut']
    e_intensity = par['intensity_engrave']
    tolerance = par['curve_tolerance']
    a_tolerance = par['curve_angle_tolerance']

    filename = rs.SaveFileName("Save", "Toolpath Files (*.nc)|*.nc||",
                               "/users/timcastelijn/documents")
    if not filename: return

    file = open(filename, 'w')

    # write header
    file.write("G90\n")  # absolute positioning
    file.write("F" + str(sfeed) + "\n")  # feed rate
    file.write("S" + str(sspindle) + "\n")  # spindle speed
    file.write("M08\n")  # coolant on
    for curve in path:

        # fast move to path start
        pt = rs.CurveStartPoint(curve)
        file.write("G00 X%0.4f" % pt.X + " Y%0.4f" % pt.Y + "\n")
        file.write("M03\n")  # spindle on clockwise

        # change feedrate for engraving
        if (rs.ObjectLayer(curve) == "engrave"):
            file.write("F%0.1f" % efeed + "\n")
            file.write("S%0.1f" % e_intensity + "\n")
        else:
            file.write("F%0.1f" % sfeed + "\n")
            file.write("S%0.1f" % sspindle + "\n")

        # detect type of curve for different G-codes
        if (rs.IsPolyline(curve)) or rs.IsLine(curve):

            points = rs.CurvePoints(curve)
            for pt in points:
                file.write("G01 X%0.4f" % pt.X + " Y%0.4f" % pt.Y + "\n")

        elif rs.IsArc(curve):
            normal = rs.CurveTangent(curve, 0)

            # get curvepoints
            startpt = rs.CurveStartPoint(curve)
            endpt = rs.CurveEndPoint(curve)
            midpt = rs.ArcCenterPoint(curve)

            # calc G2/G3 parameters
            x = endpt.X
            y = endpt.Y
            i = -startpt.X + midpt.X
            j = -startpt.Y + midpt.Y

            # make a distinction between positive and negative direction
            if ((normal[1] > 0) and
                (startpt.X > midpt.X)) or ((normal[1] < 0) and
                                           (startpt.X < midpt.X) or
                                           (normal[1] == 0 and
                                            (normal[0] == 1 or normal[0] == -1)
                                            and startpt.X == midpt.X)):
                #                file.write(";positive ARC ccw \n")
                file.write("G03 X%0.4f" % x + " Y%0.4f" % y + " I%0.4f" % i +
                           " J%0.4f" % j + "\n")
            else:
                #                file.write(";negative ARC cw \n")
                file.write("G02 X%0.4f" % x + " Y%0.4f" % y + " I%0.4f" % i +
                           " J%0.4f" % j + "\n")

        else:
            print "curve detected, subdiv needed"

            #rs.ConvertCurveToPolyline(segment,angle_tolerance=5.0, tolerance=0.01, delete_input=False)
            polyLine = rs.ConvertCurveToPolyline(curve, a_tolerance, tolerance)
            points = rs.CurvePoints(polyLine)

            # insert division points as line
            for pt in points:
                file.write("G01 X%0.4f" % pt.X + " Y%0.4f" % pt.Y + "\n")
            # remove objects after use
            rs.DeleteObjects(polyLine)

        file.write("M05\n")  # spindle stop

    file.write("G00 X0.0000 Y0.0000 F1000\n")
    # file.write("M09\n") # coolant off
    # file.write("M30\n") # program end and reset
    file.close()

    rs.MessageBox("file succesfully saved to: " + filename +
                  ", with the following parameters:\n" +
                  "cut feedrate: %0.1f" % sfeed + "\n" +
                  "cut intensity: %0.1f" % sspindle + "\n" +
                  "engrave feedrate: %0.1f" % efeed + "\n" +
                  "engrave intensity: %0.1f" % e_intensity + "\n")
Exemplo n.º 7
0
# objs = rs.GetObjects('select objects', rs.filter.polysurface, preselect=True)
objs = rs.GetObjects('select objects', preselect=True)


def createObjDict(obj):
    # rs.SetUserText(obj, 'objdict')
    objkeys = [x for x in rs.GetUserText(obj) if "BakeName" not in x]
    objvals = map(lambda x: rs.GetUserText(obj, x), objkeys)
    return dict(zip(objkeys, objvals))
    # rs.SetUserText(obj, 'objdict', dict(zip(objkeys, objvals)))


dataStore = map(createObjDict, objs)

filter = "JSON File (*.json)|*.json|All Files (*.*)|*.*||"
filename = rs.SaveFileName("Save JSON file as", filter)

# If the file name exists, write a JSON string into the file.
if filename:
    # Writing JSON data
    with open(filename, 'w') as f:
        json.dump(dataStore, f)

# def getObjDict(obj):
#     userstr = rs.GetUserText(obj, "objdict")

#     objdict = ast.literal_eval(userstr)
#     return objdict

# def func(x):
#     # trp.setValueByLayer(x,schema['keys'])
Exemplo n.º 8
0
    def AddCurveToDocument(self):
        pad = 5

        if self.box1:
            center_point = Rhino.Geometry.Point3d(-64, 64, 0)
            height_point = Rhino.Geometry.Point3d(-64, 64, 1)
            zaxis = height_point - center_point
            plane = Rhino.Geometry.Plane(center_point, zaxis)
            rect1 = Rhino.Geometry.Rectangle3d(plane, self.data.depth,
                                               self.data.height)
            scriptcontext.doc.Objects.AddRectangle(rect1)
            scriptcontext.doc.Objects.AddBox(self.box1)

        if self.box2:
            center_point = Rhino.Geometry.Point3d(-64 + self.data.depth + pad,
                                                  64, 0)
            height_point = Rhino.Geometry.Point3d(-64 + self.data.depth + pad,
                                                  64, 1)
            zaxis = height_point - center_point
            plane = Rhino.Geometry.Plane(center_point, zaxis)
            rect2 = Rhino.Geometry.Rectangle3d(plane, self.data.depth,
                                               self.data.height)
            scriptcontext.doc.Objects.AddRectangle(rect2)
            scriptcontext.doc.Objects.AddBox(self.box2)

        if self.box3:
            center_point = Rhino.Geometry.Point3d(
                -64 + self.data.depth * 2 + pad * 2, 64, 0)
            height_point = Rhino.Geometry.Point3d(
                -64 + self.data.depth * 2 + pad * 2, 64, 1)
            zaxis = height_point - center_point
            plane = Rhino.Geometry.Plane(center_point, zaxis)
            rect3 = Rhino.Geometry.Rectangle3d(plane, self.data.width,
                                               self.data.depth)
            scriptcontext.doc.Objects.AddRectangle(rect3)
            scriptcontext.doc.Objects.AddBox(self.box3)

        if self.box4:
            center_point = Rhino.Geometry.Point3d(
                -64 + self.data.depth * 2 + pad * 3 + self.data.width, 64, 0)
            height_point = Rhino.Geometry.Point3d(
                -64 + self.data.depth * 2 + pad * 3 + self.data.width, 64, 1)
            zaxis = height_point - center_point
            plane = Rhino.Geometry.Plane(center_point, zaxis)
            rect4 = Rhino.Geometry.Rectangle3d(plane, self.data.width,
                                               self.data.seat_height)
            scriptcontext.doc.Objects.AddRectangle(rect4)
            scriptcontext.doc.Objects.AddBox(self.box4)

        scriptcontext.doc.Views.Redraw()

        filter = "SBP File (*.sbp)|*.sbp||"
        filename = rs.SaveFileName("Save point coordinates as", filter)
        if filename == None: return

        with open(filename, 'w') as f:
            for i in range(4):
                pnt = rect1.Corner(i)
                f.write('M3,{0},{1},{2}\n'.format(pnt.X, pnt.Y, pnt.Z))

            for i in range(4):
                pnt = rect2.Corner(i)
                f.write('M3,{0},{1},{2}\n'.format(pnt.X, pnt.Y, pnt.Z))

            for i in range(4):
                pnt = rect3.Corner(i)
                f.write('M3,{0},{1},{2}\n'.format(pnt.X, pnt.Y, pnt.Z))

            for i in range(4):
                pnt = rect4.Corner(i)
                f.write('M3,{0},{1},{2}\n'.format(pnt.X, pnt.Y, pnt.Z))
Exemplo n.º 9
0
def ExportDialog():
    filter = "(JSON Files)|*.json|All Files (*.*)|*.*||"
    filename = rs.SaveFileName("Save JSON Sensors...", filter)
    return filename
Exemplo n.º 10
0
 def OnFileSaveAsClick(self, sender, e):
     newFile = rs.SaveFileName("Save", "YAML Files (*.yaml)|*.yaml||")
     dt.SaveProjectLevelData(self.grid.DataStore, self.databaseFile, newFile, 0)
     self.databaseFile = newFile
     rs.SetDocumentData('PCPA', 'Project_Database', self.databaseFile)
     self.UpdateFileLabel(newFile)
Exemplo n.º 11
0
    return (noteObjs)


# AUTOSELECT OBJECTS
noteObjs = getNotes()
print(noteObjs, "NOTES")
groupSet = []
# filter out objects not in groups
for noteObj in noteObjs:
    if rs.ObjectGroups(noteObj):
        groupSet.append(noteObj)

groupSet = list(set([rs.ObjectGroups(x)[0] for x in groupSet]))
###
print(groupSet)
filename = rs.SaveFileName("Save CSV File", "*.csv", None, "areaExport", "csv")

file = open(filename, 'w')

headerline = "Area Name, Area in SF\n"
file.write(headerline)

returnList = []

for groupObj in groupSet:
    objs = rs.ObjectsByGroup(groupObj)
    for obj in objs:
        print(rs.TextObjectText(obj))
        if rs.ObjectName(obj) == "Area Text":
            areaText = rs.TextObjectText(obj)
        elif rs.ObjectName(obj) == "Name Text":