Exemplo n.º 1
0
def Line2Ras():
    ss = acad.get_selection('请选择一条直线')
    if ss.count == 1:
        entity = ss.Item(0)
        p1 = APoint(entity.StartPoint)
        p2 = APoint(entity.EndPoint)
        lst = [p1, p2]
        ptl = Polyline(lst)
        DrawGrid(ptl)
        n = acad.doc.Utility.GetInteger("请选择画线算法\n1.数值微分法 2.中点Bresenham算法")
        if n == 1:
            vlist = ptl.DDA()
        elif n == 2:
            vlist = ptl.Bresenham()
        for v in vlist:
            acad.model.AddCircle(v, 0.5)
    else:
        acad.prompt('选择的对象不是一个,请重新选择')
Exemplo n.º 2
0
 def transform(self, *polist: APoint):
     polist2 = []
     for po in polist:
         x = self[0][0] * po.x + self[0][1] * po.y + self[0][2]
         y = self[1][0] * po.x + self[1][1] * po.y + self[1][2]
         polist2.append(APoint(x, y))
     if len(polist2) == 1:
         return polist2[0]
     return tuple(polist2)
Exemplo n.º 3
0
def iter_drawings_names(acad, doc):
    num_layouts = doc.Layouts.Count - 2
    for layout_number, layout in enumerate(acad.iter_layouts(doc)):
        utils.dynamic_print('  Layout %02d/%02d' %
                            (layout_number, num_layouts))
        # first we need to find our main stamp with name 'f4'
        block = acad.find_one('blockreference', layout.Block,
                              lambda x: 'f4' in x.EffectiveName)
        if not block:
            continue
        block_pos = APoint(block.InsertionPoint)
        # approximate position of drawing name
        name_pos = block_pos + APoint(-90, 12)
        for mt in acad.iter_objects("mtext", layout.Block):
            if name_pos.distance_to(mt.InsertionPoint) < 5.0:
                text = mt.TextString
                yield text.replace(" \\P", " ").replace("\\P", " ")
                break
    print
Exemplo n.º 4
0
 def __init__(self, p1, p2=None):
     if p2:
         self.begin = p1
         self.end = p2
     else:
         self.begin = APoint(0, 0)
         self.end = p1
     self.A = self[1]
     self.B = -self[0]
     self.C = self.end[0] * self.begin[1] - self.begin[0] * self.end[1]
 def wrapped(*args, **kwargs):
     temp = func(*args, **kwargs)
     changed_elems = list()
     for elem in temp:  # if isinstance(cell_draw[0], list) else [cell_draw]:
         if elem[0] == "line":
             changed_elems.append(["line", elem[2], -elem[1], elem[4], -elem[3]])
         elif elem[0] == "arc":
             pR = list(elem[1])
             changed_elems.append(["arc", APoint(pR[1], -pR[0]), elem[2], elem[3], elem[4]])
     return changed_elems
Exemplo n.º 6
0
def draw_points_in_layer():
    acad = Autocad()
    acad.prompt("Autocad from Python - Draw Points in Layer\n")
    print acad.doc.Name

    for i in range(8):
        p1 = APoint(i * 1000, 1000)
        p = acad.model.AddPoint(p1)
        p.Layer = "Node"
        p.Color = i
Exemplo n.º 7
0
def get_coordinates(distance, angle):
    if distance > 0 and angle != None:
        return APoint((math.cos(math.radians(angle)) * distance),
                      (math.sin(math.radians(angle)) * distance))
    elif distance <= 0:
        return tk.messagebox.showerror('Error',
                                       'Distance must be greater than 0')

    elif angle == None:
        return tk.messagebox.showerror('Error', 'Invalid angle')
Exemplo n.º 8
0
def draw_block(model=None):
    model_info=model.draw_info
    line_info=model_info[0]
    wenzi_info=model_info[1]
    arc_info=model_info[2]
    block_start_point = APoint(0, 0)
    blockObj = acad.ActiveDocument.Blocks.Add(block_start_point, wenzi_info[0])
    draw_line(blockObj,line_info)
    draw_wenzi(blockObj,wenzi_info)
    draw_arc(blockObj,arc_info)
    block_info.append(wenzi_info[0])
