Ver código fonte

生成相应文件

duh 6 anos atrás
pai
commit
6e0a40e38d

+ 25 - 13
phxb/utils/GetAllModule.py

@@ -1,10 +1,10 @@
 # -*- coding: UTF-8 -*-
 from pyautocad import Autocad, APoint
-from utils import getarray
+from utils import conf
 import math
 
 #这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
-acad = Autocad(create_if_not_exists = True)
+acad = Autocad(create_if_not_exists = False)
 # acad.prompt("Hello, Autocad from Python\n")
 # print(acad.doc.Name)
 def printObjects():
@@ -15,18 +15,30 @@ def printTheTypeObject(type):
   #按类型查找出所有某种图元
   for text in acad.iter_objects(type):
     print(text.name)
-names=['ssdr_800','md_py','md_xs','md_rc']
-def moveBlockReference():
+def moveBlockReference(position):
+  print(conf.moduleLengths)
   for blockReference in acad.iter_objects("BlockReference"):
-    # print(blockReference.name)
-    if(blockReference.name == names[3]):
-      insertionPoint = blockReference.InsertionPoint
-      blockReference.rotate(APoint(insertionPoint[0],insertionPoint[1]),-0.5*math.pi)
-      print(insertionPoint)
-      # blockReference.move(APoint(insertionPoint[0],insertionPoint[1]),APoint(0,0))
+    print(blockReference.name)
+    for item in conf.names:
+      if(blockReference.name == item):
+        moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
+def moveBlockReferenceToWall(blockReference,wallIndex):
+  wallIndex = int(wallIndex)
+  blockReference.rotate(APoint(blockReference.InsertionPoint),0.5*(wallIndex+1)*math.pi)
+  blockIndex = conf.names.index(blockReference.name)
+  if(wallIndex == 0):
+    blockReference.move(APoint(blockReference.InsertionPoint),APoint(0+conf.moduleLengths[blockIndex]+conf.roomUsedLengths[0],0))
+    conf.roomUsedLengths[0] = conf.roomUsedLengths[0]+conf.moduleLengths[blockIndex];
+  elif (wallIndex == 1):
+    blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomLengths[0],conf.roomLengths[1]-conf.roomUsedLengths[1]))
+    conf.roomUsedLengths[1] = conf.roomUsedLengths[1]+conf.moduleLengths[blockIndex];
+  elif (wallIndex == 2):
+    blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomUsedLengths[2],conf.roomLengths[1]))
+    conf.roomUsedLengths[2] = conf.roomUsedLengths[2]+conf.moduleLengths[blockIndex];
+  else:
+    blockReference.move(APoint(blockReference.InsertionPoint),APoint(0,conf.roomUsedLengths[3]))
+    conf.roomUsedLengths[3] = conf.roomUsedLengths[3]+conf.moduleLengths[blockIndex];
 # printObjects()
 # printTheTypeObject("BlockReference")
 
-moveBlockReference()
-# a = getarray.jieChen(5)
-# print(a)
+# moveBlockReference('021')

BIN
phxb/utils/__pycache__/__init__.cpython-37.pyc


BIN
phxb/utils/__pycache__/getarray.cpython-37.pyc


+ 7 - 3
phxb/utils/conf.py

@@ -1,7 +1,11 @@
 # 模块名称
 names=['md_py','md_xs','md_rc']
 # 房间下右上左墙的边长
-roomLengths = (2000,2200,3000,1200)
-roomUsedLengths = (0,0,0,0)
+roomWallLengths = (2000,2200,3000,1200)
+roomUsedLengths = [1200,0,0,1000]
+roomLengths = (3000,2200)
 # 模块长度
-moduleLengths = (800,900,900)
+moduleLengths = (800,1000,800)
+doorLength=800
+# 门与左右上下的间距
+doorAlign=[100,200,200,0]

+ 16 - 4
phxb/utils/getarray.py

@@ -83,6 +83,17 @@ def getitemIndexArray(itemIndex,m,n):
         a[item]=indexNum
     print("a=",a)
     return a
