Пример #1
0
def ScaleBarCreation(fs, text_h, drawing):
    # lenght of 1 cm scalebar
    fs1 = fs / 100
    drawing.add_layer('scale_bar', color=7)
    # insertion point of scale bar
    x0 = 10.
    y0 = -20.
    z0 = 0.
    P0 = (x0, y0, z0)
    P1 = (x0, y0 + (fs1 / 20.), z0)
    P2 = ((x0 + fs1), y0, z0)
    P3 = ((x0 + fs1), y0 + (fs1 / 20.), z0)

    line1 = dxf.line(P0, P1)
    line1['layer'] = 'scale_bar'
    drawing.add(line1)

    line2 = dxf.line(P0, P2)
    line2['layer'] = 'scale_bar'
    drawing.add(line2)

    line3 = dxf.line(P2, P3)
    line3['layer'] = 'scale_bar'
    drawing.add(line3)

    text = dxf.text('0', P1, height=text_h)
    text['layer'] = 'scale_bar'
    drawing.add(text)

    text = dxf.text('1 cm', P3, height=text_h)
    text['layer'] = 'scale_bar'
    drawing.add(text)
Пример #2
0
    def getLabelDxf(self, for_prime_center=True):
        x = self.getPosition()[0] - self.getWidth()/2
        y = self.getPosition()[1] - self.getHeight()/2
        width = self.getWidth()
        height = self.getHeight()

        # if self.isCoupage() and (height > width) and height <= self.getGridWidth():
        #     # rotate when more optimal
        #     width = self.getHeight()
        #     height = self.getWidth()

        if for_prime_center == True:
            x = Helper.toMillimeters(x)
            y = Helper.toMillimeters(y)
            width = Helper.toMillimeters(width)
            height = Helper.toMillimeters(width)

            text = dxf.text(str(self.getClientName()), (y, x + width), 100.0, rotation=0)
            
            text['layer'] = 'TEXT'
            text['color'] = '7'
        else:
            text = dxf.text(str(self.getClientName()), (x, y + height), 10.0, rotation=0)

            text['layer'] = 'TEXT'
            text['color'] = '7'
        
        return text
Пример #3
0
def main():
    dwg = dxf.drawing('paperspace.dxf')
    # IMPORTANT: DXF R12 supports only 1 paperspace

    # adding entities to dwg.modelspace forces the 'paper_space' attribute to be 0
    dwg.modelspace.add(dxf.text('Text1 in modelspace'))
    # adding entities to dwg.paperspace forces the 'paper_space' attribute to be 1
    dwg.paperspace.add(dxf.text('Text in paperspace'))
    # adding entities with dwg.add doen't change the 'paper_space' attribute,
    # which is 0 by default == modelspace
    dwg.add(dxf.text('Text2 also in modelspace', (0, 2)))
    dwg.add(dxf.text('Text2 also in paperspace', (0, 2), paper_space=1))

    dwg.save()
Пример #4
0
def main():
    dwg = dxf.drawing('paperspace.dxf')
    # IMPORTANT: DXF R12 supports only 1 paperspace

    # adding entities to dwg.modelspace forces the 'paper_space' attribute to be 0
    dwg.modelspace.add(dxf.text('Text1 in modelspace'))
    # adding entities to dwg.paperspace forces the 'paper_space' attribute to be 1
    dwg.paperspace.add(dxf.text('Text in paperspace'))
    # adding entities with dwg.add doen't change the 'paper_space' attribute,
    # which is 0 by default == modelspace
    dwg.add(dxf.text('Text2 also in modelspace', (0, 2)))
    dwg.add(dxf.text('Text2 also in paperspace', (0, 2), paper_space=1))

    dwg.save()
 def generate_text(self, drawing):
     textheight = self.module/2
     linespacing = self.module*1
 
     drawing.add(dxf.text("{} teeth".format(self.teeth),alignpoint=(0, linespacing/2),
                          height=textheight, halign=dxfwrite.CENTER, valign=dxfwrite.CENTER,
                          layer="geartext"))
     if self.metric:
         drawing.add(dxf.text("{}mm module".format(self.module), alignpoint=(0,-linespacing/2),
                              height=textheight, halign=dxfwrite.CENTER, valign=dxfwrite.CENTER,
                              layer="geartext"))
     else:
         drawing.add(dxf.text("{}/in Dp".format(self.diametricpitch), alignpoint=(0,-linespacing/2),
                              height=textheight, halign=dxfwrite.CENTER, valign=dxfwrite.CENTER,
                              layer="geartext"))
Пример #6
0
Файл: g2.py Проект: soldocode/g2
 def toDXF(self):
     output = io.StringIO()
     drawing = dxf.drawing('drawing.dxf')
     for id in self.Scene:
         if self.Scene[id]['Class'] == 'PATH':
             path = self.Scene[id]['Path']
             for i in range(0, len(path.geometries)):
                 geo = path.geo(i)
                 geo.writeDXF(drawing, self.Scene[id]['Position'])
         if self.Scene[id]['Class'] == 'GEO':
             geo = self.Scene[id]['Geo']
             geo.writeDXF(drawing, self.Scene[id]['Position'])
         if self.Scene[id]['Class'] == 'TXT':
             text = dxf.text(
                 self.Scene[id]['Txt'],
                 height=self.Scene[id]['Height'],
             )
             text['insert'] = (self.Scene[id]['Position'][0],
                               self.Scene[id]['Position'][1])
             text['layer'] = 'TEXT'
             text['color'] = 7
             drawing.add(text)
     drawing.save_to_fileobj(output)
     dxf_result = output.getvalue()
     return dxf_result
Пример #7
0
def color_square(x, y, color=None, bgcolor=None):
    if color:
        name = color_name(color)
    if bgcolor:
        name = color_name(bgcolor)
    drawing.add(dxf.rectangle((x, y) , 2, 2, color=color, bgcolor=bgcolor))
    drawing.add(dxf.text(name, (x, y-0.4), height=0.18))
Пример #8
0
    def draw(s, outfile):

        # Create image
        drawing = dxf.drawing(s.OUTFILE + outfile)
        drawing.add_layer('layer', color=1)

        # Draw text
        if s.includeText:
            text = ''
            text += ''.join(map(str, s.startBand))
            text += '-'
            text += ''.join(map(str, s.code))
            text += '-'
            text += ''.join(map(str, s.stopBand))
            drawing.add(dxf.text(text, height=s.unitWidth))

        # Initial offset
        xOffset = (s.size[0] - s.barWidth) / 2
        yOffset = (s.size[1] - s.barcodeLen) / 2

        # Draw notches
        for d in s.digits:
            newOffset = s.drawBar(drawing, d, xOffset, yOffset)
            yOffset = newOffset[1]

        # Draw final notch
        s.drawNotch(drawing, xOffset, yOffset)

        drawing.save()
Пример #9
0
def writeTextLeft(draw, txt, px0, py0, size, colorTextt, layerTxt,
                  angRotation):
    text = dxf.text(txt, (px0, py0), height=size, rotation=angRotation)
    text['layer'] = layerTxt
    text['color'] = colorTextt
    #text['alignpoint']=alignPx,alignPy
    draw.add(text)
Пример #10
0
def color_square(x, y, color=None, bgcolor=None):
    if color:
        name = color_name(color)
    if bgcolor:
        name = color_name(bgcolor)
    drawing.add(dxf.rectangle((x, y), 2, 2, color=color, bgcolor=bgcolor))
    drawing.add(dxf.text(name, (x, y - 0.4), height=0.18))
Пример #11
0
def generate_dxf(root_path, session_id, lines_dict, sheet_length):
    x_offset = int(sheet_length * 1.1)
    y_offset = 30
    keys = lines_dict.keys()

    drawing = dxf.drawing(root_path + "/data/" + session_id + '/cutout.dxf')
    drawing.add_layer('LINES')

    for i in range(len(keys)):
        key = keys[i]
        for line in lines_dict[key]:
            start = (line[0][0] + x_offset * i, line[0][1] + y_offset)
            end = (line[1][0] + x_offset * i, line[1][1] + y_offset)
            drawing.add(dxf.line(start, end, color=7, layer='LINES'))

    drawing.add_layer('TEXTLAYER', color=2)

    for i in range(len(keys)):
        key = keys[i]
        drawing.add(
            dxf.text(key,
                     insert=(i * x_offset, 0),
                     layer='TEXTLAYER',
                     height=25))

    drawing.add_vport('*ACTIVE',
                      upper_right=(100, 100),
                      center_point=(50, 50),
                      grid_spacing=(1, 1),
                      snap_spacing=(1, 1),
                      aspect_ratio=20)
    drawing.save()