Exemplo n.º 9
0
    def test_find_objects(self):
        p1 = APoint(0, 0)
        model = self.acad.model
        for i in range(5):
            model.AddText(u'test %s' % i, p1, 2.5)

        def text_contains_3(text_obj):
            return '3' in text_obj.TextString

        text = self.acad.find_one('Text', predicate=text_contains_3)
        self.assertEqual(text.TextString, 'test 3')
Exemplo n.º 10
0
def cap_f(acad, x, y, D, d3, d=0, oc=0):
    D0 = D + 2.5 * d3
    D2 = D0 + 2.5 * d3
    c = APoint(x, y)
    d_c(acad, c, D2 / 2, 1)
    d_c(acad, c, (D2 - 4) / 2)
    d_c(acad, c, D / 2)
    d_c(acad, c, D0 / 2)
    if oc:
        d_c(acad, c, d / 2)
        d_c(acad, c, d / 2 + 1)
Exemplo n.º 11
0
def FillCircle(cen, r):
    bottom = cen.y - r
    top = cen.y + r
    vertex = []
    for y in range(ceil(bottom), ceil(top)):
        ry = sqrt(r * r - (y - cen.y)**2)
        x1 = cen.x - ry
        x2 = cen.x + ry
        for x in range(ceil(x1), ceil(x2)):
            vertex.append(APoint(x, y))
    return vertex
Exemplo n.º 12
0
def next_p(p, i, step):
    x = p.x
    y = p.y
    if i % 4 == 0:
        x += step
    elif i % 4 == 1:
        y += step
    elif i % 4 == 2:
        x -= step
    elif i % 4 == 3:
        y -= step
    return APoint(x, y)
Exemplo n.º 13
0
def next_p(_p, _i, step):
    x = _p.x
    y = _p.y
    if _i % 4 == 0:
        x += step
    elif _i % 4 == 1:
        y += step
    elif _i % 4 == 2:
        x -= step
    elif _i % 4 == 3:
        y -= step
    return APoint(x, y)
Exemplo n.º 14
0
 def intersect(self, other):
     """
     other:Vector
     返回交点坐标
     """
     if self.direction == other.direction or self.direction == -other.direction:
         raise ValueError("无交点")
     else:
         D = self.A * other.B - self.B * other.A
         D1 = -(self.C * other.B - self.B * other.C)
         D2 = -(self.A * other.C - self.C * other.A)
         return APoint(D1 / D, D2 / D)
 def _quadrant4(self, global_Cord):
     r = self.radius
     p1 = Coordinate(0, self.scale / 2)
     p1_1 = Coordinate(self.scale / 2 - r, self.scale / 2)
     p2 = Coordinate(self.scale / 2, 0)
     p2_2 = Coordinate(self.scale / 2, self.scale / 2 - r)
     x = global_Cord.x * self.scale
     y = global_Cord.y * self.scale
     if self.mode == "line": return ["line", p1.x + x, p1.y + y, p2.x + x, p2.y + y]
     pR = Coordinate(p1_1.x, p2_2.y)
     return [["line", p1.x + x, p1.y + y, p1_1.x + x, p1_1.y + y], \
             ["line", p2.x + x, p2.y + y, p2_2.x + x, p2_2.y + y], \
             ["arc", APoint(pR.x + x, pR.y + y), r, math.pi * 3/2, math.pi * 2]]
