| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 | # -*- coding: UTF-8 -*-from pyautocad import Autocad, APoint#这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败acad = Autocad(create_if_not_exists = True)acad.prompt("Hello, Autocad from Python\n")print(acad.doc.Name)def drawPoints(points):    for point in points:        acad.model.AddCircle(APoint(point[0],point[1]), 50)def drawLines(includePoints):    if(len(includePoints)>1):        for item in range(len(includePoints)):            if(item>0):                acad.model.AddLine(APoint(includePoints[item-1][0],includePoints[item-1][1]),APoint(includePoints[item][0],includePoints[item][1]))# 获取点到长方形的最短距离def getDoorBeginAndModuleUsePointDistince(x0,y0,width,height,x,y):    points = [(x,y),(x0-width/2,y0-height/2),(x0-width/2,y0+height/2),(x0+width/2,y0-height/2),(x0+width/2,y0+height/2),(x0,y0)]    drawPoints(points)    includePoints = [(x,y)]    if x<x0-width/2:        if y>y0+height/2:            includePoints.append((x0-width/2,y0+height/2))        elif y>y0-height/2:            includePoints.append((x0-width/2,y))        else:            includePoints.append((x0-width/2,y0-height/2))    elif x<x0+width/2:        if y>y0+height/2:            includePoints.append((x,y0+height/2))        elif y>y0-height/2:            pass        else:            includePoints.append((x,y0-height/2))    else:        if y>y0+height/2:            includePoints.append((x0+width/2,y0+height/2))        elif y>y0-height/2:            includePoints.append((x0+width/2,y))        else:            includePoints.append((x0+width/2,y0-height/2))    drawLines(includePoints)# 获取点到长方形指定点的最短距离,默认点在长方形下方def getMovePath(x0,y0,width,height,x,y,x1,y1):    points = [(x,y),(x0-width/2,y0-height/2),(x0-width/2,y0+height/2),(x0+width/2,y0-height/2),(x0+width/2,y0+height/2),(x0,y0),(x1,y1)]    drawPoints(points)    includePoints = [(x,y)]    # 指定点在第0边;按下右上左方向    if y1 == y0-height/2:        includePoints.append((x1,y1))    # 指定点在第1边;按下右上左方向    elif x1 == x0+width/2:        if x>x0+width/2:            includePoints.append((x1,y1))        else:            includePoints.append((x0+width/2,y0-height/2))            includePoints.append((x1,y1))    # 指定点在第2边,暂只考虑从左边开始接近    elif y1 == y0+height/2:        if x<x0-width/2:            includePoints.append((x0-width/2,y0+height/2))            includePoints.append((x1,y1))        else:            includePoints.append((x0-width/2,y0-height/2))            includePoints.append((x0-width/2,y0+height/2))            includePoints.append((x1,y1))    # 指定点在第3边    else:        if x<x0-width/2:            includePoints.append((x1,y1))        else:            includePoints.append((x0-width/2,y0-height/2))            includePoints.append((x1,y1))    drawLines(includePoints)# getDoorBeginAndModuleUsePointDistince(3300,1500,900,600,10,3000)# getDoorBeginAndModuleUsePointDistince(3300,2800,900,600,1000,3000)# getDoorBeginAndModuleUsePointDistince(3300,2800,900,600,3100,3800)# getDoorBeginAndModuleUsePointDistince(3300,2800,900,600,4000,900)# getMovePath(3300,2800,900,600,0,0,3500,2500)# getMovePath(3300,2800,900,600,0,0,2850,2700)# getMovePath(3300,2800,900,600,3000,0,2850,2700)# getMovePath(3300,2800,900,600,3300,0,3500,3100)def testAppend():    score = []    for i in range(100):        s = []        s.append(i)        score.append(s)        print(score)testAppend()
 |