Пример #12
0
 def render_contour(self,
                    drawing,
                    contour_lines,
                    compute_point_fn,
                    layer_postfix=""):
     # loop through the contour lines adding them
     for contour_line in contour_lines:
         line = contour_line.get("vertices")
         contour_detail = {"layer": "Contour"}
         # get the contour line settings and apply them
         if self.settings["job"].get("contours") and self.settings["job"][
                 "contours"][contour_line.get("type")]:
             contour_settings = self.settings["job"]["contours"][
                 contour_line.get("type")]
             for x in ["color", "thickness", "linetype", "layer"]:
                 if contour_settings.get(x):
                     contour_detail[x] = contour_settings.get(x)
         contour_detail["layer"] = self.filter_layer_name(
             str(contour_detail["layer"]) + layer_postfix)
         if contour_line.get("type") == "major":
             drawing.add(
                 dxf.text(line[0][1],
                          compute_point_fn(line[len(line) / 2]),
                          height=0.5,
                          rotation=-90,
                          **contour_detail))
         contour = dxf.polyline(**contour_detail)
         contour.add_vertices([compute_point_fn(p) for p in line])
         drawing.add(contour)
Пример #13
0
def writeText(draw, txt, alignpx, alignpy, size, colorTextt, layerTxt,
              angRotation):
    text = dxf.text(txt, halign=CENTER, alignpoint=(alignpx, alignpy))
    text['layer'] = layerTxt
    text['color'] = colorTextt
    text['height'] = size
    draw.add(text)
Пример #14
0
 def draw(self, drawing, offset=Point(0, 0)):
   offset = offset.plus(self.base)
   if self.text is not None:
     drawing.add(dxf.text(self.text, insert=self.textOffset.plus(offset).toDxf(), height=5, halign=const.CENTER))
   for side in self.geom:
     side.draw(drawing, offset)
   for child in self.children:
     child.draw(drawing, offset)
Пример #15
0
def engrave_text(drawing, x, y):
    drawing.add(
        dxf.text('Cuffelink.com',
                 halign=dxfwrite.const.CENTER,
                 valign=dxfwrite.const.MIDDLE,
                 alignpoint=(x, y + 2.5),
                 height=2,
                 layer='ENGRAVE',
                 color=2))
Пример #16
0
def draw_sizing_refs():
    from dxfwrite import DXFEngine as dxf
    from dxfwrite.const import LEFT, TOP

    d.dwg.add(dxf.rectangle(
        insert=(part_padding, -part_padding - 10.0),
        width=10.0,
        height=10.0,
        layer="LABELS",
    ))
    d.dwg.add(dxf.text(
        "10mm ref.",
        halign=LEFT,
        valign=TOP,
        alignpoint=((part_padding * 2.0) + 10.0, -part_padding),
        height=5,
        layer="LABELS",
    ))

    inch = 25.4

    d.dwg.add(dxf.rectangle(
        insert=(part_padding, -part_padding - 40.4),
        width=inch,
        height=inch,
        layer="LABELS",
    ))
    d.dwg.add(dxf.text(
        "1 inch ref. (%0.2fmm)" % inch,
        halign=LEFT,
        valign=TOP,
        alignpoint=((part_padding * 2.0) + inch, -part_padding - 40.4 + inch),
        height=5,
        layer="LABELS",
    ))
    d.dwg.add(dxf.text(
        "(10mm ref. is authoritative)",
        halign=LEFT,
        valign=TOP,
        alignpoint=((part_padding * 2.0) + inch, -part_padding - 40.4 + (inch / 2)),
        height=5,
        layer="LABELS",
    ))
Пример #17
0
def engrave_text(drawing, x, y, text='Cuffelink.com'):
    drawing.add(
        dxf.text(text,
                 halign=dxfwrite.const.CENTER,
                 valign=dxfwrite.const.MIDDLE,
                 alignpoint=(x, y),
                 height=1.8,
                 rotation=90,
                 layer='ENGRAVECUT',
                 color=3))
Пример #18
0
 def text(self, txt, p0, height, layer=None):
     if self.enable:
         if self.d is not None:
             if layer is None:
                 layer = self.lText
             else:
                 if not layer in self.definedLayers:
                     self.definedLayers[layer] = True
                     self.d.add_layer(layer, color=self.color, lineweight=0)
             self.d.add(dxf.text(txt, p0, height, layer=layer))
Пример #19
0
def serial_number(drawing, x, y, text=""):
    serial = get_git_revision_short_hash()
    drawing.add(
        dxf.text(serial,
                 halign=dxfwrite.const.CENTER,
                 valign=dxfwrite.const.MIDDLE,
                 alignpoint=(x, y + 2.5),
                 height=2,
                 layer='ENGRAVE',
                 color=2))
    if (text != ""):
        drawing.add(
            dxf.text(text,
                     halign=dxfwrite.const.CENTER,
                     valign=dxfwrite.const.MIDDLE,
                     alignpoint=(x, y - 2.5),
                     height=2,
                     layer='ENGRAVE',
                     color=2))
Пример #20
0
def draw_z(drawing, line, measurement):
    x = line.distance_to_midpoint(measurement.point)
    y = measurement.z1 - 0.2

    text = "({x:.2f}, z1={y:.2f})".format(x=x, y=measurement.z1)

    drawing.add(dxf.text(
            text,
            insert=(x, y),
            height=0.1))
Пример #21
0
def DatesLabelsCreation(layer_name, i, text_h, drawing):
    # insert point of dates labels
    x0 = 10
    y0 = -20
    z0 = 0
    # vertical spacing of dates labels
    delta_y = 0.4

    text = dxf.text(layer_name, (x0, y0 - (delta_y * i), z0), height=text_h)
    text['layer'] = layer_name
    drawing.add(text)
Пример #22
0
def PointsLabels(drawing, text_h, df_coord_zero):

    for nome_pto in df_coord_zero.index:
        x = df_coord_zero['E'].loc[nome_pto]
        y = df_coord_zero['N'].loc[nome_pto]
        z = df_coord_zero['H'].loc[nome_pto]

        drawing.add_layer('points_names', color=7)
        text = dxf.text(nome_pto, (x, y, z), height=text_h)
        text['layer'] = 'points_names'
        drawing.add(text)
Пример #23
0
def x_axis_label(x, text):
    from dxfwrite import DXFEngine as dxf
    from dxfwrite.const import LEFT, TOP
    d.dwg.add(dxf.text(
        text,
        halign=LEFT,
        valign=TOP,
        alignpoint=(x  + part_padding, -part_padding),
        height=8,
        layer="LABELS",
    ))