Exemplo n.º 16
0
def test1():
    #Test1: mesh testing

    acad = Autocad()
    acad.prompt("Hello, Autocad from Python\n")
    print acad.doc.Name

    p1 = APoint(0, 0)
    p2 = APoint(50, 25)
    for i in range(5):
        text = acad.model.AddText('Hi %s!' % i, p1, 2.5)
        acad.model.AddLine(p1, p2)
        acad.model.AddCircle(p1, 10)
        p1.y += 10

    dp = APoint(10, 0)
    for text in acad.iter_objects('Text'):
        print('text: %s at: %s' % (text.TextString, text.InsertionPoint))
        text.InsertionPoint = APoint(text.InsertionPoint) + dp

    for obj in acad.iter_objects(['Circle', 'Line']):
        print(obj.ObjectName)
Exemplo n.º 17
0
def draw_to_cabinet(source=None):
    source = source
    for item in source:
        c = cabinet(item)
        model_info = c.draw_info
        line_info = model_info[0]
        wenzi_info = model_info[1]
        arc_info = model_info[2]
        block_start_point = APoint(0, 0)
        blockObj = acad.ActiveDocument.Blocks.Add(block_start_point,
                                                  wenzi_info[0])
        draw_line(blockObj, line_info)
        draw_wenzi(blockObj, wenzi_info)
        block_info4.append(wenzi_info[0])
Exemplo n.º 18
0
def draw_to_BN(place_to=None):
    to_BN = place_to
    for item in to_BN:
        c = BN(item)
        model_info = c.draw_info
        line_info = model_info[0]
        wenzi_info = model_info[1]
        arc_info = model_info[2]
        block_start_point = APoint(0, 0)
        blockObj = acad.ActiveDocument.Blocks.Add(block_start_point,
                                                  wenzi_info[0])
        draw_line(blockObj, line_info)
        draw_wenzi(blockObj, wenzi_info)
        block_info3.append(wenzi_info[0])
Exemplo n.º 19
0
 def draw_cabinet_model(self, info):
     draw_info = info
     for i in draw_info:
         c = cabinet(name=i)
         model_info = c.draw_info
         line_info = model_info[0]
         wenzi_info = model_info[1]
         arc_info = model_info[2]
         block_start_point = APoint(0, 0)
         blockObj = acad.ActiveDocument.Blocks.Add(block_start_point,
                                                   wenzi_info[0])
         self.draw_line(blockObj, line_info)
         self.draw_wenzi(blockObj, wenzi_info)
         self.blocklistinfo.append(wenzi_info[0])
Exemplo n.º 20
0
    def draw(self, pyacad):
        center = APoint(self.x0, self.y0)  # 圆心
        radius = self.radius_1  # 半径
        nei_lunkuo_1 = pyacad.model.AddArc(center, radius, math.radians(0),
                                           math.radians(90))
        nei_lunkuo_1.update
        #v = VARIANT (pythoncom.VT_BYREF | pythoncom.VT_ARRAY | pythoncom.VT_R8,nei_lunkuo_1)
        #nei_lunkuo_2 = v.offset(-0.50)
        nei_lunkuo_2 = nei_lunkuo_1.offset(-0.50)

        nei_lunkuo_2.update

        print(nei_lunkuo_2.radius)
        nei_lunkuo_1.update
 def _quadrant1(self, global_Cord):
     r = self.radius
     p1 = Coordinate(self.scale, self.scale / 2)  # TODO необязательно линия должна идти от середины
     p1_1 = Coordinate(self.scale / 2 + r, self.scale / 2)
     p2 = Coordinate(self.scale / 2, 0)
     p2_2 = Coordinate(self.scale / 2, self.scale / 2 - r)
     x = global_Cord.x * self.scale
     y = global_Cord.y * self.scale
     if self.mode == "line": return ["line", p1.x + x, p1.y + y, p2.x + x,
                                     p2.y + y]  # TODO фигово. Сделать нормально
     pR = Coordinate(p1_1.x, p2_2.y)
     return [["line", p1.x + x, p1.y + y, p1_1.x + x, p1_1.y + y], \
             ["line", p2.x + x, p2.y + y, p2_2.x + x, p2_2.y + y], \
             ["arc", APoint(pR.x + x, pR.y + y), r, 0, math.pi / 2]]
