Jelajahi Sumber

修改后保存

duh 6 tahun lalu
induk
melakukan
67caedfaad

+ 3 - 1
phxb/utils/GetAllModule.py

@@ -38,7 +38,9 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
   else:
     blockReference.move(APoint(blockReference.InsertionPoint),APoint(0,conf.roomUsedLengths[3]))
     conf.roomUsedLengths[3] = conf.roomUsedLengths[3]+conf.moduleLengths[blockIndex];
+def resetConfUsed():
+  conf.roomUsedLengths=[1200,0,0,1000]
 # printObjects()
 # printTheTypeObject("BlockReference")
 
-# moveBlockReference('021')
+moveBlockReference('012')

+ 40 - 0
phxb/utils/getHandler.py

@@ -0,0 +1,40 @@
+import win32gui,win32api,win32con
+import time
+
+# 获取user32.dll的API
+from ctypes import windll
+
+def test():
+  time.sleep(5)
+  user32 = windll.user32
+  # 获取当前窗口句柄
+  hwnd = user32.GetForegroundWindow()
+  # 获取句柄对应的应用程序
+  app = win32gui.GetWindowText(hwnd)
+  print(hwnd)
+  print(app)
+def get_child_windows(parent):
+    '''
+    获得parent的所有子窗口句柄
+     返回子窗口句柄列表
+     '''
+    if not parent:
+        return
+    hwndChildList = []
+    win32gui.EnumChildWindows(parent, lambda hwnd, param: param.append(hwnd),  hwndChildList)
+    print("hwndChildList=",hwndChildList)
+    return hwndChildList
+def saveChange():
+    # ctrl+s
+    win32api.keybd_event(0x11,0,0,0)
+    win32api.keybd_event(83,0,0,0)
+    win32api.keybd_event(83,0,win32con.KEYEVENTF_KEYUP,0)
+    win32api.keybd_event(0x11,0,win32con.KEYEVENTF_KEYUP,0)
+def backToOrigin():
+    # ctrl+z
+    win32api.keybd_event(0x11,0,0,0)
+    win32api.keybd_event(90,0,0,0)
+    win32api.keybd_event(90,0,win32con.KEYEVENTF_KEYUP,0)
+    win32api.keybd_event(0x11,0,win32con.KEYEVENTF_KEYUP,0)
+def closeSubWin():
+    pass

+ 2 - 2
phxb/utils/getarray.py

@@ -128,8 +128,8 @@ def getitemIndexArrayNumber(itemIndex,m,n):
 # print(result)
 # getAllPosition(3, 3)
 # getAllArrayNumber(4,3)
-getitemIndexArray("11213",5,5)
-getitemIndexArrayAndPosition("11213",5,5)
+# getitemIndexArray("11213",5,5)
+# getitemIndexArrayAndPosition("11213",5,5)
 # getitemIndexAndPositionArray("113", 4, 3)
 # number = getitemIndexArrayNumber("11143",5,5)
 # print(number)

+ 15 - 7
phxb/utils/main.py

@@ -1,6 +1,6 @@
 from pyautocad import Autocad, APoint
 from ctypes import cdll
-from utils import getarray,GetAllModule
+from utils import getarray,GetAllModule,getHandler
 import os, time, shutil
 
 from pyautocad.cache import Cached
@@ -20,11 +20,14 @@ doorName = 'ssdr_800'
 # 判断文件是否打开
 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
 
 
@@ -37,13 +40,16 @@ def openOriginFile():
     time.sleep(10)
     print("origin file opened")
 def openFile(fileName):
-    if(is_open(_rootPath+_originFile)):
-        return
+    # 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")
@@ -109,17 +115,19 @@ def myprocess(m, n):
         #         copyfile(_rootPath + _originFile, newFileName)
         # break
 def moveSingleTemplate(fileName,position):
-    openFile(fileName)
+    # openFile(fileName)
+    GetAllModule.resetConfUsed()
     GetAllModule.moveBlockReference(position)
-    time.sleep(5)
+    time.sleep(3)
     acad = Autocad(create_if_not_exists = False)
     acad.prompt("Hello, Autocad from Python\n")
     acad.doc.SaveAs(fileName)
-    acad.doc.Shutdown()
-    # closeAcad()
+    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")

+ 5 - 3
phxb/utils/testopen.py

@@ -1,6 +1,6 @@
 # coding=utf-8
 from ctypes import *
-from pyautocad import Autocad
+from pyautocad import Autocad,APoint
 import win32api
 import os
 def openTxt(fileName):
@@ -17,8 +17,10 @@ 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)
+    acad = Autocad(create_if_not_exists = True)
+    p1 = APoint(0,0)
+    acad.model.InsertBlock(p1,file,1,1,1,0)
 # openbyApi()
 # shellDllOpen(r"e:/jstat.txt")
 # shellDllOpen(r"e:/jstat.txt")
-# autoOpen( r'F:\autocad_temp\newfile032.dwg')
+autoOpen( r'F:\autocad_temp\origin.dwg')