Пример #24
0
def create_layout(dwg):
    # For viewport entities the paper_space parameter is 1 by default, so you
    # can use the drawing.add method for placing the viewports, but adding to
    # Drawing.paperspace works also.
    #
    # Define viewports in paper space:
    # center_point, width and height defines the viewport in paper space.
    # view_center_point and view_height defines the area in model space
    # which is displayed in the viewport.
    dwg.add(dxf.viewport(center_point=(2.5, 2.5), width=5, height=5,
                         view_center_point=(7.5, 7.5),
                         view_height=10))
    # scale is calculated by: height of model space (view_height=10) / height of viewport (height=5)
    dwg.paperspace.add(
        dxf.text("View of Rectangle Scale=1:2", insert=(0, 5.2),
                 height=0.18, color=1))

    # adding to Drawing.paperspace works also
    dwg.paperspace.add(
        dxf.viewport(center_point=(8.5, 2.5), width=5, height=5,
                     view_center_point=(10, 5),
                     view_height=25))
    dwg.paperspace.add(dxf.text("View of Circle Scale=1:5", insert=(6, 5.2),
                                height=0.18, color=1))

    dwg.add(dxf.viewport(center_point=(14.5, 2.5), width=5, height=5,
                         view_center_point=(12.5, 7.5),
                         view_height=5))

    dwg.paperspace.add(
        dxf.text("View of Triangle Scale=1:1", insert=(12, 5.2),
                 height=0.18, color=1))

    dwg.add(dxf.viewport(center_point=(7.5, 10), width=15, height=7.5,
                         view_center_point=(10, 6.25),
                         view_height=7.5))
    dwg.paperspace.add(dxf.text("Overall View Scale=1:1", insert=(0, 14),
                                height=0.18, color=1))

    dwg.add(dxf.viewport(center_point=(16, 13.5), width=0.3, height=0.15,
                         view_center_point=(10, 6.25), view_height=7.5))
    # scale = 7.5/0.15 = 50
    dwg.paperspace.add(
        dxf.text("Scale=1:50", halign=CENTER, alignpoint=(16, 14),
                 height=0.18, color=1))

    dwg.add(dxf.viewport(center_point=(16, 10), width=4, height=4,
                         view_target_point=(40, 40, 0),
                         # view_direction_vector determines the view direction,
                         # and it just a VECTOR, the view direction is the location
                         # of view_direction_vector to (0, 0, 0)
                         view_direction_vector=(-1, -1, 1),
                         # now we have a view plane (viewport) with its origin (0, 0) in
                         # the view target point and view_center_point shifts
                         # the center of the viewport
                         view_center_point=(0, 0), view_height=30))

    dwg.paperspace.add(
        dxf.text("Viewport to 3D Mesh", halign=CENTER, alignpoint=(16, 12.5),
                 height=0.18, color=1))
Пример #25
0
def make_tables_horizontal(dwg, dfs, pos_x, pos_y, comma_idx=None, reverse=True, scale_factor=2.8):
    # dwg: drwaings
    # dfs: datafram dictionary
    # lst_colwidth: list fo column width
    # lst_col_name: list of column name
    # pos_x: x position of tabel
    # pos_y: y posion of table
    # comma_idx: column index where comma sperable reference is
    # reverse: table descend order
    # Usage:
    #   reload(sys)
    #   sys.setdefaultencoding('utf-8') # support Korea
    #   dwg = dxf.drawing(outfile) # create a drawing
    #   dfs = pd.read_excel(infile, sheetname=None)
    #   dwg = dwg = make_tables_horizontal(dwg, dfs, 0, 10, None, True)
    #   dwg.save()

    j = 0
    for df_name in dfs:
        df = dfs[df_name]
        lst_colname = df.columns.values  # retrieve header name
        lst_colwidth = list(map(int, df.loc[0,:])) # first row is column width        
        lst_colalign = list(df.loc[1,:]) # first row is column alignment
        df = df.drop(df.index[[0,1]]) # drop first 2 row which is column width and alignment
        
        gap = sum(lst_colwidth)+10    # table column position 
        total_row = len(df.index) #줄 수 가져오기
        start_row = 0
        # Print sheet name
        header = df_name+" ("+str(total_row)+" rows)"
        print header
        dwg.add(dxf.text(header, insert=(j*gap, pos_y), height=4, layer='TEXTLAYER'))
        # Table
        while (start_row < total_row):            
            rows, list_table, list_height = build_data(lst_colwidth, \
                                            start_row, total_row, df, comma_idx, scale_factor);
            start_row += rows
            print "start:",start_row, "lenth:",len(list_table), "total:",total_row
            table = make_one_table((j*gap, pos_y-10), list_table, list_height, \
                                    lst_colwidth, lst_colalign, reverse)
            for i, name in enumerate(lst_colname):  # header
                if reverse:
                    table.text_cell(len(list_table), i, lst_colname[i], style='ctext')
                    table.set_row_height(len(list_table), def_height_cell+1)
                else:  # first line
                    table.text_cell(0, i, lst_colname[i], style='ctext') 
                    table.set_row_height(0, def_height_cell+1)
            j += 1
            dwg.add(table)  #Editable
            #dwg.add_anonymous_block(table, basepoint=(0, 0), insert=(i*gap, 0))    #Not editable
    
    return dwg
Пример #26
0
def y_axis_label(y, text):
    # Cheat a bit here since cadoodle doesn't yet have support for
    # drawing text labels.
    from dxfwrite import DXFEngine as dxf
    from dxfwrite.const import RIGHT, BOTTOM
    d.dwg.add(dxf.text(
        text,
        halign=RIGHT,
        valign=BOTTOM,
        alignpoint=(-part_padding, y + part_padding),
        height=8,
        layer="LABELS",
    ))
Пример #27
0
    def __init__(self,
                 wafer,
                 chipID,
                 layer,
                 jfingerw,
                 chip_id_loc=(6100, 0),
                 defaults=None,
                 **kwargs):
        m.Chip.__init__(self,
                        wafer,
                        chipID,
                        layer,
                        defaults={
                            'w': 200,
                            'r_out': 10,
                            'r_ins': 0
                        })
        #self.defaults = {'w':200,'r_out':10,'r_ins':0}
        if defaults is not None:
            for d in defaults:
                self.defaults[d] = defaults[d]

        #define the transmon (transmon pads and manhattan junction)
        #these numbers copied from Kevin's files
        jpos = self.centered((-self.width / 2 + 2960 + 58 - 210 - 250 + 500 +
                              790 + 1102 + 100 + 648 - 750 - 500, 0))
        Transmon3D(self,
                   jpos,
                   padh=200,
                   padw=4950 - 750 - 500,
                   padw2=750 + 750 + 500,
                   leadw=85,
                   leadw2=85,
                   leadh=20,
                   separation=20,
                   jfingerw=jfingerw,
                   **kwargs)

        #define the alignment mark
        Strip_straight(self,
                       self.centered((-1300 - 1600 + 3808 + 790 + 943.75, 0)),
                       100,
                       w=2000)
        #or to just use primitives, you could use:
        #self.add(dxf.rectangle(self.centered((-1300-1600+3808+790+943.75,0)),100,2000,valign=const.MIDDLE,bgcolor=wafer.bg()))

        #add chip name to frame layer
        self.add(
            dxf.text(str(self.chipID), chip_id_loc, height=200, layer='FRAME'))
Пример #28
0
 def drawCircle(self, p, d=0.010, layer=None, txt=None):
     if layer is None:
         layer = self.lDebug
     else:
         if not layer in self.definedLayers:
             self.definedLayers[layer] = True
             if self.d is not None:
                 self.d.add_layer(layer, color=self.color, lineweight=0)
     last = self.last
     self.circle(p, d / 2.0, layer)
     if txt is not None:
         self.add(dxf.text(txt, p, 0.010, \
                           alignpoint=p, halign=CENTER, valign=MIDDLE, \
                           layer=layer))
     self.move(last)
def create_cad():
    '''
    :return: a cad file(.dxf)
    '''
    global cad_name
    project_list = []
    excel_name = input("请输入Excel文件名称(粘贴复制无后辍哦~): ")
    num_projects = int(input("请输入写入项目数(同Excel但除XY): "))
    for project_num in range(1, num_projects + 1):
        pk_num = int(input("请输入项目%s所在列号:" % project_num))
        project_list.append(pk_num)
    pk_x_cood = int(input("请输入排口横坐标所在列号:"))
    pk_y_cood = int(input("请输入排口纵坐标所在列号:"))
    cad_name = input("请输入要保存的CAD文件名称:")
    # draw a cad picture
    drawing = dxf.drawing(os.getcwd() + "/%s.dxf" % cad_name)
    # read excel datas
    wb = load_workbook(os.getcwd() + "/" + excel_name + ".xlsx")
    ws = wb.active
    for row in ws.rows:
        for project_column in project_list:
            if str(row[pk_x_cood - 1].value).replace(
                    ".", "").isdigit() == True and str(
                        row[pk_y_cood - 1].value).replace(
                            ".", "").isdigit() == True:
                print(row[project_column - 1].value, row[pk_x_cood - 1].value,
                      row[pk_y_cood - 1].value)
                x_cood = float(row[pk_x_cood - 1].value)
                y_cood = float(row[pk_y_cood - 1].value)
                pai_num = row[project_column - 1].value
                circle = dxf.circle(2.0)
                circle['layer'] = 'paikou'
                circle['color'] = 2
                text = dxf.text(pai_num,
                                (x_cood, y_cood -
                                 1.35 * project_list.index(project_column)),
                                height=1.207)
                text['layer'] = 'paikou'
                text['color'] = 2
                block = dxf.block(name='paikou')
                block.add(circle)
                drawing.blocks.add(block)
                blockref = dxf.insert(blockname='paikou',
                                      insert=(x_cood, y_cood))
                drawing.add(blockref)
                drawing.add(text)

    drawing.save()