Exemplo n.º 22
0
def BresenhamCirc(cen, r):
    sup = r / sqrt(2)
    x = 0
    y = sqrt(r * r - x * x)
    d = 1 - r
    vertex = []
    while x < sup:
        seed = APoint(round(x), round(y))  #开始不round成整点,因为如果圆心坐标不是整数后面不好办
        seed2 = APoint(seed.y, seed.x)
        seed3 = APoint(seed.x, -seed.y)
        seed4 = APoint(seed.y, -seed.x)
        vertex += [seed, seed2, seed3, seed4, -seed, -seed2, -seed3, -seed4]
        if d <= 0:
            d += 2 * x + 3
        else:
            d += 2 * (x - y) + 5
            y -= 1
        x += 1
    vertex = move(cen.x, cen.y).transform(*vertex)
    vertexround = []
    for item in vertex:
        vertexround.append(APoint(round(item.x), round(item.y)))
    return vertexround
Exemplo n.º 23
0
 def draw_BN_model(self, info):
     BN_info = info
     for item in BN_info:
         c = BN(item)
         model_info = c.draw_info
         line_info = model_info[0]
         wenzi_info = model_info[1]
         arc_info = model_info[2]
         block_start_point = APoint(0, 0)
         blockObj = acad.ActiveDocument.Blocks.Add(block_start_point,
                                                   wenzi_info[0])
         self.draw_line(blockObj, line_info)
         self.draw_wenzi(blockObj, wenzi_info)
         self.blocklistinfo.append(wenzi_info[0])
Exemplo n.º 24
0
def drawcad(mainpowersource, auxlirypowersoruce, filelist):
    global load_list, switch_file
    mainpowersource = mainpowersource.split(",")
    auxlirypowersoruce = auxlirypowersoruce.split(",")
    for f in filelist:
        filepath = f[0]
        if "负荷" in filepath:
            load_list = filepath
        elif "开关" in filepath:
            switch_file = filepath
        else:
            print("出错了")
    load_list = read_excel_file(load_list)
    switch_file = read_excel_file(switch_file)
    for row1 in load_list:
        current = round(row1[1] / row1[2], 2)
        for row2 in switch_file:
            if current < row2[1]:
                row1.append(row2[0])
                break

    p1 = APoint(0, 0)
    p2 = APoint(0, 2200)
    p3 = APoint(800, 2200)
    p4 = APoint(800, 0)
    acad.model.AddLine(p1, p2)
    acad.model.AddLine(p2, p3)
    acad.model.AddLine(p3, p4)
    acad.model.AddLine(p4, p1)
    start_X = [0, 400]
    start_Y = 1600
    for i in range(len(load_list)):
        a = i % 2
        draw_switch(start_X[a], start_Y, load_list[i][0], load_list[i][3])
        if a == 1:
            start_Y = start_Y - 200
    print("完成绘图")
Exemplo n.º 25
0
 def __new__(cls, coor, tagMoveDup=False):
     """用得到的多义线坐标表生成该点表"""
     if isinstance(coor, (list, tuple, array.array)):
         mylist = []
         if isinstance(coor[0], (float, int)):  #如果是直接的坐标表,即x0,y0,x1,y1
             for i in range(0, len(coor), 2):
                 mylist.append(APoint(coor[i], coor[i + 1]))
             if tagMoveDup:  #去除重复元素
                 mylist = MoveDupAPoint(mylist)
             return super(PointSet, cls).__new__(cls, mylist)
         elif len(coor[0]) == 3:  #已经是APoint数组了
             mylist = coor
             if tagMoveDup:  #去除重复元素
                 mylist = MoveDupAPoint(mylist)
             return super(PointSet, cls).__new__(cls, mylist)
