Esempio n. 1
0
 def __init__(self):
     # create a layer for each pen and give it a matching color
     layers = [
         sdxf.Layer(name=str(pen), color=_pen_to_color[pen])
         for pen in xrange(1, 9)
     ]
     self.dxf = sdxf.Drawing(layers=layers)
Esempio n. 2
0
def main(argv):                         
    filename = '../../ag03.dat'
    chord = 10
                      
    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
    
    d=sdxf.Drawing()
    d.layers.append(sdxf.Layer(name="textlayer",color=3))
    d.layers.append(sdxf.Layer(name="drawinglayer",color=2))
    #I found the below constant on the internet,  this could use verification
    scale = 100 
    xOffset = 0 
    yOffset = 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)
            linePoints.append(p)
            d.layers.append(sdxf.Point(points=(row[0], row[1]), layer="drawinglayer"))
        line=1            
    print linePoints
    d.append(sdxf.Text('Hello World!',point=(3,0),layer="textlayer"))
    d.layers.append(sdxf.Layer(name="drawinglayer",color=2))
    d.append(sdxf.Text('BLUEKULU!',point=(20,20),layer="drawinglayer"))
    #d.layers.append(sdxf.LineList(points=linePoints, layer="drawinglayer"))
    

    (root, ext) = os.path.splitext(outputfilename)
    saveName = root+'.dxf'    
    d.saveas(saveName)
Esempio n. 3
0
def from_gpx_to_dxf(afile):
	if os.path.exists(afile) and os.path.isfile(afile):
		head, tail = os.path.split(afile)
		root, ext = os.path.splitext(tail)
		file_out = os.path.join(head,root+'.dxf')
		#
		gpx_file = open(afile)
		gpx_parser = GPXParser(gpx_file)
		points = gpx_parser.parse()
		drawing = sdxf.Drawing()
		if len(points)>0:
			drawing.append(sdxf.PolyLine(points=points, color=1))	
		drawing.saveas(file_out)
		return True
	return False
Esempio n. 4
0
def build(Rt, Re, angle, outpath):

	# http://aspirespace.org.uk/downloads/Thrust%20optimised%20parabolic%20nozzle.pdf
	#
	# https://github.com/nycresistor/SDXF

	pos = curvepoint(angle, Rt, Re)

	d = sdxf.Drawing()

	d.append(sdxf.PolyLine(points=pos))
	d.append(sdxf.Line(points=[(0,0), (0,10)]))

	d.saveas(outpath)

	return pos
Esempio n. 5
0
    def export_reg(self):
        filename = filedialog.asksaveasfilename()
        if not filename:
            return
        self.show_status('生在生成dxf文件...')
        dxf = sdxf.Drawing()

        # record point list
        point_list = self.process_scan_for_cad()
        with open(filename + '.txt', 'w') as f:
            f.write(str(point_list))
            f.close()

        dxf.append(
            sdxf.LineList(points=point_list, closed=1, layer='drawinglayer'))
        self.show_status('保存中...')
        if '.dxf' not in filename:
            filename += '.dxf'
        dxf.saveas(filename)
        self.show_status('已保存至' + filename)
Esempio n. 6
0
def lines2dxf(lines: list = []):
    '''
    This function receives a list of lists in which the first and the second element is the firs the last point of a line. The points must be 3D.
    Args:
        lines (list of lists) = A list of lists which contains two of each lines' points for the vectorization step.

    Returns:

    '''
    d = sdxf.Drawing()
    layername = 'lines'
    for line in lines:
        pts = [[
            np.float(line[0][0]),
            np.float(line[0][1]),
            np.float(line[0][2])
        ], [np.float(line[1][0]),
            np.float(line[1][1]),
            np.float(line[1][2])]]
        #print (pts)
        d.append(sdxf.Line(points=[pts[0], pts[1]], layer=layername,
                           color=255))
    d.saveas(f'{os.getcwd()}/Lines/3DPlan.dxf')
