Browse Source

根据检测结果判断生成文件位置

duh 6 years ago
parent
commit
6f6ae63632
2 changed files with 41 additions and 14 deletions
  1. 26 7
      phxb/utils/GetAllModule.py
  2. 15 7
      phxb/utils/main.py

+ 26 - 7
phxb/utils/GetAllModule.py

@@ -30,12 +30,19 @@ def printTheTypeObject(type):
     conf.myprint(text.name)
 def moveBlockReference(position):
   positoins.clear()
+  useAreaPositions.clear()
   conf.myprint(conf.moduleLengths)
+  moveResult = 1
   for blockReference in acad.iter_objects("BlockReference"):
     conf.myprint(blockReference.name)
     for item in conf.names:
       if(blockReference.name == item):
-        moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
+        currentPosition[0] = position
+        currentPosition[1] = conf.names.index(item)
+        result = moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
+        if(result == 0):
+            moveResult = result
+  return moveResult
 def moveBlockReferenceToWall(blockReference,wallIndex):
   wallIndex = int(wallIndex)
   blockReference.rotate(APoint(blockReference.InsertionPoint),0.5*(wallIndex+1)*math.pi)
@@ -56,9 +63,14 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
   checkPositionIntersect = tempStoragePosition(blockReference.InsertionPoint[0],blockReference.InsertionPoint[1],wallIndex,blockIndex)
   if(checkPositionIntersect == 0):
     conf.myprint("wallIndex=",wallIndex,blockReference.name," not walkable......")
+    return 0
+  else:
+    return 1
 # 根据新顺序移动模块
 def moveBlockReferenceWithNewIndex(position,moduleIndex):
+  moveResult = 1
   positoins.clear()
+  useAreaPositions.clear()
   conf.myprint(conf.moduleLengths)
   blockReferences = []
   for blockReference in acad.iter_objects("BlockReference"):
@@ -70,7 +82,10 @@ def moveBlockReferenceWithNewIndex(position,moduleIndex):
     currentPosition[0] = position
     currentPosition[1] = moduleIndex
     currentPosition[2] = moduleIndex.index(index)
-    moveBlockReferenceToWall(blockReferences[index],position[moduleIndex.index(index)])
+    result = moveBlockReferenceToWall(blockReferences[index],position[moduleIndex.index(index)])
+    if(result == 0):
+        moveResult = result
+  return moveResult
 # 重置已使用墙的长度
 def resetConfUsed():
   conf.roomUsedLengths=[1200,0,0,1000]
@@ -157,18 +172,22 @@ def drawPointCircle(points):
 # 从插入点开始顺时针记录已摆放的组件
 def tempStoragePosition(x,y,wallIndex,blockIndex):
   positoin = getCenterPoint(wallIndex, x, y, blockIndex);
+  usePosition = (positoin[3],positoin[4])
   result = 1
   for item in positoins:
     # 判断实体是否相交
     result = isPositionFeasible(positoin,positoins[item],0)
     if(result == 1):
-      # 判断可用区域是否与实体相交
-      usePosition = (positoin[3],positoin[4])
-      result = isPositionFeasible(usePosition,positoins[item],1)
+      # 判断当前实体是否与已摆放的可用区域相交
+      result = isPositionFeasible(positoin,useAreaPositions[item],1)
+      if(result == 1):
+        # 判断可用区域是否与实体相交
+        result = isPositionFeasible(usePosition,positoins[item],1)
     if(result == 0):
       return result
   if(result == 1):
     positoins[len(positoins)] = positoin
+    useAreaPositions[len(useAreaPositions)] = usePosition
   return result
 
 # 计算位置是否可行type:0 实体 1可用区域
@@ -177,7 +196,7 @@ def isPositionFeasible(position1,position2,type):
   if type==0:
     acad.model.AddLine(APoint(position1[0][0],position1[0][1]),APoint(position2[0][0],position2[0][1]))
     acad.model.AddCircle(APoint(position1[0][0],position1[0][1]), 50)