def drawSlotTestW(drawing,topLeft,maximum,minimum,step,gap,slotHeight,fullWidth):

    dX,dY = topLeft

    n = int(round((maximum-minimum)/step)) + 1

    if (maximum + (4* gap) > fullWidth):
        complain("full width not big enough")
        
    dX = dX + 2 * gap
    dY = dY + 2 * gap
    for i in range(n):
        h = slotHeight
        drawRectangle(drawing,(dX,dY),minimum+i*step,h)
        drawing.add(dxf.text(str(minimum+i*step),insert = (dX + maximum + gap, dY),height = h))
        dY = dY + gap + h

    drawRectangle(drawing,topLeft,fullWidth,dY-topLeft[1])
def drawMilimeter(cm):
    for mm in range(10):
        x_pos = tick_offset + 10 * cm + mm
        if mm == 0:  #desenha o traço mais comprido na marcação de cada centímetro
            y_pos = 20
            file.add(
                dxf.text(str(cm), [x_pos - 1, 20],
                         height=2,
                         rotation=90,
                         layer='SCAN'))
        elif mm == 5:  #desenha o traço médio na marcação de cada meio centímetro
            y_pos = 25
        else:  #desenha o traço curto na marcação de cada milimetro
            y_pos = 27.5
        file.add(
            dxf.rectangle([x_pos, y_pos],
                          tick_width,
                          ruler_width - y_pos,
                          layer='SCAN'))
        if cm == ruler_length: break
Пример #32
0
def Plot_to_dxf(filename):

    drawing = dxf.drawing(name=filename)

    for i in Punto.all:
        drawing.modelspace.add(dxf.point((i.X, i.Y, i.Z)))
        drawing.modelspace.add(dxf.text(i.Nombre, insert=(i.X, i.Y), color=2))

    def obtener_vertices(Poligono):
        vertices = []
        puntos_vertices = []
        coordenadas_vertices = []
        for observacion in Poligono.Puntos:
            if observacion.Poligono.lower() == Poligono.Nombre.lower():
                vertices.append(observacion.PO)
        for nombre in vertices:
            for punto in Punto.all:
                if punto.Nombre == nombre:
                    puntos_vertices.append(punto)
        for punto in puntos_vertices:
            coordenadas_vertices.append((punto.X, punto.Y, punto.Z))
        return coordenadas_vertices

    def linetype(objeto):
        lt = ''
        if type(objeto) is PoligonoAuxiliar:
            lt = 'DASHED'
        else:
            lt = 'CONTINUOUS'
        return lt

    for poligono in Poligono.all:

        p = drawing.modelspace.add(
            dxf.polyline(points=obtener_vertices(poligono),
                         linetype=linetype(poligono),
                         layer=poligono.Nombre,
                         color=1))
        p.close()

    drawing.saveas(filename)
Пример #33
0
 def draw_numbers(self, i):
   drawn = set()
   d = self.ds[i]
   all_fold_edges = self.fold_edges[i]
   all_cut_edges = self.cut_edges[i]
   edge_numbering = self.edge_numbering
   for k in d:
     v1, v2, v3 = d[k].transformed_vertices
     v1 = tuple(v1)
     v2 = tuple(v2)
     v3 = tuple(v3)
     cut_edges = all_cut_edges[k]
     fold_edges = all_fold_edges[k]
     
     for j, edge in enumerate([(v1,v2), (v2,v3), (v3,v1)]):
       if edge_numbering[k][j] != None:
         midpoint = ( (edge[0][0] + edge[1][0])/2 , (edge[0][1] + edge[1][1])/2 )
         n = getNormalBetween2DVertices(edge[0],edge[1])
         multiplier = 0.4
         pt = (midpoint[0] - n[0] * multiplier, midpoint[1] - n[1] * multiplier)
         self.drawings[i].add(dxf.text(edge_numbering[k][j], insert=pt, height=0.2, color=self.folding_color1))
def create_cad():
    '''
    :return: a cad file(.dxf)
    '''
    global cad_name
    excel_name = input("\033[1;32m请输入Excel文件名称:(粘贴复制哦~)\033[0m")
    pk_num = int(input("\033[1;32m请输入排口编号所在列号:\033[0m"))
    pk_x_cood = int(input("\033[1;32m请输入排口横坐标所在列号:\033[0m"))
    pk_y_cood = int(input("\033[1;32m请输入排口纵坐标所在列号:\033[0m"))
    cad_name = input("请输入要保存的CAD文件名称:")
    # draw a cad picture
    drawing = dxf.drawing(os.getcwd() + "/%s.dxf" % cad_name)
    # read excel datas
    wb = load_workbook(os.getcwd() + "/" + excel_name + ".xlsx")
    ws = wb.active
    for row in ws.rows:
        if row[pk_num-1].value != None and row[pk_x_cood-1].value != None and  row[pk_y_cood-1].value != None \
                and is_number(row[pk_x_cood-1].value) == True and is_number(row[pk_y_cood-1].value) == True:
            print(row[pk_num - 1].value, row[pk_x_cood - 1].value,
                  row[pk_y_cood - 1].value)
            x_cood = float(row[pk_x_cood - 1].value)
            y_cood = float(row[pk_y_cood - 1].value)
            pai_num = row[pk_num - 1].value
            circle = dxf.circle(2.0)
            circle['layer'] = 'paikou'
            circle['color'] = 2
            text = dxf.text(pai_num, (x_cood, y_cood), height=1.207)
            text['layer'] = 'paikou'
            text['color'] = 2
            block = dxf.block(name='paikou')
            block.add(circle)
            drawing.blocks.add(block)
            blockref = dxf.insert(blockname='paikou', insert=(x_cood, y_cood))
            drawing.add(blockref)
            drawing.add(text)

    drawing.save()
Пример #35
0
def bom_dxf(infile, outfile):
    # Korean support
    reload(sys)
    sys.setdefaultencoding('utf-8')

    dwg = dxf.drawing(outfile)  # create a drawing

    workbook = xlrd.open_workbook(infile)  #open excel file
    worksheet_names = workbook.sheet_names()  # list of worksheet names
    worksheets = workbook.sheets()  # instance of worksheets

    gap = sum(list_col_width) + 10  # table column position
    j = 0
    for i, ws in enumerate(worksheets):
        total_row = ws.nrows  #줄 수 가져오기
        start_row = 0
        # Print sheet name
        header = worksheet_names[i] + " (" + str(total_row) + " rows)"
        dwg.add(
            dxf.text(header, insert=(j * gap, 10), height=4,
                     layer='TEXTLAYER'))
        # Table
        while (start_row < total_row):
            rows, list_table, list_height = build_data(start_row, total_row,
                                                       ws)
            #print rows, list_height
            start_row += rows
            print "start:", start_row, "lenth:", len(
                list_table), "total:", total_row
            table = make_table((j * gap, 0), list_table, list_height)
            j += 1
            dwg.add(table)  #Editable
            #dwg.add_anonymous_block(table, basepoint=(0, 0), insert=(i*gap, 0))    #Not editable

    dwg.save()
    print("drawing '%s' created.\n" % outfile)
Пример #36
0
import argparse  #Parser for command-line options, arguments and sub-commands
import pytesseract  #Python-tesseract is an optical character recognition (OCR) tool for python. That is, it will recognize and “read” the text embedded in images.
from picture_to_coordinates import coordinates  #Importing array made from picture
from dxfwrite import DXFEngine as dxf  #dxf is a Python interface to the DXF (drawing interchange file) format developed by Autodesk,