Exemplo n.º 26
0
def job1():
    old_pdmode=acad.doc.GetVariable('pdmode')
    acad.doc.SetVariable('pdmode',2)
    n=acad.doc.Utility.GetInteger('请输入点的个数(至少3个):')
    if n<3:
        acad.prompt('输入点数量有误,程序终止')
        return
    ptlist=[]
    for i in range(n):
        prompt1='请输入第%d/%d个点'% (i+1,n)
        prompt1=str(prompt1)
        acad.prompt(prompt1)
        while True:#遇到呼叫错误,不断重复尝试。
            try:
                pt=acad.doc.Utility.GetPoint()
            except Exception:
                time.sleep(0.2)
                acad.doc.Regen(ACAD.acActiveViewport)
                acad.prompt(prompt1)
                print('呼叫错误,重试')
            else:
                break
        # try:
        #     pt=acad.doc.Utility.GetPoint()
        # except Exception:
        #     acad.prompt('输入有误,请重新输入')
        time.sleep(0.1)
        pt=APoint(pt)
        acad.model.AddPoint(pt)
        ptlist.append(pt)
    while True:
        closed=acad.doc.Utility.GetString(0,'\n曲线是否闭合Y(闭合)/N(不闭合)?默认Y')
        if closed=='' or closed.lower()=='y':
            tagclosed=True
            break
        elif closed.lower()=='n':
            tagclosed=False
            break
        else:
            acad.prompt('输入有误,请重新输入!')
    thetalist=CalcuTheta(ptlist,tagclosed)
    pqlist=CalcuParam(ptlist,thetalist,tagclosed)
    del thetalist
    del ptlist
    coor=AddCoor(pqlist)
    coor=[round(x,5) for x in coor]
    en=acad.model.AddLightWeightPolyline(aDouble(coor))
    en.Color=random.randint(1,7)
Exemplo n.º 27
0
    def Transform(self, matrix):
        """transform a list of coor via transformation matrix

            00 01 02    i
            10 11 12  * i+1
            0   0   1     1
            只算前两行
        """
        newcoor = []
        for i in range(0, self.L):
            x = matrix[0][0] * self[i].x + matrix[0][1] * self[i].y + matrix[
                0][2]
            y = matrix[1][0] * self[i].x + matrix[1][1] * self[i].y + matrix[
                1][2]
            newcoor.append(APoint(x, y))
        return newcoor
Exemplo n.º 28
0
def MBR():
    selection = acad.get_selection("选择一条多义线或不少于三个点")
    coor = []
    if selection.count == 1:
        entity = selection.Item(0)
        ptl = PointSet(entity.Coordinates)
    elif selection.count >= 3:
        for item in selection:
            if item.ObjectName == "AcDbPoint":
                coor.append(APoint(item.Coordinates))
        ptl = PointSet(coor)
    else:
        return
    polyline = ptl.MBR()
    en = acad.model.AddLightWeightPolyline(polyline)
    en.Closed = True
    en.Color = ACAD.acRed
Exemplo n.º 29
0
 def dist_intersect(self, r1, r2, tagRight=True):
     """
     返回右方/左方交汇点坐标
     """
     t = r1 + r2 - self.norm
     if t < 0:
         return None
     elif t == 0:
         return self.divide(1)
     else:
         h = (self.norm**2 + r1**2 - r2**2) / (2 * self.norm)
         L = sqrt(r1**2 - h**2)
         if tagRight == False:
             L = -L
         ang = self.angle() - pi / 2
         return self.begin + pyptlist.main.rotate(ang).transform(
             APoint(L, h))
Exemplo n.º 30
0
 def FillPolygon(self):
     minp, maxp = self.GetBoundingBox()
     ymin = ceil(minp.y)
     ymax = floor(maxp.y)
     fillpo = []
     for y in range(ymin, ymax + 1):
         xlist = self.GetIntersection(y)
         for i in range(0, len(xlist), 2):
             p1x = ceil(xlist[i])
             p2x = xlist[i + 1]
             if p2x != int(p2x):
                 p2x = floor(p2x)
             else:
                 p2x -= 1
             for j in range(p1x, p2x + 1):
                 fillpo.append(APoint(j, y))
     return fillpo