-    areaName = "实体"
+    areaName = "实体区域"
   if(abs(position1[0][0]-position2[0][0]) < (position1[1][0]+position2[1][0])/2 and abs(position1[0][1]-position2[0][1]) < (position1[1][1]+position2[1][1])/2):
     conf.myprint(areaName,"sorry! can not put here",currentPosition,"position1=",position1,"position2=",position2)
     return 0
@@ -192,4 +211,4 @@ def isPositionFeasible(position1,position2,type):
 # a=[0,1,2]
 # moveBlockReferenceWithNewIndex('001',a)
 # conf.myprint(isWorkable('222'))
-getCenterPoint(3,4162.85,0,2)
+# getCenterPoint(3,4162.85,0,2)

+ 15 - 7
phxb/utils/main.py

@@ -14,6 +14,8 @@ _originFile = "origin.dwg"
 
 templateIndex = {'md_xs','md_py','md_rc'}
 doorName = 'ssdr_800'
+correctFilePath = "newfile2\\"
+errorFilePath = "errorfile2\\"
 
 # 这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
 # print(acad.doc.Name)
@@ -104,18 +106,17 @@ def myprocess(m, n):
         # indexAndPositionArray = getarray.getitemIndexAndPositionArray(positons[positon], m, n)
         number = getarray.getitemIndexArrayNumber(positons[positon], m, n)
         if (number == 1):
-            newFileName = _rootPath + "newfile\\" + "newfile" + str(positons[positon]) + ".dwg"
+            newFileName = _rootPath + correctFilePath + "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)
             if(GetAllModule.isWorkable(positons[positon])):
                 for moduleIndex in moduleIndexs:
-                    newFileName = _rootPath + "newfile\\"+ "newfile" + str(positons[positon]) + str(moduleIndex) + ".dwg"
+                    newFileName = _rootPath + correctFilePath+ "newfile" + str(positons[positon]) + str(moduleIndex) + ".dwg"
                     if(not os.path.exists(newFileName)):
-                        copyfile(_rootPath + _originFile, newFileName)
+                        # copyfile(_rootPath + _originFile, newFileName)
                         moveMultipleTemplate(newFileName,positons[positon],moduleIndex)
                         # break
                 # break
@@ -126,19 +127,25 @@ def myprocess(m, n):
 def moveSingleTemplate(fileName,position):
     # openFile(fileName)
     GetAllModule.resetConfUsed()
-    GetAllModule.moveBlockReference(position)
-    time.sleep(3)
+    result = GetAllModule.moveBlockReference(position)
+    time.sleep(1)
     acad = Autocad(create_if_not_exists = False)
     acad.prompt("Hello, Autocad from Python\n")
+    if(result == 0):
+        fileName = fileName.replace(correctFilePath,errorFilePath)
+    copyfile(_rootPath + _originFile, fileName)
     acad.doc.SaveAs(fileName)
     time.sleep(1)
     getHandler.backToOrigin()
 def moveMultipleTemplate(fileName,position,moduleIndex):
     GetAllModule.resetConfUsed()
-    GetAllModule.moveBlockReferenceWithNewIndex(position,moduleIndex)
+    result = GetAllModule.moveBlockReferenceWithNewIndex(position,moduleIndex)
     time.sleep(1)
     acad = Autocad(create_if_not_exists = False)
     acad.prompt("Hello, Autocad from Python\n")
+    if(result == 0):
+        fileName = fileName.replace(correctFilePath,errorFilePath)
+    copyfile(_rootPath + _originFile, fileName)
     acad.doc.SaveAs(fileName)
     time.sleep(1)
     getHandler.backToOrigin()
@@ -152,3 +159,4 @@ myprocess(4, 3)
 # acad.prompt("Hello, Autocad from Python\n")
 # print(acad.doc.Name)
 # moveMultipleTemplate(r"F:\autocad_temp\newfile\newfile.dwg",'001',[0,1,2])
+# moveSingleTemplate(r"F:\autocad_temp\newfile\newfile2.dwg",'012')