# Might want to use 'import argparse' to get arguments from command line

# AutoCAD DXF (Drawing Interchange Format, or Drawing Exchange Format)
# is a CAD data file format developed by Autodesk[2]
# for enabling data interoperability between AutoCAD and other programs.
# https://en.wikipedia.org/wiki/AutoCAD_DXF

# Convert image to drawing here.

# Create a drawing, we will add things to it
drawing = dxf.drawing()

# In this block we are creating various objects and adding them to the drawing
# Create text object at coordinates 3, 0, 1
text = dxf.text('Hello World!', point=(3, 0, 1))
# Add text to drawing
drawing.append(text)
# Same with line
line = dxf.line(points=[(0, 0, 0), (1, 1, 1)])
drawing.append(line)

# Finally, save file to path
drawing.saveas(output_path)
print('Complete')
Пример #37
0
drawing.add(dxf.point(point=(1,1)))

# add a SOLID-entity with 4 points
drawing.add(dxf.solid([(0,0), (1,0), (1,1), (0,1)], color=2))

# add a SOLID-entity with 3 points
drawing.add(dxf.solid([(0,1), (1,1), (1,2)], color=3))

# add a 3DFACE-entity
drawing.add(dxf.face3d([(5,5), (6,5), (6,6), (5,6)], color=3))

# add a Trace-entity
drawing.add(dxf.trace([(7,5), (8,5), (8,6), (7,6)], color=4))

# add a TEXT-entity
drawing.add(dxf.text("Manfred"))

# add a TEXT-entity with more properties
drawing.add(dxf.text(
    text="mozman",
    style="ISOCPEUR",
    height=0.7,
    oblique=15,
    color=5,
    insert=(0,5),
    rotation=30,
))

# create BLOCK-entity
block = dxf.block(name='Rechteck')
# add DXF-entities to the block
def export_via_dxfwrite(  dxf_fn, V):
    from XMLlib import SvgXMLTreeNode
    from svgLib_dd import SvgTextParser, SvgPath, SvgPolygon
    from numpy import arctan2
    from circleLib import fitCircle_to_path, findCircularArcCentrePoint, pointsAlongCircularArc
    from dxfwrite import DXFEngine as dxf
    drawing = dxf.drawing( dxf_fn)
    
    pageSvg = open(V.page.PageResult).read()
    XML_tree =  SvgXMLTreeNode( pageSvg,0)
    def yT(y): #y transform
        return 210-y
    warningsShown = []
    SelectViewObjectPoint_loc = None
    for element in XML_tree.getAllElements():
        clr_text = None        
        if element.parms.has_key('fill'):
            clr_text =  element.parms['fill']
        elif element.parms.has_key('style'):
            for part in element.parms['style'].split(';'):
                if part.startswith('stroke:rgb('):
                    clr_text = part[ len('stroke:'):]
        if clr_text == None or clr_text =='none' or not clr_text.startswith('rgb(') :
            color_code = 0
        else:
            #FreeCAD.Console.PrintMessage( "color text: %s\n" % clr_text )
            r,g,b = [ int(v.strip()) for v in clr_text[ len('rgb('): clr_text.find(')')].split(',') ]
            color_code = colorLookup(r,g,b)[0]
        if element.tag == 'circle':
            x, y = element.applyTransforms( float( element.parms['cx'] ), float( element.parms['cy'] ) )
            r =  float( element.parms['r'] )* element.scaling2()
            drawing.add( dxf.circle( r, (x,yT(y)), color=color_code) )
        elif element.tag == 'line':
            x1, y1 = element.applyTransforms( float( element.parms['x1'] ), float( element.parms['y1'] ) )
            x2, y2 = element.applyTransforms( float( element.parms['x2'] ), float( element.parms['y2'] ) )
            drawing.add( dxf.line( (x1, yT(y1)), (x2, yT(y2)), color=color_code ) )
        elif element.tag == 'text' and element.parms.has_key('x'):
            x,y = element.applyTransforms( float( element.parms['x'] ), float( element.parms['y'] ) )
            try:
                t = SvgTextParser(element.XML[element.pStart: element.pEnd ] )
                drawing.add(dxf.text( t.text, insert=(x, yT(y)), height=t.height()*0.8, rotation=t.rotation, layer='TEXTLAYER', color=color_code) )
            except ValueError, msg:
                FreeCAD.Console.PrintWarning('dxf_export: unable to convert text element "%s": %s, ignoring...\n' % (element.XML[element.pStart: element.pEnd ], str(msg) ) )
        elif element.tag == 'path': 
            #FreeCAD.Console.PrintMessage(element.parms['d']+'\n')
            path = SvgPath( element )
            for line in path.lines:
                drawing.add( dxf.line( (line.x1, yT(line.y1)), (line.x2,yT(line.y2)), color=color_code) ) 
            for arc in path.arcs:
                if arc.circular:
                    for r, center, angle1, angle2 in arc.dxfwrite_arc_parms( yT ):
                        drawing.add( dxf.arc( r, center, angle1, angle2 , color=color_code) )
                else:
                    for x1,y1,x2,y2 in arc.approximate_via_lines( 12 ):
                        drawing.add( dxf.line( (x1, yT(y1)), (x2, yT(y2)), color=color_code) )
            for bezierCurve in path.bezierCurves:
                x, y, r, r_error = bezierCurve.fitCircle()
                if r_error < 10**-4:
                    raise NotImplementedError
                    drawing.add( dxf.arc( *bezierCurve.dxfwrite_arc_parms(x, y, r) ) )
                else:
                    X,Y = bezierCurve.points_along_curve()
                    for i in range(len(X) -1):
                        drawing.add( dxf.line( (X[i], yT(Y[i])), (X[i+1],yT(Y[i+1])), color=color_code ) )
Пример #39
0
def create_xref(xrefname):
    dwg = dxf.drawing(xrefname)
    for x in range(6):
        dwg.add(dxf.rectangle((x, 0), 1., 1., color=1+x))
    dwg.add(dxf.text('I AM THE XREF', (0.25, 0.25), height=0.5, color=6))
    dwg.save()
    left_pt = (arrow_point[0] - length_arrow / 6.0 , arrow_point[1] - length_arrow )
    right_pt = (arrow_point[0] + length_arrow / 6.0 , arrow_point[1] - length_arrow)
    drawing.add(dxf.trace([vertex, left_pt, right_pt]))
    return
list_xcoordinates_for_arrows = [(float(lst['A'])/(no_of_arrows - 1))*i
                                for i in xrange(no_of_arrows + 1)]
list_bottom_points = zip(list_xcoordinates_for_arrows,[-dist_of_arrow] * no_of_arrows)
list_arrow_points = zip(list_xcoordinates_for_arrows,[0] * no_of_arrows)
final_arrow_points = zip(list_bottom_points,list_arrow_points)

for i in xrange(len(final_arrow_points)):
    arrow(final_arrow_points[i][0], final_arrow_points[i][1])


# text
drawing.add(dxf.text('a', height=textsize, halign=CENTER, alignpoint=(40, 34)))
drawing.add(dxf.text('D', height=textsize, halign=CENTER, alignpoint=(105, 10)))
drawing.add(dxf.text('A', height=textsize, halign=CENTER, alignpoint=(40, -18)))
drawing.add(dxf.text('p (kN/m\u00B2)', height=textsize, halign=CENTER, alignpoint=(-17, -7)))
drawing.add(dxf.text('P (kN)', height=textsize, halign=CENTER, alignpoint=(40, 58)))
drawing.add(dxf.text('Dm', height=textsize, halign=CENTER, alignpoint=(90, 3)))
drawing.add(dxf.text('D/2', height=textsize, halign=CENTER, alignpoint=(30, 30)))
drawing.add(dxf.text('D/2', height=textsize, halign=CENTER, alignpoint=(50, 30)))
drawing.add(dxf.text(u"\u03B2", height=textsize, halign=CENTER, alignpoint=(12, 10)))
drawing.add(dxf.text(u"\u03B2", height=textsize, halign=CENTER, alignpoint=(69, 10)))


