Exemple #1
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)
Exemple #2
0
def dxf_text(f, x, y, h, txt):
    f.append(sdxf.Text(txt, point=(x, y - h / 2.0), height=h))
Exemple #3
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
Exemple #4
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)
Exemple #5
0
import sdxf

d = sdxf.Drawing()

#set the color of the text layer to green
d.layers.append(sdxf.Layer(name="textlayer", color=3))

#add drawing elements
d.append(sdxf.Text('Hello World!', point=(3, 0), layer="textlayer"))
d.append(sdxf.Line(points=[(0, 0), (1, 1)], layer="drawinglayer"))

d.saveas('hello_world.dxf')