def job3():
    '''以该多边形的外包矩形的左下角为原点,实现沿着x方向的错切变换
    '''
    try:
        acad.doc.SelectionSets.Item('SS1').Delete()
    except Exception:
        print('Delete selection failed')

    selection = acad.doc.SelectionSets.Add('SS1')
    acad.prompt('选择一条多义线')
    selection.SelectOnScreen(aShort([0]), ['lwpolyline'])
    if selection.Count == 1:
        entity = selection.Item(0)
    else:
        print("选择的多义线多于一条")
        return
    coor = entity.Coordinates
    # minPnt=np.float_([0,0,0])
    # maxPnt=np.float_([0,0])
    # pBox=entity.GetBoundingBox
    # minx=pBox()[0][0]
    # miny=pBox()[0][1]
    # maxx=pBox()[1][0]
    # maxy=pBox()[1][1]
    retval = GetBoundingBox(entity)
    mat = multi(move(-retval[0], -retval[1]), shear(1),
                move(retval[0], retval[1]))
    newcoor = transform(mat, coor)
    entity.Coordinates = aDouble(newcoor)
    entity.Color = ACAD.acYellow
    acad.doc.Regen(1)
def job2():
    '''选取最长的对角线,以对角线的某一点为原点,沿该对角线伸长1.5倍
    绘制的线用蓝色表示
    '''
    try:
        acad.doc.SelectionSets.Item('SS1').Delete()
    except Exception:
        print('Delete selection failed')

    selection = acad.doc.SelectionSets.Add('SS1')
    acad.prompt('选择一条多义线')
    selection.SelectOnScreen(aShort([0]), ['lwpolyline'])
    if selection.Count == 1:
        entity = selection.Item(0)
    else:
        print("选择的多义线多于一条")
        return
    coor = entity.Coordinates  #tuple77
    vectorcoor = longestDiagonalLine(coor)
    basePnt = vectorcoor[0:2]
    endPnt = vectorcoor[2:4]
    angle = acad.doc.Utility.AngleFromXAxis(APoint(*basePnt), APoint(*endPnt))
    negbasePnt = [-x for x in basePnt]
    mat1 = multi(move(*negbasePnt), rotate(-angle))
    mat2 = scale(1.5)
    mat3 = multi(rotate(angle), move(*basePnt))
    mat = multi(mat1, mat2, mat3)
    newcoor = transform(mat, coor)
    entity.Coordinates = aDouble(newcoor)
    entity.Color = ACAD.acBlue
    acad.doc.Regen(1)
def retangle(origin,L,H):
    x0=origin[0]
    y0=origin[1]
    pnts = [APoint(x0,y0), APoint(x0+L,y0), APoint(x0+L,y0+H),APoint(x0,y0+H),APoint(x0,y0)]
    pnts = [j for i in pnts for j in i]  # 将各点坐标顺序变换为行数据
    pnts = aDouble (pnts)  # 转化为双精度浮点数
    plineObj = pyacad.model.AddPolyLine (pnts)
    plineObj.Closed = True  # 闭合多段线
Beispiel #4
0
def demo14():  #函数绘图
    x = 1
    ptlist = [0, 0, 1, 0]
    while x < 2:
        x += 0.05
        y = math.sin(math.pi / 2 * (x - 1))
        ptlist += [x, y]
    ptlist += [2, 1, 3, 1]
    en = acad.model.AddLightWeightPolyline(aDouble(ptlist))
    basePnt = APoint(0)
    endPnt = APoint(0)
    for i in range(100):
        copyen = en.Copy()
        endPnt.x += 0.5
        copyen.Move(basePnt, endPnt)
Beispiel #5
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)
Beispiel #6
0
    def test_types(self):
        model = self.acad.model
        p1 = APoint(0, 0, 0)
        p2 = APoint(10, 10, 0)
        p3 = tuple(p+10 for p in p2)

        model.AddLine(p1, p2)
        model.AddLine(p2, APoint(p3))
        lines = list(self.acad.iter_objects())
        self.assertEqual(len(lines), 2)
        self.assertEqual(lines[0].StartPoint, p1)
        self.assertEqual(lines[0].EndPoint, p2)
        self.assertEqual(lines[1].StartPoint, p2)
        self.assertEqual(lines[1].EndPoint, p3)
        with self.assertRaises(COMError):
            model.AddLine(aDouble(0, 0), APoint(0, 0, 0))
def job1():
    '''绕中心点逆时针旋转45度,绘制的线用红色表示
    '''
    try:
        acad.doc.SelectionSets.Item('SS1').Delete()
    except Exception:
        print('Delete selection failed')
    selection = acad.doc.SelectionSets.Add('SS1')
    acad.prompt('选择一条多义线')
    selection.SelectOnScreen(aShort([0]), ['lwpolyline'])
    if selection.Count == 1:
        entity = selection.Item(0)
    else:
        print("选择的多义线多于一条")
        return
    coor = entity.Coordinates  #tuple
    newcoor = transform(rotate(radians(45), *center(coor)), coor)
    entity.Coordinates = aDouble(newcoor)
    entity.Color = ACAD.acRed
    acad.doc.Regen(1)
Beispiel #8
0
def demo10():  #创建pl
    lis = aDouble(0, 0, 100, 200)
    acad.model.AddLightWeightPolyline(lis)
Beispiel #9
0
    ' Define the 2D polyline points
    points(0) = 1: points(1) = 1: points(2) = 0
    points(3) = 1: points(4) = 2: points(5) = 0
    points(6) = 2: points(7) = 2: points(8) = 0
    points(9) = 3: points(10) = 2: points(11) = 0
    points(12) = 4: points(13) = 4: points(14) = 0

    ' Create a lightweight Polyline object in model space
    Set plineObj = ThisDrawing.ModelSpace.AddPolyline(points)
    ZoomAll

End Sub
'''
# p1(0,0,0) p2(10,10,0) p3(20,30,0) p4(30,80,0)
acad.model.AddPolyLine(aDouble([0, 0, 0, 10, 10, 0, 20, 30, 0, 30, 80, 0]))
''' 三维多段线 AcDb3dPolyline '''
# Add3DPoly Method (ActiveX)
# RetVal = object.Add3Dpoly(PointsArray)
'''
Sub Example_Add3DPoly()

    Dim polyObj As Acad3DPolyline
    Dim points(0 To 8) As Double

    ' Create the array of points
    points(0) = 0: points(1) = 0: points(2) = 0
    points(3) = 10: points(4) = 10: points(5) = 10
    points(6) = 30: points(7) = 20: points(8) = 30

    ' Create a 3DPolyline in model space
Beispiel #10
0
def toLightWeightPolyline(apointlist):
    pt = []
    for item in apointlist:
        pt += item[0:2]
    return aDouble(pt)
Beispiel #11
0
def toPolyline(apointlist):
    pt = []
    for item in apointlist:
        pt += item[0:3]
    return aDouble(pt)