| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 | from pyautocad import Autocad, APointfrom ctypes import cdllfrom utils import getarray,GetAllModule,getHandlerimport os, time, shutilfrom pyautocad.cache import Cached_sopen = cdll.msvcrt._sopen_close = cdll.msvcrt._close_SH_DENYRW = 0x10_rootPath = "F:\\autocad_temp\\"_originFile = "origin.dwg"templateIndex = {'md_xs','md_py','md_rc'}doorName = 'ssdr_800'# 这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败# print(acad.doc.Name)# 判断文件是否打开def is_open(filename):    if not os.access(filename, os.F_OK):        print("file doesn't exist")        return False  # file doesn't exist    h = _sopen(filename, 0, _SH_DENYRW, 0)    if h == 3:        _close(h)        print("file is not opened by anyone else")        return False  # file is not opened by anyone else    print("file is already open")    return True  # file is already open# 1、打开dwg文件def openOriginFile():    # if(is_open(_rootPath+_originFile)):    #     return    print("begin to open origin file")    os.popen("acad " + _rootPath + _originFile)    time.sleep(10)    print("origin file opened")def openFile(fileName):    # if(is_open(_rootPath+_originFile)):    #     return    print("begin to open file")    os.popen("acad " + fileName)    time.sleep(20)    print("file opened")def startAcadAndGetHandler():    print("begin to start acad")    pass# 关闭autoCaddef closeAcad():    os.system("taskkill /F /IM acad.exe")# 2、缓存房间、门、模块def tempStorageModules():    acad = Autocad(create_if_not_exists=False)    acad.prompt("Hello, Autocad from Python\n")    print(acad.doc.Name)    cached_acad = Cached(acad)    return cached_acad# 3、获取文件中的房间、门、模块参数def getModuleData():    pass# 4、获取所有模块的摆法def getPutArray():    pass# 5、对每一种摆法,新建dwg文件,def copyToNewFile():    os.system("")    pass# 6、摆放房间、门、模块后保存def saveNewFile():    passdef copyfile(srcfile, dstfile):    if not os.path.isfile(srcfile):        print("%s not exist!" % (srcfile))    else:        fpath, fname = os.path.split(dstfile)  # 分离文件名和路径        if not os.path.exists(fpath):            os.makedirs(fpath)  # 创建路径        shutil.copyfile(srcfile, dstfile)  # 复制文件        print("copy %s -> %s" % (srcfile, dstfile))def createNewFileAndMove(newFil):    passdef myprocess(m, n):    positons = getarray.getAllPosition(m, n)    for positon in positons:        indexAndPositionArray = getarray.getitemIndexAndPositionArray(positons[positon], m, n)        number = getarray.getitemIndexArrayNumber(positons[positon], m, n)        if (number == 1):            newFileName = _rootPath + "newfile" + str(positons[positon]) + ".dwg"            if(not os.path.exists(newFileName)):                copyfile(_rootPath + _originFile, newFileName)                moveSingleTemplate(newFileName,positons[positon])                # break        else:            moduleIndexs = getarray.getModuleIndex(positons[positon],m,n)            for moduleIndex in moduleIndexs:                newFileName = _rootPath + "newfile" + str(positons[positon]) + str(moduleIndex) + ".dwg"                if(not os.path.exists(newFileName)):                    copyfile(_rootPath + _originFile, newFileName)                    moveMultipleTemplate(newFileName,positons[positon],moduleIndex)            # breakdef moveSingleTemplate(fileName,position):    # openFile(fileName)    GetAllModule.resetConfUsed()    GetAllModule.moveBlockReference(position)    time.sleep(3)    acad = Autocad(create_if_not_exists = False)    acad.prompt("Hello, Autocad from Python\n")    acad.doc.SaveAs(fileName)    time.sleep(1)    getHandler.backToOrigin()def moveMultipleTemplate(fileName,position,moduleIndex):    GetAllModule.resetConfUsed()    GetAllModule.moveBlockReferenceWithNewIndex(position,moduleIndex)    time.sleep(1)    acad = Autocad(create_if_not_exists = False)    acad.prompt("Hello, Autocad from Python\n")    acad.doc.SaveAs(fileName)    time.sleep(1)    getHandler.backToOrigin()# openOriginFile()# tempStorageModules()# print(is_open(_rootPath+_originFile))myprocess(4, 3)# openFile(r"F:\autocad_temp\newfile023.dwg")# is_open(r"F:\autocad_temp\origin11.dwg")
 |