Exemple #1
0
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)
 def draw_line(self, center, length, angle, style='k-', **kwargs):
     self.dxf.append(
         sdxf.Line(points=[[
             center[0] - length / 2 * np.cos(angle), center[1] -
             length / 2 * np.sin(angle)
         ],
                           [
                               center[0] +
                               length / 2 * np.cos(angle), center[1] +
                               length / 2 * np.sin(angle)
                           ]]))
Exemple #3
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
Exemple #4
0
 def drawNumber(self, char, x, y, width, height, layer, reverse=False):
     char = int(char)
     assert char >= 0 and char <= 9, char
     if char == 1:
         return [
             sdxf.Line(points=[(x + width / 2, y),
                               (x + width / 2, y + height)],
                       layer=layer)
         ]
     ret = []
     if char in [0, 2, 3, 5, 6, 7, 8, 9]:  # top bar
         ret.append(sdxf.Line(points=[(x, y), (x + width, y)], layer=layer))
     if char in [0, 1, 4, 8, 9] or (reverse and char in [2, 3, 7]) or (
             not reverse and char in [5, 6]):  # top-right
         ret.append(
             sdxf.Line(points=[(x + width, y), (x + width, y + height / 2)],
                       layer=layer))
     if char in [0, 1, 6, 8] or (reverse and char in [3, 4, 5, 7, 9]) or (
             not reverse and char in [2]):  # bottom-right
         ret.append(
             sdxf.Line(points=[(x + width, y + height / 2),
                               (x + width, y + height)],
                       layer=layer))
     if char in [0, 2, 3, 5, 6, 8, 9]:  # bottom bar
         ret.append(
             sdxf.Line(points=[(x + width, y + height), (x, y + height)],
                       layer=layer))
     if char in [0, 4, 8, 9] or (reverse and char in [5, 6]) or (
             not reverse and char in [2, 3, 7]):  # top-left
         ret.append(
             sdxf.Line(points=[(x, y), (x, y + height / 2)], layer=layer))
     if char in [0, 6, 8] or (reverse and char in [2]) or (
             not reverse and char in [3, 4, 5, 7, 9]):  # bottom-left
         ret.append(
             sdxf.Line(points=[(x, y + height / 2), (x, y + height)],
                       layer=layer))
     if char in [2, 3, 4, 5, 6, 8, 9]:  # middle bar
         ret.append(
             sdxf.Line(points=[(x, y + height / 2),
                               (x + width, y + height / 2)],
                       layer=layer))
     return ret
Exemple #5
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')
Exemple #6
0
	elif t >= math.pi and t < 4*math.pi/3:
		return yepi(t)
	elif t >= 4*math.pi/3 and t < 5 * math.pi / 3:
		return yhypo(t)
	else:
		return yepi(t)
	
#plot2d([[parametric,xctr(t),yctr(t),[t,0,2*%pi]],[parametric,xhypo(t),yhypo(t),[t,0,2*%pi]]],[nticks,80])

i=0
x1 = x(q*i)
y1 = y(q*i)
# s is the number of steps, q is 2 pi divided by s
for i in range(0, s):
        x2 = x(q*(i+1))
        y2 = y(q*(i+1))
        dxf.append( sdxf.Line(points=[(x1,y1),  (x2,y2)], layer="STATOR" ) )
        x1 = x2
        y1 = y2

# need a file name
f = "moinTriple.dxf"

try:
        dxf.saveas(f)
except:
        print("File save error!")
        sys.exit(2)


Exemple #7
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 #8
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)
    def dxf_draw(self, **common):
        d = []
        x = -self.width/2

        # Left edge segment B0 (horizontal)
        if self.b[0] > 0:
            x1 = x + self.b[0]
            d.append(sdxf.Line(points=[(x, self.height), (x1, self.height)], **common))
            x = x1

        for j in range(self.waves):
            # Segment B1 (arc)
            if self.b[1] > 0:
                x1 = x + self.w1
                d.append(sdxf.Arc(center=(x, self.height-self.r1), radius=self.r1,
                                  startAngle=90-self.angle.deg, endAngle=90, **common))
                x = x1

            # Segment B2 (inclined)
            if self.b[2] > 0:
                x1 = x + self.w2
                d.append(sdxf.Line(points=[(x, self.h2 + self.h3), (x1, self.h3)], **common))
                x = x1

            # Segment B3 (arc)
            if self.b[3] > 0:
                x1 = x + self.w3
                d.append(sdxf.Arc(center=(x1, self.r3), radius=self.r3,
                                  startAngle=270-self.angle.deg, endAngle=270, **common))
                x = x1

            # Segment B4 (horizontal)
            if self.b[4] > 0:
                x1 = x + self.b[4]
                d.append(sdxf.Line(points=[(x, 0), (x1, 0)], **common))
                x = x1

            # Symmetrically against B4 segment
            # Segment B3 (arc)
            if self.b[3] > 0:
                x1 = x + self.w3
                d.append(sdxf.Arc(center=(x, self.r3), radius=self.r3,
                                  startAngle=270, endAngle=270+self.angle.deg, **common))
                x = x1

            # Segment B2 (inclined)
            if self.b[2] > 0:
                x1 = x + self.w2
                d.append(sdxf.Line(points=[(x, self.h3), (x1, self.h2 + self.h3)], **common))
                x = x1

            # Segment B1 (arc)
            if self.b[1] > 0:
                x1 = x + self.w1
                d.append(sdxf.Arc(center=(x1, self.height-self.r1), radius=self.r1,
                                  startAngle=90, endAngle=90+self.angle.deg, **common))
                x = x1

            # Segment B5 (horizontal)
            if j < self.waves-1 and self.b[5] > 0:
                x1 = x + self.b[5]
                d.append(sdxf.Line(points=[(x, self.height), (x1, self.height)], **common))
                x = x1

        # Right edge segment B0
        if self.b[0] > 0:
            x1 = x + self.b[0]
            d.append(sdxf.Line(points=[(x, self.height), (x1, self.height)], **common))

        return d
Exemple #10
0
 def line(self, x1, y1, x2, y2, pen=1, **kwargs):
     # pen maps to a specific layer
     l = sdxf.Line(points=[(x1, y1), (x2, y2)], layer=pen, **kwargs)
     self.dxf.append(l)
     return l
def dxf_line(f,x1,y1,x2,y2):
        f.append(sdxf.Line(points=[(x1,y1),(x2,y2)]))
Exemple #12
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')