def createdat(spacing): ##### Down Aisle Ties tie = dxf.block(name='tie') dwg.blocks.add(tie) # calculate tie length datx = ((bays + 1) * upx) + (bays * (((bay - 1) * upgap) + (bay * maxx) + ((bay - 1) * palgap))) blockfaces(tie, datx, daty, datz, 0, 0, 0) # Create ties for all levels for m in range(levels): levelheight = datz + palz + loadz + lift lh = levelheight * m # Outer loop to create all the aisles for l in range(aisles): # Calc distance between aisles #spacing = (2 * maxy) + aislew + backgap + (2 * (maxy + deepgap) * ydeep) aisle2 = spacing * l # create outer tie blockref1 = dxf.insert(blockname='tie', layer='CLT_RAK_Pallet_Rack', insert=((0,(aislew/2)+(maxy/2)+(up2up/2)+upy+aisle2, lapproach-datz+lh))) dwg.add(blockref1) # create inter tie blockref2 = dxf.insert(blockname='tie', layer='CLT_RAK_Pallet_Rack', insert=((0,(aislew/2)+(maxy/2)-(up2up/2)-upy-daty+aisle2, lapproach-datz+lh))) dwg.add(blockref2) # create outer tie (opposite) blockref1 = dxf.insert(blockname='tie', layer='CLT_RAK_Pallet_Rack', insert=((0,0-(aislew/2)-(maxy/2)-(up2up/2)-upy-daty+aisle2, lapproach-datz+lh))) dwg.add(blockref1) # create inter tie (opposite) blockref2 = dxf.insert(blockname='tie', layer='CLT_RAK_Pallet_Rack', insert=((0,0-(aislew/2)-(maxy/2)+(up2up/2)+upy+aisle2, lapproach-datz+lh))) dwg.add(blockref2)
def createuprights(spacing): ##### Uprights upright = dxf.block(name='upright') dwg.blocks.add(upright) # calculate upright height upz = lapproach + (levels * (palz + loadz + lift + datz)) - datz - lift + uapproach blockfaces(upright, upx, upy, upz, 0, 0, 0) # Outer loop to create all the aisles for l in range(aisles): # Calc distance between aisles #spacing = (2 * maxy) + aislew + backgap + (2 * (maxy + deepgap) * ydeep) aisle2 = spacing * l # Inner loop to create one aisle for k in range(bays+1): # calculate bay length blen = upx + ((bay - 1) * upgap) + (bay * maxx) + ((bay - 1) * palgap) blength = blen * k # create inner upright blockref1 = dxf.insert(blockname='upright', layer='CLT_RAK_Pallet_Rack', insert=((blength,(aislew/2)+(maxy/2)+(up2up/2)+aisle2, 0))) dwg.add(blockref1) # create outer upright blockref2 = dxf.insert(blockname='upright', layer='CLT_RAK_Pallet_Rack', insert=((blength,(aislew/2)+(maxy/2)-(up2up/2)-upy+aisle2, 0))) dwg.add(blockref2) # create inner upright (opposite) blockref1 = dxf.insert(blockname='upright', layer='CLT_RAK_Pallet_Rack', insert=((blength,0-(aislew/2)-(maxy/2)+(up2up/2)+aisle2, 0))) dwg.add(blockref1) # create outer upright (opposite) blockref2 = dxf.insert(blockname='upright', layer='CLT_RAK_Pallet_Rack', insert=((blength,0-(aislew/2)-(maxy/2)-(up2up/2)-upy+aisle2, 0))) dwg.add(blockref2)
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 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)
def createpallets(spacing): ##### Pallets pallet = dxf.block(name='pallet') dwg.blocks.add(pallet) blockfaces(pallet, palx, paly, palz, 0, 0, 0) # Outermost loop for creating levels for m in range(levels): levelheight = datz + palz + loadz + lift lh = levelheight * m # Outer loop to create all the aisles for l in range(aisles): # Calc distance between aisles #spacing = (2 * maxy) + aislew + backgap + (2 * (maxy + deepgap) * ydeep) aisle2 = spacing * l # Inner loop to create one aisle for k in range(bays): # calculate bay length blen = upx + ((bay - 1) * upgap) + (bay * maxx) + ((bay - 1) * palgap) blength = blen * k # create first bay for i in range(bay): blockref = dxf.insert(blockname='pallet', layer='CLT_PLT_Pallet', insert=(upx+upgap+(maxx/2)-(palx/2)+(i*(maxx + palgap))+blength,(aislew/2)+(maxy/2)-(paly/2)+aisle2,lapproach+lh)) dwg.add(blockref) # create opposite side for j in range(bay): blockref = dxf.insert(blockname='pallet', layer='CLT_PLT_Pallet', insert=(upx+upgap+(maxx/2)-(palx/2)+(j*(maxx + palgap))+blength,0-(aislew/2)-(maxy/2)-(paly/2)+aisle2,lapproach+lh)) dwg.add(blockref)
def generate_template_trophy(h1, h2, w, drawing): """ Generates a outline around all the tropies on the drawing given. (c) shovel """ drawing.add(dxf.line((0, 0), (600,0), color=255, layer='LINES', thickness=0.00)) drawing.add(dxf.line((600, 0), (600,450), color=255, layer='LINES', thickness=0.00)) drawing.add(dxf.line((600,450), (0,450), color=255, layer='LINES', thickness=0.00)) drawing.add(dxf.line((0,450), (0,0), color=255, layer='LINES', thickness=0.00)) refpoint = generate_ref_trophy(h1, h2, w) for i in refpoint[:4]: x,y = i draw(x,y,x+h1,y,drawing) draw(x,y,x,y-w,drawing) draw(x,y-w,x+h2,y-w,drawing) draw(x+h1,y,x+h2,y-w,drawing) for i in refpoint[4:8]: x,y=i draw(x,y,x-h1,y,drawing) draw(x,y,x,y+w,drawing) draw(x,y+w,x-h2,y+w,drawing) draw(x-h2,y+w,x-h1,y,drawing) x,y = refpoint[-2] draw(x,y,x,y+h1,drawing) draw(x,y,x+w,y,drawing) draw(x+w,y,x+w,y+h2,drawing) draw(x+w,y+h2,x,y+h1,drawing) x,y = refpoint[-1] draw(x,y,x,y-h1,drawing) draw(x,y,x-w,y,drawing) draw(x-w,y,x-w,y-h2,drawing) draw(x-w,y-h2,x,y-h1,drawing)
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))
def __init__(self, wafer, chipID, w=40, l=1500, pad_extend=1000, offset=(0, 0), overhang=80): m.BlankCenteredWR10.__init__(self, wafer, chipID, wafer.defaultLayer, offset) #put in holes to define a resistance bar #self.add(dxf.rectangle((-pad_extend+offset[0],0),pad_extend+self.width/2-l/2,self.height,bgcolor=wafer.bg(wafer.defaultLayer))) #self.add(dxf.rectangle((self.width/2 + l/2+offset[0],0),pad_extend+self.width/2-l/2,self.height,bgcolor=wafer.bg(wafer.defaultLayer))) self.add( dxf.rectangle(self.centered((0, -w / 2)), l, self.height / 2 - w / 2 + overhang, halign=const.CENTER, valign=const.BOTTOM, bgcolor=wafer.bg(wafer.defaultLayer))) self.add( dxf.rectangle(self.centered((0, w / 2)), l, self.height / 2 - w / 2 + overhang, halign=const.CENTER, valign=const.TOP, bgcolor=wafer.bg(wafer.defaultLayer)))
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 __init__(self, wafer, chipID, w=40, l=1500, pad_extend=1000, offset=(0, 0)): m.BlankCenteredWR10.__init__(self, wafer, chipID, wafer.defaultLayer, offset) #put in a resistance bar self.add( dxf.rectangle((-pad_extend + offset[0], 0), pad_extend + self.width / 2 - l / 2, self.height, bgcolor=wafer.bg(wafer.defaultLayer))) self.add( dxf.rectangle((self.width / 2 + l / 2 + offset[0], 0), pad_extend + self.width / 2 - l / 2, self.height, bgcolor=wafer.bg(wafer.defaultLayer))) self.add( dxf.rectangle(self.centered((-l / 2, -w / 2)), l, w, bgcolor=wafer.bg(wafer.defaultLayer)))
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()
def std_linetypes(self): """ Create standard linetypes. """ return [DXFEngine.linetype( name, description=desc, pattern=DXFEngine.linepattern(pat)) for name, desc, pat in std.linetypes()]
def __init__(self, wafer, chipID, layer, structures=None, defaults=None, FRAME_NAME='FRAME'): self.wafer = wafer self.width = wafer.chipX - wafer.sawWidth self.height = wafer.chipY - wafer.sawWidth self.chipID = chipID #string (usually) self.ID = 'CHIP_' + str(chipID) self.solid = wafer.solid self.frame = wafer.frame self.layer = layer if defaults is None: self.defaults = {} else: self.defaults = defaults.copy() #setup centering self.center = (self.width / 2, self.height / 2) #initialize the block self.chipBlock = dxf.block(self.ID) #setup structures if structures is not None: self.structures = structures #add a debug frame for actual chip area if wafer.frame: self.add( dxf.rectangle((0, 0), self.width, self.height, layer=wafer.lyr(FRAME_NAME)))
def arrow(bottom_point,arrow_point, length_arrow = 3): drawing.add(dxf.line(bottom_point,arrow_point, color= 7)) vertex = arrow_point 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
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 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))
def Draw(p): lay=0 path=p['path'] n=p['nodes'] d=p['drawing'] rx=p['position'][0] ry=p['position'][1] if 'layer' in p.keys(): lay=p['layer'] for c in path: if c[0]=='line': d.add(dxf.line((rx+n[c[1]][0],ry+n[c[1]][1]), (rx+n[c[2]][0],ry+n[c[2]][1]),layer=lay)) elif c[0]=='arc': cr=geo.CircleFrom3Points(n[c[1]],n[c[3]],n[c[2]]) if cr['Direction']<0: d.add(dxf.arc(center=(rx+cr['Center'][0],ry+cr['Center'][1]), radius=cr['Radius'], startangle=math.degrees(cr['P1Degree']), endangle=math.degrees(cr['P3Degree']), layer=lay)) else: d.add(dxf.arc(center=(rx+cr['Center'][0],ry+cr['Center'][1]), radius=cr['Radius'], startangle=math.degrees(cr['P3Degree']), endangle=math.degrees(cr['P1Degree']), layer=lay)) elif c[0]=='circle': rds=n[c[2]][0]-n[c[1]][0] d.add(dxf.circle(rds,(rx+n[c[1]][0],ry+n[c[1]][1]),layer=lay))
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 save_traced_scene(self,dxf_file): """ write geometry and traced rays to a DXF file for your viewing pleasure. It's no fun with more than a few 100 rays though. >1000 rays look like sonic the sea urchin.""" drawing = dxf.drawing(dxf_file) drawing.add_layer('Rays', color=3) drawing.add_layer('Geometry', color=5) print "Writing results as DXF file." for res in self.results: rays_origin = res[0] rays_dest = res[1] #draw rays to dxf for (r0,rd) in zip(rays_origin,rays_dest): drawing.add(dxf.face3d([r0[0:3], rd[0:3], rd[0:3]], layer="Rays")) #draw facets (m_v0,m_v1,m_v2)=self.geometry for (t0,t1,t2) in zip(m_v0,m_v1,m_v2): drawing.add(dxf.face3d([t0[0:3], t1[0:3], t2[0:3]], layer="Geometry")) drawing.save()
def writeDXF(self): fname = self.ui.lineEditOutputDXF.text() file = open(fname, 'w') rad = 0.25 scale = 1.0 col = 7 dec = self.ui.spinBoxDecimal.value() dwg = dxf.drawing(fname) # create block scalarsymbol = dxf.block(name='symbol') scalarsymbol.add( dxf.circle(radius=rad, color=0) ) # define some attributes scalarsymbol.add( dxf.attdef(insert=(1.25, -1.25), tag='VAL1', height=1.25, color=0) ) # add block definition to the drawing dwg.blocks.add(scalarsymbol) for nID in self.points: x = self.points[nID][0] y = self.points[nID][1] val1 = self.points[nID][2] values = {'VAL1': "%.{0}f".format(dec) % val1} dwg.add(dxf.insert2(blockdef=scalarsymbol, insert=(x, y), attribs=values, xscale=scale, yscale=scale, layer='0', color = col)) dwg.save()
def run(fpfile, dxffile): # read the input floorplan fp = fp_io.Floorplan(fpfile) # prepare the output dxf file drawing = dxf.drawing(dxffile) # iterate over the rooms of the floor plan for room_id in range(fp.num_rooms): # make a layer for this room room_layer_name = 'room_' + str(room_id+1) room_layer = dxf.layer(room_layer_name) room_layer['color'] = 1+room_id # valid colors: [1,255] drawing.layers.add(room_layer) # generate the objects for this room obj_arr = room_to_polylines(fp, room_id) # draw each object in the room for pi in range(len(obj_arr)): # add each object to the drawing obj_arr[pi]['layer'] = room_layer_name obj_arr[pi]['color'] = 256 # color by layer obj_arr[pi]['paper_space'] = 0 # put in model space drawing.add(obj_arr[pi]) # save the drawing to file drawing.save()
def export_sections_dxf(self, graph, filename): with self.connect() as con: cur = con.cursor() cur.execute(""" with hole_idx as ( select s.id as section_id, h.id as hole_id from _albion.named_section as s join _albion.hole as h on s.geom && h.geom and st_intersects(s.geom, st_startpoint(h.geom)) ) select st_collectionhomogenize(st_collect(ef.geom)) from albion.all_edge as e join hole_idx as hs on hs.hole_id = e.start_ join hole_idx as he on he.hole_id = e.end_ and he.section_id = hs.section_id join albion.edge_face as ef on ef.start_ = e.start_ and ef.end_ = e.end_ and not st_isempty(ef.geom) where ef.graph_id='{}' """.format(graph)) drawing = dxf.drawing(filename) m = wkb.loads(bytes.fromhex(cur.fetchone()[0])) for p in m: r = p.exterior.coords drawing.add( dxf.face3d( [tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save()
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
def tgates_side_mirror(layer, tgate_to_nw, tgate_tip_width, tgate_tip_height, tgate_taper_width, blockname): #plungers on just one side of the nanowire block = dxf.block(blockname, layer=layer) block.add( dxf.rectangle((-tgate_tip_width / 2, -tgate_to_nw - tgate_taper_width), tgate_tip_width, tgate_taper_width, rotation=0, layer=layer)) block.add( dxf.rectangle((-tgate_taper_width / 2, -tgate_to_nw - tgate_taper_width - tgate_tip_height), tgate_taper_width, tgate_tip_height, rotation=0, layer=layer)) # block.add(dxf.rectangle((-tgate_tip_width/2,+tgate_to_nw), # tgate_tip_width, tgate_taper_width, rotation = 0, layer = layer)) # block.add(dxf.rectangle((-tgate_taper_width/2, +tgate_to_nw+tgate_taper_width), # tgate_taper_width, tgate_tip_height, rotation = 0, layer = layer)) return block # creating the block
def __init__(self, wafer, chipID, pad, notch, globalOffset=(0, 0)): m.BlankCenteredWR10.__init__(self, wafer, chipID, wafer.defaultLayer, globalOffset) self.wr10x = 2540 + 2 * pad self.wr10y = 1270 + 2 * pad color = wafer.bg(wafer.defaultLayer) #positive regions define metal self.add( dxf.rectangle((self.cx(-self.wr10x / 2), 0), self.wr10x, self.cy(-self.wr10y / 2), bgcolor=color)) self.add( dxf.rectangle((0, self.height), self.width, self.cy(self.wr10y / 2 - self.height), bgcolor=color)) self.add( dxf.rectangle((0, notch), self.cx(-self.wr10x / 2), self.cy(self.wr10y / 2 - notch), bgcolor=color)) self.add( dxf.rectangle((self.cx(self.wr10x / 2), 0), -self.cx(self.wr10x / 2 - self.width), self.cy(self.wr10y / 2), bgcolor=color))
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()
def arc(self, end, center, layer=None): if self.enable: r = xyDist(end, center) if self.svg is not None: self.path.push_arc(self.scaleOffset(end), 0, r, \ large_arc=True, angle_dir='+', \ absolute=True) if self.d is not None: if layer is None: layer = self.lPath else: if not layer in self.definedLayers: self.definedLayers[layer] = True self.d.add_layer(layer, color=self.color, lineweight=0) p0 = self.last p1 = end if xyDist(p0, p1) < MIN_DIST: self.d.add(dxf.circle(r, center, layer=layer)) else: # dprt("p0 (%7.4f, %7.4f) p1 (%7.4f, %7.4f)" % \ # (p0[0], p0[1], p1[0], p1[1])) # if orientation(p0, center, p1) == CCW: # (p0, p1) = (p1, p0) a0 = degrees(calcAngle(center, p0)) a1 = degrees(calcAngle(center, p1)) if a1 == 0.0: a1 = 360.0 # dprt("a0 %5.1f a1 %5.1f" % (a0, a1)) self.d.add(dxf.arc(r, center, a0, a1, layer=layer)) self.last = end
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 export_elementary_volume_dxf(self, graph_id, cell_ids, outdir, closed_only=False): with self.connect() as con: cur = con.cursor() cur.execute(""" select cell_id, row_number() over(partition by cell_id order by closed desc), geom, closed from ( select cell_id, triangulation as geom, albion.is_closed_volume(triangulation) as closed from albion.volume where cell_id in ({}) and graph_id='{}' ) as t """.format(','.join(["'{}'".format(c) for c in cell_ids]), graph_id)) for cell_id, i, wkb_geom, closed in cur.fetchall(): geom = wkb.loads(bytes.fromhex(wkb_geom)) if closed_only and not closed: continue filename = '{}_{}_{}_{}.dxf'.format( cell_id, graph_id, "closed" if closed else "opened", i) path = os.path.join(outdir, filename) drawing = dxf.drawing(path) for p in geom: r = p.exterior.coords drawing.add( dxf.face3d([tuple(r[0]), tuple(r[1]), tuple(r[2])], flags=1)) drawing.save()
def create_dxf(filename): dxf_drawing = dxf.drawing(filename) for y in range(0, 5): x = 0 dxf_drawing.add(dxf.circle(radius=y, center=(x, y * 2))) dxf_drawing.save()
def four_c(A, length, rotation): dwg.add( dxf.clothoid(start=(2, 2), length=length, paramA=A, rotation=rotation, color=1)) dwg.add( dxf.clothoid(start=(2, 2), mirror='x', length=length, paramA=A, rotation=rotation, color=2)) dwg.add( dxf.clothoid(start=(2, 2), mirror='y', length=length, paramA=A, rotation=rotation, color=3)) dwg.add( dxf.clothoid(start=(2, 2), mirror='xy', length=length, paramA=A, rotation=rotation, color=4))
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
def getRectangleDxf(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(height) bgcolor = random.randint(1,255) return dxf.rectangle((y,x), height, width, bgcolor=bgcolor) else: bgcolor = random.randint(1,255) return dxf.rectangle((x, y), width, height, bgcolor=bgcolor)
def raith_alignment_marker(layer, w_r, pw_r, cc_x, cc_y): #program does nothing as written #questions: does the layer name have to be a string? #In this case, the alignment marker elionix block will always be called the elionix block cc = [cc_x, cc_y] block = dxf.block("alignmentmarker_raith", layer=layer) # creating the block block.add( dxf.rectangle((cc[0] - pw_r / 2, cc[1] - w_r / 2, 0), pw_r, w_r, rotation=0, layer=layer)) # long vertical block.add( dxf.rectangle((cc[0] - w_r / 2, cc[1] - pw_r / 2, 0), (w_r - 2 - pw_r) / 2, pw_r, rotation=0, layer=layer)) # short horizonal left block.add( dxf.rectangle((cc[0] + pw_r / 2, cc[1] - pw_r / 2, 0), (w_r - 2 - pw_r) / 2, pw_r, rotation=0, layer=layer)) # short horiztonal right # add block-definition to drawing #drawing.blocks.add(block_name) print("I DID IT RAITH") return block
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 double_dot_etch_block(layer, starting_gap, window_length, etch_window_1, island_1, etch_window_2, island_2, etch_window_3, blockname): block = dxf.block(blockname, layer=layer) # creating the block x_etch_position = starting_gap block.add( dxf.rectangle((x_etch_position, -window_length / 2), etch_window_1, window_length, rotation=0, layer=layer)) x_etch_position = starting_gap + etch_window_1 + island_1 block.add( dxf.rectangle((x_etch_position, -window_length / 2), etch_window_2, window_length, rotation=0, layer=layer)) x_etch_position = starting_gap + etch_window_1 + island_1 + etch_window_2 + island_2 block.add( dxf.rectangle((x_etch_position, -window_length / 2), etch_window_3, window_length, rotation=0, layer=layer)) # short horiztonal right # add block-definition to drawing #drawing.blocks.add(block_name) print("I DID IT ETCH BLOCK") return block
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 material(self, xSize, ySize): if self.svg is not None: self.offset = 0.0 path = self.materialPath if path is None: self.materialPath = Path(stroke_width=.5, stroke='red', \ fill='none') path = self.materialPath path.push('M', (self.scaleOffset((0, 0)))) path.push('L', (self.scaleOffset((xSize, 0)))) path.push('L', (self.scaleOffset((xSize, ySize)))) path.push('L', (self.scaleOffset((0, ySize)))) path.push('L', (self.scaleOffset((0, 0)))) self.path.push('M', (self.scaleOffset((0, 0)))) # dwg = svgwrite.Drawing(name, (svg_size_width, svg_size_height), \ # debug=True) cfg = self.cfg if self.d is not None: orientation = cfg.orientation if orientation == O_UPPER_LEFT: p0 = (0.0, 0.0) p1 = (xSize, 0.0) p2 = (xSize, -ySize) p3 = (0.0, -ySize) elif orientation == O_LOWER_LEFT: p0 = (0.0, 0.0) p1 = (xSize, 0.0) p2 = (xSize, ySize) p3 = (0.0, ySize) elif orientation == O_UPPER_RIGHT: p0 = (0.0, 0.0) p1 = (-xSize, 0.0) p2 = (-xSize, -ySize) p3 = (0.0, -ySize) elif orientation == O_LOWER_RIGHT: p0 = (0.0, 0.0) p1 = (-xSize, 0.0) p2 = (-xSize, ySize) p3 = (0.0, ySize) elif orientation == O_CENTER: p0 = (-xSize / 2, -ySize / 2) p1 = (xSize / 2, -ySize / 2) p2 = (xSize / 2, ySize / 2) p3 = (-xSize / 2, ySize / 2) elif orientation == O_POINT: dxfInput = cfg.dxfInput p0 = (dxfInput.xMin, dxfInput.yMin) p1 = (dxfInput.xMin, dxfInput.yMax) p2 = (dxfInput.xMax, dxfInput.yMax) p3 = (dxfInput.xMax, dxfInput.yMin) else: ePrint("invalid orientation") self.d.add(dxf.line(p0, p1, layer=self.lBorder)) self.d.add(dxf.line(p1, p2, layer=self.lBorder)) self.d.add(dxf.line(p2, p3, layer=self.lBorder)) self.d.add(dxf.line(p3, p0, layer=self.lBorder))
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 dxflist_example(x=0, y=0, w=1, h=1): # dxf list can contain any dxf entity, that supports __dxf__() rect = dxfwrite.DXFList() rect.append(dxf.line(start=(x, y), end=(x + w, y), color=1)) rect.append(dxf.line(start=(x + w, y), end=(x + w, y + h), color=2)) rect.append(dxf.line(start=(x + w, y + h), end=(x, y + h), color=3)) rect.append(dxf.line(start=(x, y + h), end=(x, y), color=4)) return rect
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 addToDrawing(self, drawing, layer='0'): Shape.addToDrawing(self, drawing, layer) if not self.error: if self.p.reverse: arc = dxf.arc(self.p.radius, self.p.centerPoint, self.p.endAngle, self.p.startAngle, layer = '0') else: arc = dxf.arc(self.p.radius, self.p.centerPoint, self.p.startAngle, self.p.endAngle, layer = '0') drawing.add(arc)
def dxflist_example(x=0, y=0, w=1, h=1): # dxf list can contain any dxf entity, that supports __dxf__() rect = dxfwrite.DXFList() rect.append(dxf.line(start=(x, y), end=(x+w, y), color=1)) rect.append(dxf.line(start=(x+w, y), end=(x+w, y+h), color=2)) rect.append(dxf.line(start=(x+w, y+h), end=(x, y+h), color=3)) rect.append(dxf.line(start=(x, y+h), end=(x, y), color=4)) return rect
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_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_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 four_c(A, length, rotation): dwg.add(dxf.clothoid(start=(2, 2), length=length, paramA=A, rotation=rotation, color=1)) dwg.add(dxf.clothoid(start=(2, 2), mirror='x', length=length, paramA=A, rotation=rotation, color=2)) dwg.add(dxf.clothoid(start=(2, 2), mirror='y', length=length, paramA=A, rotation=rotation, color=3)) dwg.add(dxf.clothoid(start=(2, 2), mirror='xy', length=length, paramA=A, rotation=rotation, color=4))
def drawRectangle(drawing,topLeft,w,h): dX,dY = topLeft drawing.add(dxf.line((dX,dY),(dX + w,dY))) drawing.add(dxf.line((dX,dY),(dX,dY + h))) drawing.add(dxf.line((dX + w,dY),(dX + w,dY + h))) drawing.add(dxf.line((dX,dY + h),(dX + w,dY + h)))
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 triangle( cx, cy, sz): cx0 = cx cy0 = cy - TOP_Y * sz cx1 = cx - sz/2 cy1 = cy + BOT_Y * sz cx2 = cx + sz/2 cy2 = cy + BOT_Y * sz drawing.add(dxf.line((cx0, cy0), (cx1, cy1), layer='Prova')) drawing.add(dxf.line((cx1, cy1), (cx2, cy2), color=4)) drawing.add(dxf.line((cx2, cy2), (cx0, cy0), color=2))
def write_dxf(self,dxf_file): """ writes geometry to a file by using the dxfwrite libs.""" drawing = dxf.drawing(dxf_file) drawing.add_layer('0', color=2) for tri in self.triangles: drawing.add(dxf.face3d([self.vertices[tri[0]][0:3], self.vertices[tri[1]][0:3], self.vertices[tri[2]][0:3]], layer="0")) #drawing.add(dxf.text('Test', insert=(0, 0.2), layer='TEXTLAYER')) drawing.save()
def drawBox(drawing, topLeft, size = 0.5): dX,dY = topLeft drawing.add(dxf.line((dX,dY),(dX + size,dY))) drawing.add(dxf.line((dX,dY),(dX,dY + size))) drawing.add(dxf.line((dX + size,dY),(dX + size,dY + size))) drawing.add(dxf.line((dX,dY + size),(dX + size,dY + size)))
def DXFWrite(edges, filename): from dxfwrite import DXFEngine as dxf dwg = dxf.drawing(filename) for e in edges: if e[2] is None: kwargs = {"layer": "Cut"} else: kwargs = {"layer": repr(e[2])} dwg.add(dxf.line((e[0][0], e[0][1]), (e[1][0], e[1][1]), **kwargs)) dwg.save()
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 arc_dxf(self, direction=True): radius = (self.centre - self.cutto).length() a = self.centre - self.cutto b = self.centre - self.cutfrom angle0 = math.atan2(a[1], a[0])/math.pi *180+180 angle1 = math.atan2(b[1], b[0])/math.pi *180+180 if(self.direction=='ccw'): return [dxf.arc(radius, self.centre, angle0, angle1)] else: return [dxf.arc(radius, self.centre, angle1, angle0)]
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()