# p(kN/m)
dim8_arrow(-12, 0, -8, 0, -10, 10, -10, 0)
atrace(-10.5, 3, -9.5, 3, -10, 0)
Пример #41
0
def get_host_dwg(drawingname):
    dwg = dxf.drawing(drawingname)
    dwg.add(dxf.text('I AM THE HOST DRAWING', (-0.5, 1.5), 0.5, color=2))
    dwg.add(dxf.rectangle((-1,-1), 10, 3, color=2))
    return dwg
Пример #42
0
def serial_number(drawing, x, y, text = ""):
    serial =  get_git_revision_short_hash()
    drawing.add(dxf.text(serial, halign=dxfwrite.const.CENTER,  valign=dxfwrite.const.MIDDLE, alignpoint=(x, y+2.5), height=2, layer='ENGRAVE', color=2))
    if (text !=""):
        drawing.add(dxf.text(text, halign=dxfwrite.const.CENTER,  valign=dxfwrite.const.MIDDLE, alignpoint=(x, y-2.5), height=2, layer='ENGRAVE', color=2))
Пример #43
0
def create_dxf(filename, polys, close=False, close_with_arc=False, right_temple_text=None):
    drawing = dxf.drawing(filename)
    drawing.add_layer('OUTLINE', color=1)
    drawing.add_layer('TEXT', color=2)

    for p in polys:
        polyline = dxf.polyline(layer="OUTLINE", thickness=0.1)
        if close:
            p = p + [p[0]]  # Close the polygon to avoid a cusp
        elif close_with_arc and p[0] != p[-1]:
            # Temples get a little arc to account for frame curvature after bending.
            # Frame is bent at base 6 curvature, which is 88 mm radius sphere.  Plane
            # intersecting sphere at 30mm (about the offset of most temples) is 80mm radius.
            # First find the center of the arc

            center_point = (
                    p[-1][0] + (p[0][0]-p[-1][0])/2,
                    p[-1][1] + (p[0][1]-p[-1][1])/2)

            vect = (p[-1][0]-p[0][0], p[-1][1]-p[0][1])
            scale = (vect[0]**2 + vect[1]**2) ** 0.5
            unit_vect = (vect[0]/scale, vect[1]/scale)
            vect = (unit_vect[0]*88, unit_vect[1]*88)
            vect = (vect[1], -vect[0])
            center_point = (center_point[0]+vect[0], center_point[1]+vect[1])

            # We set it arbitrarily at 79 mm but the actual radius will be to the end points
            radius = ((center_point[0]-p[0][0])**2 + (center_point[1]-p[0][1])**2) **0.5
            print 'radius', radius
            angle1 = math.atan2(p[0][1]-center_point[1], p[0][0] - center_point[0])
            angle2 = math.atan2(p[-1][1]-center_point[1], p[-1][0] - center_point[0])
            print 'angle of p0', math.degrees(angle1)
            print 'angle of pn1', math.degrees(angle2)

            drawing.add(dxf.arc(radius, center_point, math.degrees(angle2), math.degrees(angle1), layer="OUTLINE", thickness=0.1))


        polyline.add_vertices(p)
        drawing.add(polyline)

    if right_temple_text:
        p = polys[1]
        insertion_point = (
                p[-1][0] + (p[0][0]-p[-1][0])/2,
                p[-1][1] + (p[0][1]-p[-1][1])/2)

        vect = (p[-1][0]-p[0][0], p[-1][1]-p[0][1])
        scale = (vect[0]**2 + vect[1]**2) ** 0.5
        unit_vect = (vect[0]/scale, vect[1]/scale)
        vect = (unit_vect[0]*15, unit_vect[1]*15)
        vect = (vect[1], -vect[0])
        insertion_point = (insertion_point[0]+vect[0], insertion_point[1]+vect[1]-1)

        bottom_vect = (p[100][0]-p[0][0], p[100][1]-p[0][1])
        text_angle = math.atan2(bottom_vect[1], bottom_vect[0])
        print 'text angle', text_angle
        txt = dxf.text(
                right_temple_text,
                insertion_point,
                rotation=math.degrees(text_angle),
                style="ARIAL",
                layer="TEXT",
                height=2.0
                )
        txt2 = dxf.text(
                "made with love by GUILD eyewear",
                (insertion_point[0]+0.5, insertion_point[1]-3),
                style="TIMES",
                rotation=math.degrees(text_angle),
                layer="TEXT",
                height=2.0
                )
        drawing.add(txt);
    #    drawing.add(txt2);
    drawing.save()
    right_pt = (arrow_point[0] + length_arrow / 6.0 , arrow_point[1] - length_arrow)
    drawing.add(dxf.trace([vertex, left_pt, right_pt]))
    return
list_xcoordinates_for_arrows = [(float(lst['A'])/(no_of_arrows - 1))*i for i in xrange(no_of_arrows + 1)]
list_bottom_points = zip(list_xcoordinates_for_arrows,[-dist_of_arrow_from_footing_base] * no_of_arrows)
list_arrow_points = zip(list_xcoordinates_for_arrows,[0] * no_of_arrows)
final_arrow_points = zip(list_bottom_points,list_arrow_points)

for i in xrange(len(final_arrow_points)):
    arrow(final_arrow_points[i][0], final_arrow_points[i][1])

# text size
textsize = 2.5

#text
drawing.add(dxf.text('a', height=2.5, halign=CENTER, alignpoint=(50, 32)))
drawing.add(dxf.text('D', height=2.5, halign=CENTER, alignpoint=(114, 12)))
drawing.add(dxf.text('A', height=2.5, halign=CENTER, alignpoint=(50, -18)))
drawing.add(dxf.text('p (kN/m\u00B2)', height=2.5, halign=CENTER, alignpoint=(-15, -7)))
drawing.add(dxf.text('P (kN)', height=2.5, halign=CENTER, alignpoint=(50, 54)))
drawing.add(dxf.text('Dm', height=2.5, halign=CENTER, alignpoint=(104, -5)))
drawing.add(dxf.text(u"\u03B2", height=2.5, halign=CENTER, alignpoint=(15, 8)))
drawing.add(dxf.text(u"\u03B2", height=2.5, halign=CENTER, alignpoint=(85, 8)))

# p(kN/m)
dim8_arrow(-12, 0, -8, 0, -10, 10, -10, 0)
atrace(-10.5, 3, -9.5, 3, -10, 0)

# p(kN/m)lower
dim8_arrow(-12, -10, -8, -10, -10, -10, -10, -20)
atrace(-10.5, -13, -9.5, -13, -10, -10)
drawing.add(
    dxf.line(points_list[13],
             points_list[14],
             color=7,
             layer='TESTLAYER',
             linetype='DASHEDX2'))

# Diagonal lines:
drawing.add(dxf.line(points_list[0], points_list[5], color=7))
drawing.add(dxf.line(points_list[1], points_list[6], color=7))
drawing.add(dxf.line(points_list[2], points_list[7], color=7))
drawing.add(dxf.line(points_list[3], points_list[8], color=7))

# text
drawing.add(
    dxf.text('A', height=text_size, halign=CENTER, alignpoint=(115, 50)))
drawing.add(dxf.text('A', height=text_size, halign=CENTER,
                     alignpoint=(50, -8)))
drawing.add(dxf.text('a', height=text_size, halign=CENTER,
                     alignpoint=(85, 52)))
drawing.add(
    dxf.text('d/2', height=text_size, halign=CENTER, alignpoint=(85, 65)))
drawing.add(dxf.text('a', height=text_size, halign=CENTER,
                     alignpoint=(48, 21)))
drawing.add(
    dxf.text('d/2', height=text_size, halign=CENTER, alignpoint=(35, 21)))
drawing.add(
    dxf.text('d/2', height=text_size, halign=CENTER, alignpoint=(64, 21)))
drawing.add(
    dxf.text('d/2', height=text_size, halign=CENTER, alignpoint=(85, 34)))