Esempio n. 7
0
 def __init__(self):
     self.dxf = sdxf.Drawing()
Esempio n. 8
0
import sdxf

# Set your parabola's parameters here
width = 450
focus = width * .23
range = (-width / 2, width / 2)
delta = 5
centerRadius = 5  # radius of circle marking center

d = sdxf.Drawing()

d.layers.append(sdxf.Layer(name="PARABOLA"))


def parabolaPoint(x, focus):
    return (x, (x**2) / (4 * focus))


def addParabola(drawing, focus=1, range=(-5.0, 5.0), delta=0.1):
    middle = sum(range) / 2.0
    if (middle - range[0] < delta):
        p1 = parabolaPoint(range[0], focus)
        p2 = parabolaPoint(range[1], focus)
        drawing.append(sdxf.Line(points=[p1, p2], layer="PARABOLA"))
    else:
        addParabola(drawing, focus, (range[0], middle), delta)
        addParabola(drawing, focus, (middle, range[1]), delta)


d.append(sdxf.Circle(center=(0, focus), radius=centerRadius, layer="PARABOLA"))
addParabola(d, focus, range, delta)
Esempio n. 9
0
def dxf_header():
    return sdxf.Drawing()
Esempio n. 10
0
    def Dxf(Objects, Filters, Points, NumberedPoints, Elements):
        OutputFile = sdxf.Drawing()
        #ExtendedData = {}
        GlobalActions = SettingsDict['Actions'].copy() if 'Actions' in SettingsDict else {}
        GlobalActionOrder = SettingsDict['ActionOrder'] if 'ActionOrder' in SettingsDict else False
        for GlobalAction in GlobalActions:
            ActionType = GlobalActions[GlobalAction].pop('Type')
            ExtendedData, Output = ProcessGlobalAction(ActionType, GlobalActions[GlobalAction], NumberedPoints, Elements, Points)
            if ExtendedData['information'] == 'addObjects':
                for Item in Output:
                    if Item['element_type'] == 'POINT':
                        OutputFile.append(sdxf.Text(text=Item['nodenumber'], point=Item['position'], layer=Item['layer']))
                    if Item['element_type'] == '3DFACE':
                        if len(Item['position'])<4:
                            Item['position'].append(Item['position'][-1])
                        OutputFile.append(sdxf.Face(points=Item['position'], layer=Item['layer']))


        ElementActions = SettingsDict['Element Actions'].copy() if 'Element Actions' in SettingsDict else [] #Copying because we will be pop()ping already processed Actions
        ElementActionOrder = SettingsDict['ElementActionOrder'] if 'ElementActionOrder' in SettingsDict else []
        ActionName = None
        if not isinstance(ElementActionOrder, list):
            ElementActionOrder = [ElementActionOrder]

        for compoundObject in Elements:
            if not compoundObject: continue


            for i, ListElement in enumerate(ElementActionOrder):
                ActionName = ListElement
                ElementAction = ElementActions.pop(ActionName)
                ActionType = ElementAction['Action']
                ElementActionFunction = getElementActionFunction(ActionType)
                NewElements, Output = ElementActionFunction(ElementAction, Element, NumberedPoints, Elements, ExtendedData)
                #2013-04-20 Working here. ERRONEOUS CODE!
                if Output: Format(FormatDict, ActionType, Output, ExtendedData)

            for ElementAction in ElementActions:
                ActionType = ElementActions[ElementAction]['Action']
                ElementActionFunction = getElementActionFunction(ActionType)
                NewElements, Output = ElementActionFunction(ElementActions[ElementAction], compoundObject, NumberedPoints, Elements, ExtendedData)
                #Points[Point], NumberedPoints and Elements get updated

            objectType = compoundObject['elementclass']
            objectLayer = compoundObject['entity_model_data']['layer'] if 'entity_model_data' in compoundObject and compoundObject['entity_model_data'] else objectType
            if objectType == 'LINE_2NODES':
                Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                OutputFile.append(sdxf.Line(points=[Point1, Point2], layer=objectLayer))
            if objectType == 'SOLID_8NODES':
                for x in [    [[0,1,2,3], "bottom"],
                              [[4,5,6,7], "top"],
                              [[0,1,5,4], "side1"],
                              [[1,2,6,5], "side2"],
                              [[2,3,7,6], "side3"],
                              [[3,0,4,7], "side4"]
                              ]:
                    FaceVertices = [NumberedPoints['points'][compoundObject['points'][index]]['point'] for index in x[0]]
                    OutputFile.append(sdxf.Face(points=FaceVertices, layer=objectLayer + " " + x[1]))

                #Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                #Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                #Point3 = NumberedPoints['points'][compoundObject['points'][2]]['point']
                #Point4 = NumberedPoints['points'][compoundObject['points'][3]]['point']
                #OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer=objectLayer))
                #Point1 = NumberedPoints['points'][compoundObject['points'][4]]['point']
                #Point2 = NumberedPoints['points'][compoundObject['points'][5]]['point']
                #Point3 = NumberedPoints['points'][compoundObject['points'][6]]['point']
                #Point4 = NumberedPoints['points'][compoundObject['points'][7]]['point']
                #OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer=objectLayer))
                #Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                #Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                #Point3 = NumberedPoints['points'][compoundObject['points'][4]]['point']
                #Point4 = NumberedPoints['points'][compoundObject['points'][5]]['point']
                #OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer=objectLayer))

            if objectType == 'SOLID_10NODES':
                Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                Point3 = NumberedPoints['points'][compoundObject['points'][2]]['point']
                Point4 = NumberedPoints['points'][compoundObject['points'][3]]['point']
                #Point1 = compoundObject['points'][compoundObject['pointlist'][objectNum][0]]
                #Point2 = compoundObject['points'][compoundObject['pointlist'][objectNum][1]]
                #Point3 = compoundObject['points'][compoundObject['pointlist'][objectNum][2]]
                #Point4 = compoundObject['points'][compoundObject['pointlist'][objectNum][3]]
                OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer=objectLayer))
                #Point1 = compoundObject['points'][compoundObject['pointlist'][objectNum][5]]
                #Point2 = compoundObject['points'][compoundObject['pointlist'][objectNum][6]]
                #Point3 = compoundObject['points'][compoundObject['pointlist'][objectNum][7]]
                #Point4 = compoundObject['points'][compoundObject['pointlist'][objectNum][8]]
                #OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer="Faces"))
            if objectType == 'SOLID_6NODES':
                Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                Point3 = NumberedPoints['points'][compoundObject['points'][2]]['point']
                OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point3], layer=objectLayer))
                Point1 = NumberedPoints['points'][compoundObject['points'][3]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][4]]['point']
                Point3 = NumberedPoints['points'][compoundObject['points'][5]]['point']
                OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point3], layer=objectLayer))
            if objectType == 'FACE_3NODES':
                #Point1 = tuple(list(compoundObject['points'][compoundObject['pointlist'][objectNum][0]])[0:2])
                #Point2 = tuple(list(compoundObject['points'][compoundObject['pointlist'][objectNum][1]])[0:2])
                #Point3 = tuple(list(compoundObject['points'][compoundObject['pointlist'][objectNum][2]])[0:2])
                Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                Point3 = NumberedPoints['points'][compoundObject['points'][2]]['point']
                #OutputFile.append(sdxf.LwPolyLine(points=[Point1, Point2, Point3], flag=1, layer="Polylines"))
                OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point3], layer=objectLayer))
            if objectType == 'FACE_4NODES':
                Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                Point3 = NumberedPoints['points'][compoundObject['points'][2]]['point']
                Point4 = NumberedPoints['points'][compoundObject['points'][3]]['point']
                #OutputFile.append(sdxf.LwPolyLine(points=[Point1, Point2, Point3, Point4], flag=1, layer=objectLayer))
                OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer=objectLayer))
            if objectType == 'PLINE_5NODES':
                Point1 = NumberedPoints['points'][compoundObject['points'][0]]['point']
                Point2 = NumberedPoints['points'][compoundObject['points'][1]]['point']
                Point3 = NumberedPoints['points'][compoundObject['points'][2]]['point']
                Point4 = NumberedPoints['points'][compoundObject['points'][3]]['point']
                #OutputFile.append(sdxf.LwPolyLine(points=[Point1, Point2, Point3, Point4], flag=1, layer="Polylines"))
                OutputFile.append(sdxf.Face(points=[Point1, Point2, Point3, Point4], layer=objectLayer))
            if objectType in ['POLYLINE', 'LWPOLYLINE']:
                PointRefs = compoundObject['points']
                PointList = [NumberedPoints['points'][x]['point'] for x in PointRefs]
                OutputFile.append(sdxf.PolyLine(points=PointList, layer=objectLayer))
        OutputFile.saveas(SettingsDict['OutputFile'])
        return True
