123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- from pyautocad import Autocad, APoint
- from ctypes import cdll
- from utils import getarray,GetAllModule,getHandler
- import os, time, shutil
- from 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
- # 关闭autoCad
- def 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():
- pass
- def 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):
- pass
- def 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:
- # for index in range(number):
- # newFileName = _rootPath + "newfile" + str(positons[positon]) + str(index + 1) + ".dwg"
- # copyfile(_rootPath + _originFile, newFileName)
- # break
- def 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()
- # 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")
|