def plungers_side_mirror( layer, plunger_to_nw, plunger_tip_width, plunger_tip_height, plunger_taper_width, blockname): #plungers on just one side of the nanowire block = dxf.block(blockname, layer=layer) taper = dxf.polyline(layer=layer) taper.add_vertices([ (-plunger_tip_width / 2, -plunger_to_nw), (plunger_tip_width / 2, -plunger_to_nw), (plunger_taper_width / 2, -plunger_tip_height - plunger_to_nw), (-plunger_taper_width / 2, -plunger_tip_height - plunger_to_nw) ]) taper.close(True) block.add(taper) taper_top = dxf.polyline(layer=layer) taper_top.add_vertices([ (-plunger_tip_width / 2, plunger_to_nw), (plunger_tip_width / 2, plunger_to_nw), (plunger_taper_width / 2, plunger_tip_height + plunger_to_nw), (-plunger_taper_width / 2, plunger_tip_height + plunger_to_nw) ]) taper_top.close(True) block.add(taper_top) return block
def output_dxf(box, material, cnc, filename): """ Output the drawing """ drawing = dxf.drawing(filename) drawing.add_layer('TOP') top = dxf.polyline(flags=const.POLYLINE_CLOSED, layer='TOP') top.add_vertices([(0, 0), (box.length, 0), (box.length, box.width), (0, box.width)]) drawing.add(top) drawing.add_layer('BOTTOM') bottom = dxf.polyline(flags=const.POLYLINE_CLOSED, layer='BOTTOM') bottom_coord = [(0, 0), (box.length, 0), (box.length, box.width), (0, box.width)] bottom_coord = [ (x + box.length + margin, y) for x,y in bottom_coord ] bottom.add_vertices(bottom_coord) drawing.add(bottom) drawing.add_layer('SIDE') side = dxf.polyline(flags=const.POLYLINE_CLOSED, layer='SIDE') perimeter = (box.length + box.width)*2 side_coord = [(0, 0), (perimeter, 0), (perimeter, box.height), (0, box.height)] side_coord = [ (x + 2*(box.length + margin), y) for x,y in side_coord ] side.add_vertices(side_coord) drawing.add(side) drawing.save()
def draw_radials(self, d): """draw all radials""" rot = rot_matrix(self.ap) for i in range(self.n): d.add(dxf.polyline(self.seg_r_upper)) d.add(dxf.polyline(self.seg_r_lower)) self.seg_r_upper = [mult_matrix(rot, p) for p in self.seg_r_upper] self.seg_r_lower = [mult_matrix(rot, p) for p in self.seg_r_lower]
def draw_involutes(self, d): """draw all the involutes""" rot = rot_matrix(self.ap) for i in range(self.n): d.add(dxf.polyline(self.seg_lower)) d.add(dxf.polyline(self.seg_upper)) self.seg_upper = [mult_matrix(rot, p) for p in self.seg_upper] self.seg_lower = [mult_matrix(rot, p) for p in self.seg_lower]
def draw_crosshair(d, location, size = 0.125): """add a crosshair to a drawing""" x = location[0] y = location[1] delta = size / 2.0 s1 = ((x-delta, y), (x+delta, y)) s2 = ((x, y-delta), (x, y+delta)) d.add(dxf.polyline(s1)) d.add(dxf.polyline(s2))
def DrawCreator(name, type, parameter, material, thickness=0, address=dirc): file_name = name + '.dxf' #加一步判据 file_name = re.sub('[\\\]|[\/]|[\*]', '_', file_name) drawing = dxf.drawing(file_name) if 'od' in parameter and not ('id' in parameter): drawing.add(dxf.circle(radius=(parameter['od']) / 2, center=(0, 0))) # drawing.add(dxf.text(file_name,height=parameter[0]/4,alignpoint =(0,0))) elif 'od' in parameter and 'id' in parameter and not ('angle' in parameter): drawing.add(dxf.circle(radius=(parameter['od']) / 2, center=(0, 0))) drawing.add(dxf.circle(radius=(parameter['id']) / 2, center=(0, 0))) # drawing.add(dxf.text(file_name,height=parameter[1]/4, alignpoint =(0,0))) elif 'od' in parameter and 'id' in parameter and 'angle' in parameter: drawing.add( dxf.arc(radius=parameter['od'] / 2, center=(0, 0), startangle=0, endangle=parameter['angle'])) drawing.add( dxf.arc(radius=(parameter['id']) / 2, center=(0, 0), startangle=0, endangle=parameter['angle'])) drawing.add( dxf.polyline(points=[(parameter['od'] / 2, 0), ((parameter['id']) / 2, 0)])) drawing.add( dxf.polyline( points=[((parameter['od']) / 2 * math.cos(parameter['angle'] * math.pi / 180), (parameter['od']) / 2 * math.sin(parameter['angle'] * math.pi / 180)), ((parameter['id']) / 2 * math.cos(parameter['angle'] * math.pi / 180), (parameter['id']) / 2 * math.sin(parameter['angle'] * math.pi / 180))])) elif 'w' in parameter and 'l' in parameter: drawing.add( dxf.polyline(points=[(0, 0), ( 0, parameter['w']), (parameter['l'], parameter['w']), (parameter['l'], 0), (0, 0)])) else: print(file_name + '无对应图形') # 创建对应_厚度_的文件夹 if not path.exists(address + '//' + '材料_' + material + '_厚度_' + str(thickness)): #如果文件夹不存在创建 mkdir(address + '//' + '材料_' + material + '_厚度_' + str(thickness)) chdir(address + '\\材料_' + material + '_厚度_' + str(thickness)) drawing.save()
def main(): parser = OptionParser() parser.add_option( "-n", "--name", dest="name", help= "Name of the hinge. Program will load file called <name>.json and output <name>-face.dxf and <name>-temple.dxf.", metavar="HINGENAME") (options, args) = parser.parse_args() if options.name == None: sys.stderr.write("Not enough arguments") parser.print_help() sys.exit(0) name = options.name infile = open(name + ".json") hinge = json.loads(infile.read()) face = hinge["face_contour"] temple = hinge["temple_contour"] face_hole_diam = hinge["drill_dia"] temple_hole_diam = hinge["drill_dia"] face_holes = hinge["face_holes"] temple_holes = hinge["temple_holes"] face_drawing = dxf.drawing("./%s-face.dxf" % name) temple_drawing = dxf.drawing("./%s-temple.dxf" % name) face_drawing.add_layer("OUTLINE", color=1) face_drawing.add_layer("HOLES", color=2) temple_drawing.add_layer("OUTLINE", color=1) temple_drawing.add_layer("HOLES", color=2) face_outline = dxf.polyline(layer="OUTLINE", thickness=0.1) face_outline.add_vertices(face) face_drawing.add(face_outline) for hole in face_holes: circ = dxf.circle(face_hole_diam / 2.0, hole, layer="HOLES", thickness=0.1) face_drawing.add(circ) face_drawing.save() temple_outline = dxf.polyline(layer="OUTLINE", thickness=0.1) temple_outline.add_vertices(temple) temple_drawing.add(temple_outline) for hole in temple_holes: circ = dxf.circle(temple_hole_diam / 2.0, hole, layer="HOLES", thickness=0.1) temple_drawing.add(circ) temple_drawing.save()
def block(length, height, inner_height, inner_length): block_lx = -length / 2 block_rx = length / 2 block_y = float(elem1[1]) vertical_depth = (length - inner_length) / 2 drawing.add( dxf.line((block_lx, block_y), (block_rx, block_y), color=75, layer='Block')) block_height = block_y + height horizontal_depth = height - inner_height inner_lx = block_lx + vertical_depth inner_rx = block_rx - vertical_depth inner_y = block_y + horizontal_depth blockList = [(block_lx, block_y), (block_rx, block_y), (block_rx, block_height), (inner_rx, block_height), (inner_rx, inner_y), (inner_lx, inner_y), (inner_lx, block_height), (block_lx, block_height), (block_lx, block_y)] drawing.add(dxf.polyline(blockList, color=75, layer='Block')) return blockList
def dxfmaker(Bdata, prof, rim, cup): Bmatrix2 = [( float(x[0]), float(x[1]), ) for x in Bdata] prof2 = [( float(x[0]), float(x[1]), ) for x in prof] rim2 = [( float(x[0]), float(x[1]), ) for x in rim] cup2 = [( float(x[0]), float(x[1]), ) for x in cup] drawing = dxf.drawing('drawing.dxf') polyline = dxf.polyline(linetype='LINE') polyline.add_vertices(Bmatrix2) polyline.add_vertices(prof2) polyline.add_vertices(rim2) polyline.add_vertices(cup2) drawing.add(polyline) drawing.save() return
def create_dxf(p): drawing = dxf.drawing('test.dxf') drawing.add_layer('OUTLINE', color=1) polyline = dxf.polyline(layer="OUTLINE") polyline.add_vertices(p) drawing.add(polyline) drawing.save()
def skewRect(corner, width, height, offset, newLength, edge=1, **kwargs): #>>>>>>>> Deprecated, use Entities.SkewRect instead <<<<<<<<<< #quadrangle drawn counterclockwise starting from bottom left #edges are indexed 0-3 correspondingly #edge 1 is default (east edge ) pts = [(corner[0], corner[1]), (corner[0] + width, corner[1]), (corner[0] + width, corner[1] + height), (corner[0], corner[1] + height)] direction = edge // 2 > 0 and -1 or 1 if (edge % 2 == 0): #horizontal delta = 0.5 * (newLength - width) * direction pts[edge] = (pts[edge][0] + offset[0] - delta, pts[edge][1] + offset[1]) pts[(edge + 1) % 4] = (pts[(edge + 1) % 4][0] + offset[0] + delta, pts[(edge + 1) % 4][1] + offset[1]) else: #vertical delta = 0.5 * (newLength - height) * direction pts[edge] = (pts[edge][0] + offset[0], pts[edge][1] + offset[1] - delta) pts[(edge + 1) % 4] = (pts[(edge + 1) % 4][0] + offset[0], pts[(edge + 1) % 4][1] + offset[1] + delta) taper = dxf.polyline(points=pts, flags=0, **kwargs) taper.close() return taper
def SaveDXF(self): # Creates a dxf-file with the name written in the FileInput widget, adding the extension .dxf if it's not # present. Then creates a polyline entity in that file resembling the planned trajectory of the list, ignoring # all instructions in the list other than those with the 'go to: '-tag. Finally, the list of the ActionInputBox # widget is refreshed. filename = self._widget.FileInput.text() l = len(filename) if l > 3: if filename[(l-4):l] != '.dxf': filename = filename + '.dxf' else: filename = filename + '.dxf' drawing = dxfE.drawing(self.pwd + '/src/kampala/gui/src/gui/DXFFiles/' + filename) trajectory_points = [] for point in self.pointlist: if point[0] == 'go to: ': trajectory_points.append(point[1]) drawing.add(dxfE.polyline(trajectory_points)) drawing.save() self.filelist = os.listdir(self.pwd + '/src/kampala/gui/src/gui/DXFFiles') self._widget.DXFInputBox.clear() self._widget.DXFInputBox.insertItems(0,self.filelist)
def room_to_polylines(fp, room_id): # prepare the array to return polyline_arr = [] # compute the oriented boundary boundary_list = fp.compute_room_oriented_boundary(room_id) # iterate over each boundary for bi in range(len(boundary_list)): # prepare the next polyline pl = dxf.polyline() # make the array of vertices and CONVERT UNITS TO FEET verts = [ \ (fp.verts[vi][0]*METERS2FEET,fp.verts[vi][1]*METERS2FEET) \ for vi in boundary_list[bi] ] pl.add_vertices(verts) pl.close() # make the polyline polyline_arr.append(pl) # return the final list return polyline_arr
def draw_single(drawing, x1, y1, l1, l2, l3, l4, angle): d = (l1 - l3) / 2 if angle == 1: x2, y2 = x1, y1 + l2 x8, y8 = x1 + l1, y1 x7, y7 = x8, y2 x3, y3 = x2 + d, y2 x4, y4 = x3, y3 - l4 x5, y5 = x4 + l3, y4 x6, y6 = x5, y2 elif angle == 2: x2, y2 = x1 + l2 * SIN, y1 + l2 * COS x3, y3 = x2 + d * COS, y2 - d * SIN x4, y4 = x3 - l4 * SIN, y3 - l4 * COS x5, y5 = x4 + l3 * COS, y4 - l3 * SIN x6, y6 = x5 + l4 * SIN, y5 + l4 * COS x7, y7 = x6 + d * COS, y6 - d * SIN x8, y8 = x7 - l2 * SIN, y7 - l2 * COS else: x2, y2 = x1 - l2 * SIN, y1 + l2 * COS x3, y3 = x2 + d * COS, y2 + d * SIN x4, y4 = x3 + l4 * SIN, y3 - l4 * COS x5, y5 = x4 + l3 * COS, y4 + l3 * SIN x6, y6 = x5 - l4 * SIN, y5 + l4 * COS x7, y7 = x6 + d * COS, y6 + d * SIN x8, y8 = x7 + l2 * SIN, y7 - l2 * COS drawing.add( dxf.polyline(points=[(x1, y1), (x2, y2), (x3, y3), (x4, y4), ( x5, y5), (x6, y6), (x7, y7), (x8, y8), (x1, y1)]))
def SaveDXF(self): # Creates a dxf-file with the name written in the FileInput widget, adding the extension .dxf if it's not # present. Then creates a polyline entity in that file resembling the planned trajectory of the list, ignoring # all instructions in the list other than those with the 'go to: '-tag. Finally, the list of the ActionInputBox # widget is refreshed. filename = self._widget.FileInput.text() l = len(filename) if l > 3: if filename[(l - 4):l] != '.dxf': filename = filename + '.dxf' else: filename = filename + '.dxf' drawing = dxfE.drawing(self.pwd + '/src/kampala/gui/src/gui/DXFFiles/' + filename) trajectory_points = [] for point in self.pointlist: if point[0] == 'go to: ': trajectory_points.append(point[1]) drawing.add(dxfE.polyline(trajectory_points)) drawing.save() self.filelist = os.listdir(self.pwd + '/src/kampala/gui/src/gui/DXFFiles') self._widget.DXFInputBox.clear() self._widget.DXFInputBox.insertItems(0, self.filelist)
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)
def emit_dxf(self, d): x = [] for p in self.points: p.emit_dxf(d) x.append((p.x, p.y)) flags = (0, dxfwrite.POLYLINE_CLOSED)[self.closed] d.add(dxf.polyline(x, flags = flags))
def create_dxf(self, file_path, polyline_controller, model, calib_controller): """ Creates a DXF file at the given 'file_path' location """ if polyline_controller: # Create a DXF object drawing = dxf.drawing(file_path) points = [] # Header information self.add_header(drawing, '$ACADVER', 'AC1014') # Add the polylines drawing.add_layer('POLYLINES', color=2) # DGZ 16 Aug 2012 # Bug fix for DXF y-axis flipping error # code provided by Adam Childs # Convert (0, 0) to bottom-left instead of upper-left for drill program # sY, sX = model.get_image_shape() # Loops through all polylines for polyline in polyline_controller.polylines: # Loops through all verticies of each polyline for vertex in polyline.verticies: try: x = int(vertex.get_xdata()) y = int(vertex.get_ydata()) except TypeError: # This error is thrown when one of the user's polylines goes outside the coordinates of the image. # For some reason (that I'm not sure of at the moment), the data is put into a 1 element list. So # the fix is to just take the 0th element of the list and then cast it to an integer... # # Adam Childs (11/17/2012) x = int(vertex.get_xdata()[0]) y = int(vertex.get_ydata()[0]) y = sY - y x /= float(calib_controller.pixels_per_unit) y /= float(calib_controller.pixels_per_unit) # Set the units in mm if calib_controller.unit == 'cm': x *= 10 y *= 10 elif calib_controller.unit == 'in': x *= 25.4 y *= 25.4 points.append((x, y)) # Adds the points to a polyline object, which is added to the DXF file drawing.add(dxf.polyline(points)) points = [] # Reset points for the next polyline to use drawing.save() else: wx.MessageBox('No polylines have been found. Please add some.', 'No polylines!', wx.OK | wx.ICON_ERROR) return
def kapakciz(self, dwg, xbase, ybase): points = [(0.33 + xbase, 0 + ybase), (0.21 + xbase, 0 + ybase), (0.18 + xbase, 0.03 + ybase), (-0.55 + xbase, 0.03 + ybase), (-0.58 + xbase, 0 + ybase), (-0.7 + xbase, 0 + ybase), (-0.7 + xbase, 0.1 + ybase), (0.32 + xbase, 0.1 + ybase), (0.33 + xbase, 0 + ybase)] polyline = dxf.polyline(points) dwg.add(polyline)
def WriteDXF(filename, lines, elevations, scaler): drawing = DXFEngine.drawing(filename) for idx in xrange(len( lines )): points = [] for point in lines[idx]: points.append(scaler.inverse((point[0], point[1]))) drawing.add(DXFEngine.polyline(points, polyline_elevation = (0,0,elevations[idx]))) drawing.save()
def main(): parser = OptionParser() parser.add_option("-n", "--name", dest="name", help="Name of the hinge. Program will load file called <name>.json and output <name>-face.dxf and <name>-temple.dxf.", metavar = "HINGENAME") (options, args) = parser.parse_args() if options.name == None: sys.stderr.write("Not enough arguments") parser.print_help() sys.exit(0) name = options.name infile = open(name + ".json") hinge = json.loads(infile.read()) face = hinge["face_contour"] temple = hinge["temple_contour"] face_hole_diam = hinge["drill_dia"] temple_hole_diam = hinge["drill_dia"] face_holes = hinge["face_holes"] temple_holes = hinge["temple_holes"] face_drawing = dxf.drawing("./%s-face.dxf" % name) temple_drawing = dxf.drawing("./%s-temple.dxf" % name) face_drawing.add_layer("OUTLINE", color=1) face_drawing.add_layer("HOLES", color=2) temple_drawing.add_layer("OUTLINE", color=1) temple_drawing.add_layer("HOLES", color=2) face_outline = dxf.polyline(layer="OUTLINE", thickness = 0.1) face_outline.add_vertices(face) face_drawing.add(face_outline) for hole in face_holes: circ = dxf.circle(face_hole_diam/2.0, hole, layer="HOLES", thickness=0.1) face_drawing.add(circ) face_drawing.save() temple_outline = dxf.polyline(layer="OUTLINE", thickness = 0.1) temple_outline.add_vertices(temple) temple_drawing.add(temple_outline) for hole in temple_holes: circ = dxf.circle(temple_hole_diam/2.0, hole, layer="HOLES", thickness=0.1) temple_drawing.add(circ) temple_drawing.save()
def main(argv): filename = '../../ag03.dat' chord = [300.0, 290.0, 280.0, 270.0, 260.0, 250.0] try: opts, args = getopt.getopt(argv, "c:f:o:", ["chord=", "filename=", "outputfilename="]) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ("-c", "chord="): chord = float(arg) elif opt in ("-f", "filename="): filename = str(arg) elif opt in ("-o", "outputfilename="): outputfilename = str(arg) #DXF related INIT (root, ext) = os.path.splitext(outputfilename) saveName = root + '.dxf' drawing = dxf.drawing(saveName) #I found the below constant on the internet, this could use verification chordnumber = 1.0 for c in chord: scale = 1.0 xOffset = 45.0 yOffset = 45.0 linePoints = [] #pts = "" line = 0 # Read airfoil data spamReader = csv.reader(open(filename, 'rb'), delimiter=' ', quotechar='|', skipinitialspace="true") for row in spamReader: #Skip the first line of header information if (line != 0): #Format and store in a string #p= ((float(row[0])*chord+xOffset)*scale, (float(row[1])*-chord+yOffset)*scale) #swap the pomits around to orinetate vertically p = (float(row[1]) * c + xOffset * chordnumber, float(row[0]) * c) linePoints.append(p) print p, 'x', (row[0], row[1]) line = 1 polyline = dxf.polyline(linetype='CONTINUOUS') polyline.add_vertices(linePoints) drawing.add(polyline) chordnumber = chordnumber + 1.0 drawing.save()
def bilezikciz1000(self, dwg, xbase, ybase, h): points_sag = [(0.7 + xbase, h + ybase), (0.7 + xbase, 0 + ybase), (0.58 + xbase, 0 + ybase), (0.55 + xbase, 0.03 + ybase), (0.5 + xbase, 0.03 + ybase), (0.5 + xbase, h + 0.03 + ybase), (0.55 + xbase, h + 0.03 + ybase), (0.58 + xbase, h + ybase), (0.7 + xbase, h + ybase)] points_sol = [(-0.7 + xbase, h + ybase), (-0.7 + xbase, 0 + ybase), (-0.58 + xbase, 0 + ybase), (-0.55 + xbase, 0.03 + ybase), (-0.5 + xbase, 0.03 + ybase), (-0.5 + xbase, h + 0.03 + ybase), (-0.55 + xbase, h + 0.03 + ybase), (-0.58 + xbase, h + ybase), (-0.7 + xbase, h + ybase)] polyline_sag = dxf.polyline(points_sag) polyline_sol = dxf.polyline(points_sol) dwg.add(polyline_sag) dwg.add(polyline_sol)
def writeVectorDXF(nodes, VMin, VMax, eps, scale, fname): colMono = 7 arrow = [(1.0,0.0),(0.6,-0.1),(0.6,0.1),(1.0,0.0)] arrowline = [(0.0,0.0),(0.6,0.0)] dwg = dxf.drawing(fname) # create block vectorsymbol = dxf.block(name='vector') vectorsymbol.add( dxf.polyline(arrow, color=0) ) vectorsymbol.add( dxf.polyline(arrowline, color=0) ) # add block definition to the drawing dwg.blocks.add(vectorsymbol) nOfVectors = 0 for nID in nodes: x = nodes[nID][0] y = nodes[nID][1] u = nodes[nID][2] v = nodes[nID][3] velocity = (u**2.0 + v**2.0)**(1.0/2.0) phi = math.atan2(v,u)*180.0/math.pi # write block, if value is inside a given band blockScale = scale * velocity if velocity <= VMax and velocity >= VMin: if velocity < eps and velocity > -eps: continue else: dwg.add(dxf.insert2(blockdef=vectorsymbol, insert= (x, y), xscale=blockScale, yscale=blockScale, layer='0', color = colMono, rotation = phi)) nOfVectors += 1 dwg.save() return nOfVectors
def main(argv): filename = '../../ag03.dat' chord = [300.0, 290.0, 280.0, 270.0, 260.0, 250.0] try: opts, args = getopt.getopt(argv, "c:f:o:", ["chord=", "filename=", "outputfilename="]) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ("-c", "chord="): chord = float(arg) elif opt in ("-f", "filename="): filename = str(arg) elif opt in ("-o", "outputfilename="): outputfilename = str(arg) #DXF related INIT (root, ext) = os.path.splitext(outputfilename) saveName = root+'.dxf' drawing = dxf.drawing(saveName) #I found the below constant on the internet, this could use verification chordnumber = 1.0 for c in chord: scale = 1.0 xOffset = 45.0 yOffset = 45.0 linePoints = [] #pts = "" line= 0 # Read airfoil data spamReader = csv.reader(open(filename, 'rb'), delimiter=' ', quotechar='|', skipinitialspace="true") for row in spamReader: #Skip the first line of header information if(line!=0): #Format and store in a string #p= ((float(row[0])*chord+xOffset)*scale, (float(row[1])*-chord+yOffset)*scale) #swap the pomits around to orinetate vertically p = ( float(row[1])*c + xOffset*chordnumber , float(row[0])*c ) linePoints.append(p) print p,'x', (row[0],row[1]) line=1 polyline= dxf.polyline(linetype='CONTINUOUS') polyline.add_vertices( linePoints ) drawing.add(polyline) chordnumber = chordnumber + 1.0 drawing.save()
def button(drawing, x, y): polyline = dxf.polyline(layer='CUTSOUTER', color=5) polyline.add_vertices([(x, y), (x + (p_thickness * 0), y + (p_thickness * 2)), (x + (p_thickness * 0.75), y + (p_thickness * 2)), (x + (p_thickness * 0.75), y + (p_thickness * 1)), (x + (p_thickness * 3), y + (p_thickness * 1)), (x + (p_thickness * 3), y + (p_thickness * 0)), (x, y)]) drawing.add(polyline)
def create_dxf(filename, polys): drawing = dxf.drawing(filename) drawing.add_layer('OUTLINE', color=1) for p in polys: polyline = dxf.polyline(layer="OUTLINE") p = p + [p[0], p[1]] # Close the polygon to avoid a cusp polyline.add_vertices(p) drawing.add(polyline) drawing.save()
def ayarbilezikciz(self, dwg, xbase, ybase): points_sag = [ (0.33 + xbase, 0.1 + ybase), (0.33 + xbase, 0 + ybase), (0.21 + xbase, 0 + ybase), (0.18 + xbase, 0.03 + ybase), (0.13 + xbase, 0.03 + ybase), (0.13 + xbase, 0.13 + ybase), (0.18 + xbase, 0.13 + ybase), (0.21 + xbase, 0.1 + ybase), (0.33 + xbase, 0.1 + ybase) ] points_sol = [ (-0.7 + xbase, 0.1 + ybase), (-0.7 + xbase, 0 + ybase), (-0.58 + xbase, 0 + ybase), (-0.55 + xbase, 0.03 + ybase), (-0.5 + xbase, 0.03 + ybase), (-0.5 + xbase, 0.13 + ybase), (-0.55 + xbase, 0.13 + ybase), (-0.58 + xbase, 0.1 + ybase), (-0.7 + xbase, 0.1 + ybase) ] polyline_sag = dxf.polyline(points_sag) polyline_sol = dxf.polyline(points_sol) dwg.add(polyline_sag) dwg.add(polyline_sol)
def button(drawing, x, y): polyline= dxf.polyline(layer='CUTSOUTER', color=5) polyline.add_vertices( [(x,y), (x+(p_thickness*0),y+(p_thickness*2)), (x+(p_thickness*0.75),y+(p_thickness*2)), (x+(p_thickness*0.75),y+(p_thickness*1)), (x+(p_thickness*3),y+(p_thickness*1)), (x+(p_thickness*3),y+(p_thickness*0)), (x,y) ]) drawing.add(polyline)
def draw_base(self, d): c = circle((0.0, self.offset), self.radius) segs = [] theta = 0.0 for i in xrange(_STEPS + 1): l = line((0.0, 0.0), (math.cos(theta), math.sin(theta))) t_vals = line2circle(l, c) segs.append(l.xy(max(t_vals))) theta += theta_delta d.add(dxf.polyline(segs))
def comp2dxf(comp, fname, sample_interval, traverse_interval, scale, clip, layer): """ comp; Numpy array of shape length, width fname; filepath to save dxf sample_interval; distance between samples (m) traverse_interval; distance between traverses scale; z units/cm clip; value to clip data at (z units) layer; name of dxf layer (string) """ #Copies Comp & Flips along horizontal axis #Copy to avoid flipping,clipping original data #FlipUD due to positional referencing comp = np.flipud(np.copy(comp)) #Initiates the dxf using DXFEngine drawing = dxf.drawing(fname) #Creates a layer for the polylines to reside drawing.add_layer(str(layer)) #sets the first line position to be the centre of a traverse y = 0.5 * traverse_interval #iterates through the traverses for row in comp: #Calculates the x position of each data point x_pos = np.arange(len(row)) x_pos = np.multiply(x_pos, sample_interval) #clips the magnitude according to user input y_pos = np.clip(row, -clip, clip) #scales the magnitude according to user input y_pos = np.divide(np.multiply(y_pos, scale), clip * 100) #shifts the magnitude to centre on correct traverse location y_pos = np.add(y_pos, y) #calculates position of next traverse y += traverse_interval #splits traverses on Nan. Polylines cannot bridge Nan lines = using_clump(x_pos, y_pos) #For each traverse section (from nan splitting) creates a polyline & adds to drawing for line in lines: polyline = dxf.polyline(layer=str(layer)) polyline.add_vertices(line) drawing.add(polyline) #Saves Drawing drawing.save()
def comp2dxf(comp, fname, sample_interval, traverse_interval, scale, clip, layer): """ comp; Numpy array of shape length, width fname; filepath to save dxf sample_interval; distance between samples (m) traverse_interval; distance between traverses scale; z units/cm clip; value to clip data at (z units) layer; name of dxf layer (string) """ #Copies Comp & Flips along horizontal axis #Copy to avoid flipping,clipping original data #FlipUD due to positional referencing comp = np.flipud(np.copy(comp)) #Initiates the dxf using DXFEngine drawing = dxf.drawing(fname) #Creates a layer for the polylines to reside drawing.add_layer(str(layer)) #sets the first line position to be the centre of a traverse y = 0.5*traverse_interval #iterates through the traverses for row in comp: #Calculates the x position of each data point x_pos = np.arange(len(row)) x_pos = np.multiply(x_pos,sample_interval) #clips the magnitude according to user input y_pos = np.clip(row,-clip,clip) #scales the magnitude according to user input y_pos = np.divide(np.multiply(y_pos,scale),clip*100) #shifts the magnitude to centre on correct traverse location y_pos = np.add(y_pos, y) #calculates position of next traverse y += traverse_interval #splits traverses on Nan. Polylines cannot bridge Nan lines = using_clump(x_pos, y_pos) #For each traverse section (from nan splitting) creates a polyline & adds to drawing for line in lines: polyline = dxf.polyline(layer=str(layer)) polyline.add_vertices(line) drawing.add(polyline) #Saves Drawing drawing.save()
def drawNotch(s, drawing, xOffset, yOffset): # Draw start notch x0 = xOffset y0 = yOffset x1 = x0 + s.barWidth y1 = y0 + s.notchWidth drawing.add( dxf.polyline(points=[(x0, y0), (x1, y0), (x1, y1), (x0, y1), (x0, y0)])) return (x0, y0, x1, y1)
def encode_feature(self, feature): if feature["geometry"]["type"] == "Point": self._drawing.add(dxf.point(point=(feature["geometry"]["coordinates"][0],feature["geometry"]["coordinates"][1]))) elif feature["geometry"]["type"] == "LineString": polyline= dxf.polyline() coords = feature["geometry"]["coordinates"] for coord in coords: polyline.add_vertex((coord[0], coord[1])) self._drawing.add(polyline) elif feature["geometry"]["type"] == "Polygon": polygon = dxf.polyline() coords = feature["geometry"]["coordinates"] for coord in coords: for point in coord: polygon.add_vertex((point[0], point[1])) polygon.close() self._drawing.add(polygon)
def temelciz1000(self, dwg, xbase, ybase): # Cadtoolsdan alindi. points = [(-0.5 + xbase, 0.25 + ybase), (-0.5 + xbase, 1.23 + ybase), (-0.55 + xbase, 1.23 + ybase), (-0.58 + xbase, 1.2 + ybase), (-0.7 + xbase, 1.2 + ybase), (-0.7 + xbase, 0 + ybase), (0.7 + xbase, 0 + ybase), (0.7 + xbase, 1.2 + ybase), (0.58 + xbase, 1.2 + ybase), (0.55 + xbase, 1.23 + ybase), (0.5 + xbase, 1.23 + ybase), (0.5 + xbase, 0.25 + ybase), (-0.5 + xbase, 0.25 + ybase)] polyline = dxf.polyline(points) dwg.add(polyline)
def konikciz1000(self, dwg, xbase, ybase): points_sag = [ (0.7 + xbase, 0.15 + ybase), (0.64 + xbase, 0.15 + ybase), (0.59 + xbase, 0.18 + ybase), (0.33 + xbase, 0.7 + ybase), (0.21 + xbase, 0.7 + ybase), (0.18 + xbase, 0.73 + ybase), (0.13 + xbase, 0.73 + ybase), (0.13 + xbase, 0.7 + ybase), (0.5 + xbase, 0.03 + ybase), (0.55 + xbase, 0.03 + ybase), (0.58 + xbase, 0 + ybase), (0.7 + xbase, 0 + ybase), (0.7 + xbase, 0.15 + ybase) ] points_sol = [ (-0.7 + xbase, 0.7 + ybase), (-0.7 + xbase, 0 + ybase), (-0.58 + xbase, 0 + ybase), (-0.55 + xbase, 0.03 + ybase), (-0.5 + xbase, 0.03 + ybase), (-0.5 + xbase, 0.73 + ybase), (-0.55 + xbase, 0.73 + ybase), (-0.58 + xbase, 0.7 + ybase), (-0.7 + xbase, 0.7 + ybase) ] polyline_sag = dxf.polyline(points_sag) polyline_sol = dxf.polyline(points_sol) dwg.add(polyline_sag) dwg.add(polyline_sol)
def write_layer_paths(self, paths, number): # for path in paths: # x_avg = sum(d[0] for d in path[1:]) / (len(path)-1) * PPMM # y_avg = sum(d[1] for d in path[1:]) / (len(path)-1) * PPMM # self.f.write('0 0 1 setrgbcolor\n') # self.f.write('%f %f moveto ' % (x_avg, y_avg)) # self.f.write('(%s) dup stringwidth pop 2 div neg 0 rmoveto false charpath\n' % (number)) # self.f.write('closepath\nstroke\nrestore\nsave\nnewpath\n') for path in paths: pline = dxf.polyline(points=path, layer="LINES", color=RED) self.f.add(pline)
def button(drawing, x, y): polyline= dxf.polyline(layer='CUTSOUTER', color=6) polyline.add_vertices( [(x,y), (x,y+1), (x+2,y+1), (x+2,y+3), (x+4,y+3), (x+4,y+1), (x+6,y+1), (x+6,y), (x,y) ]) drawing.add(polyline)
def composite_on_dxf_using_polygons(self): drawing = dxf.drawing() for c in self._polygon.get_palet(): drawing.add_layer(c.name, color=c.value) #print(c.name) for poly in self._polygon.polygon_list: polyline = dxf.polyline(linetype='DOT', layer=poly.color_layer.name) polyline.add_vertices(poly.get_points()) polyline.close() drawing.add(polyline) return drawing
def export_dxf(glider, path="", midribs=0, numpoints=None, *other): outfile = dxf.drawing(path) other = glider.copy_complete() if numpoints: other.numpoints = numpoints ribs = other.return_ribs(midribs) panels = [] points = [] outfile.add_layer('RIBS', color=2) for rib in ribs: outfile.add(dxf.polyface(rib * 1000, layer='RIBS')) outfile.add(dxf.polyline(rib * 1000, layer='RIBS')) return outfile.save()
def encode_feature(self, feature): if feature["geometry"]["type"] == "Point": self._drawing.add( dxf.point(point=(feature["geometry"]["coordinates"][0], feature["geometry"]["coordinates"][1]))) elif feature["geometry"]["type"] == "LineString": polyline = dxf.polyline() coords = feature["geometry"]["coordinates"] for coord in coords: polyline.add_vertex((coord[0], coord[1])) self._drawing.add(polyline) elif feature["geometry"]["type"] == "Polygon": polygon = dxf.polyline() coords = feature["geometry"]["coordinates"] for coord in coords: for point in coord: polygon.add_vertex((point[0], point[1])) polygon.close() self._drawing.add(polygon)
def export_layer_dxf(self, table, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" select st_collect(albion.hole_piece(from_, to_, hole_id)) from albion.{} """.format(table)) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for l in m: r = l.coords drawing.add(dxf.polyline(list(l.coords))) drawing.save()
def export_holes_dxf(self, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" select st_collect(geom) from albion.hole """) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for l in m: r = l.coords drawing.add(dxf.polyline(list(l.coords))) drawing.save()
def create3dPrintFile(points, filename): """ Generates a starter file for creating a 3d print """ drawing = dxf.drawing(filename + '.dxf') for x in points: polyline = dxf.polyline() polyline.add_vertices(x) polyline.close() drawing.add(polyline) drawing.save()
def Paperclip_Rounded(dwg, xy, w, s, L_res, gap, r_ins, UD, line_color, curve_pts=30): #UD = 1 if gap on top, -1 if gap on bottom RL = 1 q = m.transformedQuadrants(UD=UD) #draw pline = dxf.polyline(points=[(xy[0], xy[1])], color=line_color) pline.add_vertices(r_ins > 0 and m.corner( (xy[0] - RL * s / 2, xy[1]), q[2], -1 * UD, r_ins, curve_pts // 2) or [(xy[0] - RL * s / 2, xy[1])]) pline.add_vertices(r_ins > 0 and m.corner( (xy[0] - RL * s / 2, xy[1] - UD * L_res), q[3], -1 * UD, r_ins, curve_pts // 2) or [(xy[0] - RL * s / 2, xy[1] - UD * L_res)]) pline.add_vertices(r_ins > 0 and m.corner( (xy[0] + RL * s / 2, xy[1] - UD * L_res), q[4], -1 * UD, r_ins, curve_pts // 2) or [(xy[0] + RL * s / 2, xy[1] - UD * L_res)]) pline.add_vertices( m.corner((xy[0] + RL * s / 2, xy[1] - UD * gap), q[2], 1 * UD, w / 3, curve_pts)) pline.add_vertices( m.corner((xy[0] + RL * (s / 2 + w), xy[1] - UD * gap), q[1], 1 * UD, w / 3, curve_pts)) pline.add_vertices( m.corner((xy[0] + RL * (s / 2 + w), xy[1] - UD * (L_res + w)), q[4], 1 * UD, w, curve_pts)) pline.add_vertices( m.corner((xy[0] - RL * (s / 2 + w), xy[1] - UD * (L_res + w)), q[3], 1 * UD, w, curve_pts)) pline.add_vertices( m.corner((xy[0] - RL * (s / 2 + w), xy[1] + UD * w), q[2], 1 * UD, w, curve_pts)) pline.add_vertices( m.corner((xy[0] + RL * (s / 2 + w), xy[1] + UD * w), q[1], 1 * UD, w / 3, curve_pts)) pline.add_vertices( m.corner((xy[0] + RL * (s / 2 + w), xy[1]), q[4], 1 * UD, w / 3, curve_pts)) pline.close() dwg.add(pline)
def get_mat_symbol(): p1 = 0.5 p2 = 0.25 points = [(p1, p2), (p2, p1), (-p2, p1), (-p1, p2), (-p1, -p2), (-p2, -p1), (p2, -p1), (p1, -p2)] polygon = dxf.polyline(points, color=2) polygon.close() attdef = dxf.attdef(text='0', tag='num', height=0.7, color=1, halign=dxfwrite.CENTER, valign=dxfwrite.MIDDLE ) symbolblock = dxf.block('matsymbol') symbolblock.add(polygon) symbolblock.add(attdef) dwg.blocks.add(symbolblock) return symbolblock
def writeMeshDXF(fname, nodes, mesh, type): dwg = dxf.drawing(fname) for eID in mesh: p1 = (nodes[mesh[eID][0]][0], nodes[mesh[eID][0]][1], nodes[mesh[eID][0]][2]) p2 = (nodes[mesh[eID][1]][0], nodes[mesh[eID][1]][1], nodes[mesh[eID][1]][2]) p3 = (nodes[mesh[eID][2]][0], nodes[mesh[eID][2]][1], nodes[mesh[eID][2]][2]) if type == 1: dwg.add(dxf.face3d((p1, p2, p3))) elif type == 2: dwg.add(dxf.polyline((p1, p2, p3, p1))) dwg.save()
def bar(drawing, x, y): polyline= dxf.polyline(layer='CUTSOUTER', color=5) polyline.add_vertices( [(x,y), (x,y+bar_length), (x+p_thickness,y+bar_length), (x+p_thickness,y+(bar_length)/2+bar_thickness/2), (x+bar_height-bar_thickness,y+(bar_length)/2+bar_thickness/2), (x+bar_height-bar_thickness,y+bar_length), (x+bar_height,y+bar_length), (x+bar_height,y), (x+bar_height-bar_thickness,y), (x+bar_height-bar_thickness,y+(bar_length)/2-bar_thickness/2), (x+p_thickness,y+(bar_length)/2-bar_thickness/2), (x+p_thickness,y), (x,y) ]) drawing.add(polyline) engrave_text(drawing, x+bar_height/2+.75, y+(bar_length)/2-2.5)
def main(): """Run as a command line program.""" parser = OptionParser() parser.add_option("-i", "--infile", dest="infile", help="read specification from INFILE", metavar="INFILE") parser.add_option("-u", "--url", dest="url", help="read specification from URL", metavar="URL") parser.add_option("-o", "--outdir", dest="outdir", help="write manufacturing instruction files to OUTDIR", metavar="OUTDIR") (options, args) = parser.parse_args() if (options.infile == None and options.url == None): log("Insufficient arguments.") parser.print_help() sys.exit(0) infile = open(options.infile) if options.infile else urllib.urlopen(options.url) o = json.loads(infile.read()) drawing = dxf.drawing('test.dxf') drawing.add_layer('OUTLINE', color=1) lhole = o['lhole_con'] polyline = dxf.polyline(layer="OUTLINE") polyline.add_vertices(lhole) drawing.add(polyline) p2 = poly.erode(3.175/2.0, lhole)[0] p2 = poly.erode(2.0, p2); poly2 = dxf.polyline(layer="OUTLINE") poly2.add_vertices(p2[0]) drawing.add(poly2) drawing.save()
def bar(drawing, x, y): polyline = dxf.polyline(layer='CUTSOUTER', color=5) polyline.add_vertices([ (x, y), (x, y + bar_length), (x + p_thickness, y + bar_length), (x + p_thickness, y + (bar_length) / 2 + bar_thickness / 2), (x + bar_height - bar_thickness, y + (bar_length) / 2 + bar_thickness / 2), (x + bar_height - bar_thickness, y + bar_length), (x + bar_height, y + bar_length), (x + bar_height, y), (x + bar_height - bar_thickness, y), (x + bar_height - bar_thickness, y + (bar_length) / 2 - bar_thickness / 2), (x + p_thickness, y + (bar_length) / 2 - bar_thickness / 2), (x + p_thickness, y), (x, y) ]) drawing.add(polyline) engrave_text(drawing, x + bar_height / 2 + .75, y + (bar_length) / 2 - 2.5)
def main(argv): filename = "../../ag03.dat" chord = 300.0 try: opts, args = getopt.getopt(argv, "c:f:o:", ["chord=", "filename=", "outputfilename="]) except getopt.GetoptError: usage() sys.exit(2) for opt, arg in opts: if opt in ("-c", "chord="): chord = float(arg) elif opt in ("-f", "filename="): filename = str(arg) elif opt in ("-o", "outputfilename="): outputfilename = str(arg) # DXF related INIT (root, ext) = os.path.splitext(outputfilename) saveName = root + ".dxf" drawing = dxf.drawing(saveName) # I found the below constant on the internet, this could use verification scale = 1.0 xOffset = 0.0 yOffset = 0.0 linePoints = [] # pts = "" line = 0 # Read airfoil data spamReader = csv.reader(open(filename, "rb"), delimiter=" ", quotechar="|", skipinitialspace="true") for row in spamReader: # Skip the first line of header information if line != 0: # Format and store in a string p = ((float(row[0]) * chord + xOffset) * scale, (float(row[1]) * -chord + yOffset) * scale) p = (float(row[0]) * chord, float(row[1]) * chord) linePoints.append(p) print p, "x", (row[0], row[1]) line = 1 polyline = dxf.polyline(linetype="CONTINUOUS") polyline.add_vertices(linePoints) drawing.add(polyline) drawing.save()
def writeLineSetDXF(fname, linesetNodes, lineset, dim): dwg = dxf.drawing(fname) for lsID in lineset: nodes = () for i in range(len(lineset[lsID])): x = linesetNodes[lineset[lsID][i]][0] y = linesetNodes[lineset[lsID][i]][1] if dim == 2: nodes += ((x, y),) elif dim == 3: z = linesetNodes[lineset[lsID][i]][2] nodes += ((x, y, z),) dwg.add(dxf.polyline(nodes)) dwg.save()
def xyz2dxf(array,fname,layer): x = array[:,0] y = array[:,1] z = array[:,2] #Initiates the dxf using DXFEngine drawing = dxf.drawing(fname) #Creates a layer for the polylines to reside drawing.add_layer(str(layer)) #splits traverses on Nan. Polylines cannot bridge Nan lines = using_clump(x, y, z=z) #For each traverse section (from nan splitting) creates a polyline & adds to drawing for line in lines: polyline = dxf.polyline(layer=str(layer)) polyline.add_vertices(line) drawing.add(polyline) #Saves Drawing drawing.save()
def flatten_glider(glider, path): # Temporary declarations: allowance_general = 0.01 glider.recalc() parts = [] drawing = dxf.drawing(path) drawing.add_layer('MARKS') drawing.add_layer('CUTS') for cell in glider.cells: left, right = flattened_cell(cell) left_out = left.copy() right_out = right.copy() left_out.add_stuff(-allowance_general) right_out.add_stuff(allowance_general) right_out.data = right_out.data[::-1] left_out += right_out right.data = right.data[::-1] left = left + right left.layer = 'MARKS' left_out.layer = 'CUTS' parts.append([left, left_out]) startx = 0 for liste in parts: startpoint = [startx+0.1, 0] group = DXFList() for element in liste: startx = max(startx, startpoint[0]+max([x[0] for x in element.data])) group.append(dxf.polyline(points=(element.data+startpoint)*1000, layer=element.layer)) drawing.add(group) drawing.save() return True
def block(length, height, inner_height, inner_length): block_lx = -length / 2 block_rx = length / 2 block_y = float(elem1[1]) vertical_depth = (length - inner_length) / 2 drawing.add(dxf.line((block_lx, block_y), (block_rx, block_y), color=75, layer='Block')) block_height = block_y + height horizontal_depth = height - inner_height inner_lx = block_lx + vertical_depth inner_rx = block_rx - vertical_depth inner_y = block_y + horizontal_depth blockList = [(block_lx, block_y), (block_rx, block_y), (block_rx, block_height), (inner_rx, block_height), (inner_rx, inner_y), (inner_lx, inner_y), (inner_lx, block_height), (block_lx, block_height), (block_lx, block_y)] drawing.add(dxf.polyline(blockList, color=75, layer='Block')) return blockList