Esempio n. 11
0
                                or grid[z + 1][y][x] == CubeType.Empty):
                            faces.append(face)
                        elif face.direction == Direction.POS_X and (
                                x == 0 or grid[z][y][x - 1] == CubeType.Empty):
                            faces.append(face)
                        elif face.direction == Direction.POS_Y and (
                                y == 0 or grid[z][y - 1][x] == CubeType.Empty):
                            faces.append(face)
                        elif face.direction == Direction.POS_Z and (
                                z == 0 or grid[z - 1][y][x] == CubeType.Empty):
                            faces.append(face)
                        else:
                            print "skipping", face, face.direction
                            face.removeCubes()

    blender = sdxf.Drawing()
    space.fixCubes(opts.cube_side)
    space.generateCubes(blender)
    blender.saveas(args[0] + '-3d.dxf')

    # reindex all of the faces as there's a few missing after the hidden-face removal
    for newindex, face in enumerate(
            sorted(faces, key=operator.attrgetter("index"))):
        face.index = newindex

    plans = Plans(opts.sheet_size, args[0] + '-plans-%d.dxf')

    facesDone = []

    for face in sorted(faces, key=operator.attrgetter("index")):
        #print face, face.colour
Esempio n. 12
0
    def save_in_dxf(name, desc):
        z = 0
        d = sdxf.Drawing()
        for room in desc:
            if room.type == 'kitchen':
                wall = room.walls[0]
                p1 = wall.inner_part.point_1
                p2 = wall.inner_part.point_2
                point = (int(p1.x + (p2.x - p1.x) / 2) - 30,
                         int(p1.y + (p2.x - p1.y) / 2))
                d.append(
                    sdxf.Text(text='k',
                              point=[point[0], -point[1], z],
                              height=20))

            for wall in room.walls:
                line = wall.inner_part
                d.append(
                    sdxf.Line(points=[(line.point_1.x, -line.point_1.y,
                                       z), (line.point_2.x, -line.point_2.y,
                                            z)]))

            for opening in room.openings:
                if opening._type == 'door':
                    for line in opening.placement:
                        d.append(
                            sdxf.Line(points=[
                                (line.point_1.x, -line.point_1.y, z),
                                (line.point_2.x, -line.point_2.y, z)
                            ],
                                      color=3))
                    continue

                if opening._type == 'window':
                    for line in opening.placement:
                        d.append(
                            sdxf.Line(points=[
                                (line.point_1.x, -line.point_1.y, z),
                                (line.point_2.x, -line.point_2.y, z)
                            ],
                                      color=4))
                    continue

                if opening._type == 'arch':
                    for line in opening.placement:
                        d.append(
                            sdxf.Line(points=[
                                (line.point_1.x, -int(line.point_1.y), z),
                                (line.point_2.x, -int(line.point_2.y), z)
                            ],
                                      color=2))
                    continue

                if opening._type == 'item':
                    rect = opening.placement[0]
                    p1 = rect.point_1
                    p3 = rect.point_2
                    p2 = Point(p1.x, p3.y)
                    p4 = Point(p3.x, p1.y)
                    lines = [
                        Line(p1, p2),
                        Line(p2, p3),
                        Line(p3, p4),
                        Line(p1, p4)
                    ]
                    for line in lines:
                        d.append(
                            sdxf.Line(points=[
                                (line.point_1.x, -line.point_1.y, z),
                                (line.point_2.x, -line.point_2.y, z)
                            ],
                                      color=5))
                    continue
                if room.furniture:
                    for furniture in room.furniture:
                        rect = furniture.placement
                        p1 = rect.point_1
                        p3 = rect.point_2
                        p2 = Point(p1.x, p3.y)
                        p4 = Point(p3.x, p1.y)
                        lines = [
                            Line(p1, p2),
                            Line(p2, p3),
                            Line(p3, p4),
                            Line(p1, p4)
                        ]
                        for line in lines:
                            d.append(
                                sdxf.Line(points=[
                                    (line.point_1.x, -line.point_1.y, z),
                                    (line.point_2.x, -line.point_2.y, z)
                                ],
                                          color=6))

        d.saveas(name)