+#获取单个组合的各边重复项及重复项顺序
+def getitemIndexArrayAndPosition(itemIndex,m,n):
+    a = getitemIndexArray(itemIndex,m,n)
+    for item in a:
+        if(a[item] > 1):
+            newItem = {}
+            newItem[0] = a[item]
+            newItem[1] = jiechenarray(a[item])
+            a[item] = newItem
+    print("getitemIndexArrayAndPosition=",a)
+    return a
 #获取单个组合的各边重复项--包含各项位置
 # 如{0: {0: 0, 1: {}}, 1: {0: 0, 1: {}}, 2: {0: 2, 1: {0: 0, 1: 4}}, 3: {0: 3, 1: {0: 1, 1: 2, 2: 3}}, 4: {0: 0, 1: {}}}
 def getitemIndexAndPositionArray(itemIndex, m, n):
@@ -117,9 +128,10 @@ def getitemIndexArrayNumber(itemIndex,m,n):
 # print(result)
 # getAllPosition(3, 3)
 # getAllArrayNumber(4,3)
-# getitemIndexArray("01243",5,5)
-# getitemIndexAndPositionArray("23332", 5, 5)
-# number = getitemIndexArrayNumber("51243",5)
+getitemIndexArray("11213",5,5)
+getitemIndexArrayAndPosition("11213",5,5)
+# getitemIndexAndPositionArray("113", 4, 3)
+# number = getitemIndexArrayNumber("11143",5,5)
 # print(number)
-# getAllArrayNumber(4,2)
+# getAllArrayNumber(11,2)
 # print(jiechenarray(3))

+ 125 - 0
phxb/utils/main.py

@@ -0,0 +1,125 @@
+from pyautocad import Autocad, APoint
+from ctypes import cdll
+from utils import getarray,GetAllModule
+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):
+        return False  # file doesn't exist
+    h = _sopen(filename, 0, _SH_DENYRW, 0)
+    if h == 3:
+        _close(h)
+        return False  # file is not opened by anyone else
+    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")
+# 关闭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.moveBlockReference(position)
+    time.sleep(5)
+    acad = Autocad(create_if_not_exists = False)
+    acad.prompt("Hello, Autocad from Python\n")
+    acad.doc.SaveAs(fileName)
+    acad.doc.Shutdown()
+    # closeAcad()
+
+# openOriginFile()
+# tempStorageModules()
+# print(is_open(_rootPath+_originFile))
+myprocess(4, 3)
+# openFile(r"F:\autocad_temp\newfile023.dwg")

+ 24 - 0
phxb/utils/testopen.py

@@ -0,0 +1,24 @@
+# coding=utf-8
+from ctypes import *
+from pyautocad import Autocad
+import win32api
+import os
+def openTxt(fileName):
+    win32api.ShellExecute(0, 'open', r'C:\Program Files (x86)\Notepad++\notepad++.exe', fileName,'',1)
+def openTxt2(handler,fileName):
+    print(handler)
+    handler=win32api.ShellExecute(handler, 'open', r'C:\Program Files\TortoiseGit\bin\notepad2.exe', fileName,'',1)
+    print(handler)
+def openbyApi():
+    win32api.ShellExecute(0, 'open', r'D:\tools\autocadinstall\AutoCAD 2016\acad.exe', r'F:\autocad_temp\newfile032.dwg','',1)
+def closeAcad():
+    os.system("taskkill /F /IM acad.exe")
+def shellDllOpen(file):
+    shelldll = WinDLL("C:/Windows/System32/shell32.dll")
+    shelldll.ShellExecuteW(None, 'open', file, '', '', 1)
+def autoOpen(file):
+    acad = Autocad(create_if_not_exists = False)
+# openbyApi()
+# shellDllOpen(r"e:/jstat.txt")
+# shellDllOpen(r"e:/jstat.txt")
+# autoOpen( r'F:\autocad_temp\newfile032.dwg')