drawing.add(dxf.text('1', height=text_size, halign=CENTER,
    drawing.add(dxf.trace([vertex, left_pt, right_pt]))
    return
list_xcoordinates_for_arrows = [(float(A)/(no_of_arrows - 1))*i
                                for i in xrange(no_of_arrows + 1)]
list_bottom_points = zip(list_xcoordinates_for_arrows,[-dist_of_arrow] * no_of_arrows)
list_arrow_points = zip(list_xcoordinates_for_arrows,[0] * no_of_arrows)
final_arrow_points = zip(list_bottom_points,list_arrow_points)

for i in xrange(len(final_arrow_points)):
    arrow(final_arrow_points[i][0], final_arrow_points[i][1])


# text size
textsize = 2.5

drawing.add(dxf.text('a', height=textsize, halign=CENTER, alignpoint=(40, 43)))
drawing.add(dxf.text('D', height=textsize, halign=CENTER, alignpoint=(105, 10)))
drawing.add(dxf.text('A', height=textsize, halign=CENTER, alignpoint=(40, -18)))
drawing.add(dxf.text('p (kN/m\u00B2)', height=textsize, halign=CENTER, alignpoint=(-16, -7)))
drawing.add(dxf.text('P (kN)', height=textsize, halign=CENTER, alignpoint=(40, 63)))
drawing.add(dxf.text('Dm', height=textsize, halign=CENTER, alignpoint=(90, 5)))
drawing.add(dxf.text('a\'', height=textsize, halign=CENTER, alignpoint=(30, 35)))
drawing.add(dxf.text('1\'', height=textsize, halign=CENTER, alignpoint=(20, 43)))
drawing.add(dxf.text('2\'', height=textsize, halign=CENTER, alignpoint=(10, 43)))
drawing.add(dxf.text('1\'', height=textsize, halign=CENTER, alignpoint=(22, -25)))
drawing.add(dxf.text('2\'', height=textsize, halign=CENTER, alignpoint=(10, -25)))

# p(kn/m)
dim8_arrow(-12, 0, -8, 0, -10, 0, -10, 10)
atrace(-10.5, 3, -9.5, 3, -10, 0)
Пример #47
0
# 60-degree hex grid
hexperf = perf.microperf_style(angle=60, grid_width=4.25, grid_height=3.25,
  border_width=8.5, border_height=8.37, tab_radius=1, suffix='A', border=True,
  label=True)
# 60-degree hex grid with much fewer points, so we can open it in AI and inspect
hexperf_tiny = perf.microperf_style(angle=60, grid_width=.25, grid_height=.25,
  border_width=8.5, border_height=8.37, tab_radius=1, suffix='A', border=True,
  label=True)

# generate microperf grids and add to drawing
perf.add_to_drawing([
  hexperf_tiny(5, 25, offset_x=20, offset_y=80),
  hexperf_tiny(5, 20, offset_x=20, offset_y=60),
  hexperf_tiny(5, 15, offset_x=20, offset_y=40),
  hexperf_tiny(5, 10, offset_x=20, offset_y=20),

  hexperf_tiny(10, 25, offset_x=40, offset_y=80),
  hexperf_tiny(10, 20, offset_x=40, offset_y=60),
  hexperf_tiny(10, 15, offset_x=40, offset_y=40),

  hexperf_tiny(15, 25, offset_x=60, offset_y=80),
  hexperf_tiny(15, 20, offset_x=60, offset_y=60),

  hexperf_tiny(20, 25, offset_x=80, offset_y=80)
], drawing)

# add 10mmx10mm square for reference
drawing.add(dxf.rectangle((75, 20), 10, 10, layer='ref'))
drawing.add(dxf.text('10mmx10mm', (75, 18), height=1, layer='text'))

drawing.save()
                         [-arrow_height] * (no_of_arrows + 1))

# corresponding upper points.
list_arrow_points = zip(list_xcoordinates_for_arrows, [0] * (no_of_arrows + 1))
final_arrow_points = zip(list_bottom_points, list_arrow_points)

# creating arrows.
for i in range(len(final_arrow_points)):
    arrow(final_arrow_points[i][0], final_arrow_points[i][1])


# ################# Dimensionized Text #################

drawing.add(dxf.text('a', height=textsize, halign=CENTER,
                     alignpoint=((points_list[0][0] +
                                  points_list[-2][0])*scale_factor/2,
                                 ((points_list[0][1] +
                                   points_list[1][1])/2)*scale_factor + 3)))

# drawing.add(dxf.text('D', height=textsize, halign=CENTER, alignpoint=(115, 8)))
# drawing.add(dxf.text('A', height=textsize, halign=CENTER,
#                      alignpoint=(50, -18)))
# drawing.add(dxf.text('P (kN)', height=textsize, halign=CENTER,
#                      alignpoint=(50, 53)))
# drawing.add(dxf.text('p (kN/m\u00B2)', height=textsize, halign=CENTER,
#                      alignpoint=(-12, -7)))

# p(kN/m)
# def dim8_arrow(u11, u12, u13, u14, l11, l12, l13, l14)
u11 = points_list[3][0] - (8 * scale_factor)
u12 = points_list[3][1]
Пример #49
0
def engrave_text(drawing, x, y):
    drawing.add(dxf.text('Cuffelink.com', halign=dxfwrite.const.CENTER,  valign=dxfwrite.const.MIDDLE, alignpoint=(x, y+2.5), height=2, layer='ENGRAVE', color=2))
Пример #50
0
def writeText(draw, txt, alignpx, alignpy, size, colorTextt, layerTxt, angRotation):
    text = dxf.text(txt, halign=CENTER, alignpoint=(alignpx, alignpy))
    text["layer"] = layerTxt
    text["color"] = colorTextt
    text["height"] = size
    draw.add(text)
Пример #51
0



for i in ppolylines:
    polyline= dxf.polyline(linetype='DOT',color = 256,layer='midPressB')
    polyline.add_vertices( i )
    drawing.add(polyline)
# =============================================================================
#     drawing.save()
#     drawing.add(
#         dxf.polylines(
#             ppoints[i],
#             ppoints[i+1],
#             layer='midPressB',
#             color = 256
#         )
#     )
# =============================================================================
for i in ppoints:
    text = dxf.text('Text', i, height=3, rotation=45,layer ='text' ,color =200 )
    point = dxf.point(i)
    point['layer'] = 'points'
    point['color'] = 100
    point['thickness'] = 3.2
    drawing.add(point)
    drawing.add(text)
drawing.save()


Пример #52
0
def temple_dxf(o, filename, hinge, reverse):
    temple_contour = poly.mirror_y(o['ltemple_con'], False)

    # Location in y for the center of the hinge
    hinge_y = -(temple_contour[0][1]+temple_contour[-1][1])/2

    temple_contour = poly.mirror_y(temple_contour, True)
    # Only mirror the temple contour, not the hinge, because the hinge is modelled
    # for the RIGHT hinge and we have the LEFT temple
    hinge_contour = hinges.get_hinge(hinge)["temple_contour"]
    hinge_holes = hinges.get_hinge(hinge)["temple_holes"]

    # Temple should be at 6 degrees.  We tilt the hinge instead for manufacturing
    # ease.
#    hinge_contour = poly.rotate(hinge_contour, 6)
#    hinge_holes = poly.rotate(hinge_holes, 6)

    # 0 point of hinge is center of straight edge of hinge.  We want the
    # center of the hinge box.
    hinge_center_offset = (poly.top(hinge_contour)+poly.bottom(hinge_contour))/2
    y_offset = hinge_y-hinge_center_offset

    # Since we're tilted 6 degrees compared to design space we need to
    # compensate on the x axis
    x_offset = y_offset * math.tan(math.radians(6)) # This adjusts the hinge for the move to the center of the temple

    hinge_contour = poly.translate(hinge_contour, x_offset, y_offset)
    hinge_holes = poly.translate(hinge_holes, x_offset, y_offset)

    # Reverse for the right temple
    if reverse:
        temple_contour = poly.mirror_x(temple_contour, False)
        hinge_contour = poly.mirror_x(hinge_contour, False)
        hinge_holes = poly.mirror_x(hinge_holes, False)

    drawing = dxf.drawing(filename)
    drawing.add_layer("CUT", color=1)
    drawing.add_layer("POCKET", color=2)
    drawing.add_layer("TEXT", color=3)
    polyline = dxf.polyline(layer="CUT", color=1, thickness=0.1)
    polyline.add_vertices(temple_contour)
    drawing.add(polyline)
    polyline = dxf.polyline(layer="POCKET", color=2, thickness = 0.1)
    polyline.add_vertices(hinge_contour)
    drawing.add(polyline)
    for hole in hinge_holes:
        c = dxf.circle(0.5, hole, layer="CUT", color=1)
        drawing.add(c)
    if not reverse:
        # Left temple, add our company name
        # First find Y position 15mm from temple top corner
        xPos = temple_contour[0][0]-15
        yPos = -1
        yStartPos = -1
        for pt in reversed(temple_contour):
            if pt[0] < xPos and yPos < 0:
                yPos = pt[1]-3.5
            elif pt[0] < (xPos - 25):
                yStartPos = pt[1] - 3.5
                break
        angle = math.degrees(math.atan((yPos-yStartPos)/25))
        print 'text angle', angle
        text = dxf.text("GUILD eyewear", style="TIMES", color=3, rotation=angle, height=2.5, alignpoint=[xPos, yPos], halign=2, valign=2)
        drawing.add(text)


    drawing.save()
Пример #53
0
def writeTextRight(draw,txt,alignpx,alignpy,size,colorTextt,layerTxt,angRotation):
	text=dxf.text(txt, halign=RIGHT, alignpoint=(alignpx,alignpy))
	text['layer'] = layerTxt
	text['color'] = colorTextt
	text['height']= size
	draw.add(text)
Пример #54
0
drawing.add(dxf.line((7.5,4),(7.9,3.5)))
drawing.add(dxf.line((8.5,4),(8.9,3.5)))
drawing.add(dxf.line((8.5,4),(8.2,3.5)))
drawing.add(dxf.line((9.5,4),(9.9,3.5)))
drawing.add(dxf.line((9.5,4),(9.2,3.5)))
drawing.add(dxf.line((10.5,4),(10.9,3.5)))
drawing.add(dxf.line((10.5,4),(10.2,3.5)))
drawing.add(dxf.line((11.5,4),(11.9,3.5)))
drawing.add(dxf.line((11.5,4),(11.2,3.5)))
drawing.add(dxf.line((12.5,4),(12.9,3.5)))
drawing.add(dxf.line((12.5,4),(12.2,3.5)))
drawing.add(dxf.line((13.5,4),(13.9,3.5)))
drawing.add(dxf.line((13.5,4),(13.2,3.5)))
drawing.add(dxf.line((15,4),(14.5,3.5)))
drawing.add(dxf.line((15,4),(15.5,3.5)))


drawing.add(dxf.text('A', halign=CENTER, alignpoint=(8, 0)))
drawing.add(dxf.text('a', halign=CENTER, alignpoint=(8, 8)))
drawing.add(dxf.text('P(kN)', halign=CENTER, alignpoint=(8, 12)))
drawing.add(dxf.text('D', valign=CENTER, alignpoint=(16, 4)))
drawing.add(dxf.text('Uniformly deep footing', halign=CENTER, alignpoint=(-2, -2)))
drawing.add(dxf.text('p(kN/cm)', halign=CENTER, alignpoint=(-3, 2)))






drawing.save()
Пример #55
0
def writeTextLeft(draw, txt, px0, py0, size, colorTextt, layerTxt, angRotation):
    text = dxf.text(txt, (px0, py0), height=size, rotation=angRotation)
    text["layer"] = layerTxt
    text["color"] = colorTextt
    # text['alignpoint']=alignPx,alignPy
    draw.add(text)
Пример #56
0
def save_as_dxf(profile, dxf_path):
    """Save the profile in DXF format, with filename dxf_path. Return
    success"""
    line = profile.line
    if line is None:
        # No base line. Skip!
        return False
    midpoint = line.midpoint

    leftmost = profile.sorted_measurements[0]

    drawing = dxf.drawing(dxf_path)

    measurements = profile.sorted_measurements

    x = line.distance_to_midpoint(leftmost.point)

    # Draw location code to the left of the profile, 1m above the
    # highest z1/z2 there
    drawing.add(dxf.text(
            '{location_code} ({x}, {y}) {date}'.format(
                location_code=profile.id,
                x=midpoint.x,
                y=midpoint.y,
                date=profile.date_measurement),
            insert=(x, max([leftmost.z1, leftmost.z2]) + 1),
            height=0.4))  # 40cm high

    previous = None
    previous_z1 = None
    previous_z2 = None
    previous_x = None
    for m in measurements:
        projected_m = line.project(m.point)

        draw_z(drawing, line, m)

        if previous is not None:
            # Add distance between previous and this one to x
            # projected on the line
            p_m = line.project(m.point)
            x += p_m.distance(previous)

            drawing.add(dxf.line((previous_x, previous_z1),
                                 (x, m.z1)))
            drawing.add(dxf.line((previous_x, previous_z2),
                                 (x, m.z2)))

        previous = projected_m
        previous_z1 = m.z1
        previous_z2 = m.z2
        previous_x = x

    # Draw water line
    waterlevel = profile.waterlevel
    if waterlevel is not None:
        drawing.add(dxf.line(
                (-line.start.distance(line.midpoint), waterlevel),
                (line.end.distance(line.midpoint), waterlevel)))

    drawing.save()
    return True

# circle code
no_of_bars_above = 9

some_space_at_end = 5
center_to_center = ((lst['A'] - lst['ClearCover'] * 2 - some_space_at_end * 2) / float(no_of_bars_above - 1))
center_of_first_bar = (lst['ClearCover'] + some_space_at_end, lst['ClearCover'] + lst['Dia'] + lst['Dia'] / 2.0)

x_coord_of_center_of_bars = [(center_of_first_bar[0] + i * center_to_center) for i in xrange(no_of_bars_above)]
for x in x_coord_of_center_of_bars:
    drawing.add(dxf.circle(lst['Dia'] / 2.0, (x, center_of_first_bar[1])))


# text
drawing.add(dxf.text('a', height=textsize, halign=CENTER, alignpoint=(50, 33)))
drawing.add(dxf.text('D', height=textsize, halign=CENTER, alignpoint=(115, 8)))
drawing.add(dxf.text('A', height=textsize, halign=CENTER, alignpoint=(50, -10)))
drawing.add(dxf.text('4', height=textsize, halign=CENTER, alignpoint=(-10, -13)))
drawing.add(dxf.text('4', height=textsize, halign=CENTER, alignpoint=
                  (106, -4)))
drawing.add(dxf.text('y > L\U+0501',height=textsize, halign=CENTER, alignpoint=(18, -15)))
drawing.add(dxf.text('Sloped footing', height=textsize, halign=CENTER, alignpoint=(20, 33)))
drawing.add(dxf.text('Uniformly deep footing', height=textsize, halign=CENTER, alignpoint=(80, 33)))


# D
# def dim12_arrow(u1, u2, u3, u4, l1, l2, l3, l4, c1, c2, c3, c4):
dim12_arrow(108, 20, 112, 20, 110, 20, 110, 0, 108, 0, 112, 0)
atrace(109.5, 17, 110.5, 17, 110, 20)
atrace(109.5, 3, 110.5, 3, 110, 0)
Пример #58
0
#!/usr/bin/env python
#coding:utf-8
# Author:  raz
# Purpose: Using unicode text in the drawing
# Created: 22.11.2011
# Copyright (C) 2010, Toni Ruža
# License: MIT License

from __future__ import unicode_literals

__author__ = "raz"

try:
    import dxfwrite
except ImportError:
    # if dxfwrite is not 'installed' append parent dir of __file__ to sys.path
    import os, sys
    curdir = os.path.dirname(os.path.abspath(__file__))
    sys.path.insert(0, os.path.abspath(os.path.join(curdir, os.path.pardir)))

from dxfwrite import DXFEngine as dxf

drawing = dxf.drawing('unicode_text.dxf')
drawing.add(dxf.line((0, 0), (24, 0), color=7))
layer_name = 'ŽĆČĐŠ'
drawing.add_layer(layer_name, color=2)
drawing.add(dxf.text(
    'На крај села жута ћирилична кућа', insert=(0, 0.2), layer=layer_name
))
drawing.save()