Esempio n. 13
0
def main():
    print('Введите длины участков b0-b5:')
    b = [0 for _ in range(6)]
    for i in range(6):
        b[i] = input_float('b%d = ' % i,
                           cond=lambda x: x >= 0,
                           msg_on_false_cond='Длина участка не может быть отрицательной.')

    N = int(input_float('Введите количество волн N = ',
                        cond=lambda x: 0 < x < 1000 and int(x) == x,
                        msg_on_false_cond='Количество волн должно быть целым числом больше нуля.'))

    M = int(input_float('Введите количество клетей M = ',
                        cond=lambda x: 1 < x < 1000 and int(x) == x,
                        msg_on_false_cond='Количество клетей должно быть целым числом больше единицы.'))

    amin = Angle(
        deg=input_float('Введите начальный угол Amin = ',
                        cond=lambda x: 0 <= x < 180,
                        msg_on_false_cond='Начальный угол должен быть больше или равен нулю и меньше 180 градусов.'))

    amax = Angle(
        deg=input_float('Введите конечный угол Amax = ',
                        cond=lambda x: amin.deg < x < 180,
                        msg_on_false_cond='Конечный угол должен быть больше начального, но меньше 180 градусов.'))

    eps = 1e-5

    angles = []

    if amin.rad == 0:
        amin = Angle(rad=sys.float_info.epsilon)
        M += 1  # Не считаем полностью развернутый лист клетью
    else:
        angles.append(amin)
    
    # При минимальном угле альфа получается максимальная ширина и наоборот
    Wmax = partial_width(b, amin.rad)
    Wmin = partial_width(b, amax.rad)

    DW = (Wmax-Wmin)/(M-1)
    W = Wmax - DW

    a = amin
    for i in range(M-2):
        a = Angle(rad=secant_method(lambda x: partial_width(b, x)-W, a.rad, amax.rad, eps))
        W -= DW
        angles.append(a)
    angles.append(amax)

    calc = []
    for i, angle in enumerate(angles):
        profile = Profile(b=b, waves=N, angle=angle)
        print('Клеть №%d' % (i+1))
        profile.print()
        print()
        calc.append(profile)
    
    # Write to dxf file
    d = sdxf.Drawing()

    # Reserve two layers
    # d.layers.append(sdxf.Layer('0'))
    # d.append(sdxf.Line(points=[(0, 0), (0, 0)], layer='0'))
    # d.layers.append(sdxf.Layer('1'))
    # d.append(sdxf.Line(points=[(0, 0), (0, 0)], layer='1'))

    for i, profile in enumerate(calc):
        layer = str(i)
        d.layers.append(sdxf.Layer(layer))
        d.extend(profile.dxf_draw(layer=layer))

    fname = input('Введите имя файла dxf: ')
    if not fname:
        fname = 'profile'
    fname += '.dxf'

    d.saveas(fname)

    print('Файл сохранён.')

    input()