GetAllModule.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- coding: UTF-8 -*-
  2. from pyautocad import Autocad, APoint
  3. from utils import conf
  4. import math
  5. #这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
  6. acad = Autocad(create_if_not_exists = False)
  7. # acad.prompt("Hello, Autocad from Python\n")
  8. # print(acad.doc.Name)
  9. def printObjects():
  10. #遍历cad图形对象
  11. for obj in acad.iter_objects():
  12. print(obj.ObjectName)
  13. def printTheTypeObject(type):
  14. #按类型查找出所有某种图元
  15. for text in acad.iter_objects(type):
  16. print(text.name)
  17. def moveBlockReference(position):
  18. print(conf.moduleLengths)
  19. for blockReference in acad.iter_objects("BlockReference"):
  20. print(blockReference.name)
  21. for item in conf.names:
  22. if(blockReference.name == item):
  23. moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
  24. def moveBlockReferenceToWall(blockReference,wallIndex):
  25. wallIndex = int(wallIndex)
  26. blockReference.rotate(APoint(blockReference.InsertionPoint),0.5*(wallIndex+1)*math.pi)
  27. blockIndex = conf.names.index(blockReference.name)
  28. if(wallIndex == 0):
  29. blockReference.move(APoint(blockReference.InsertionPoint),APoint(0+conf.moduleLengths[blockIndex]+conf.roomUsedLengths[0],0))
  30. conf.roomUsedLengths[0] = conf.roomUsedLengths[0]+conf.moduleLengths[blockIndex];
  31. elif (wallIndex == 1):
  32. blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomLengths[0],conf.roomLengths[1]-conf.roomUsedLengths[1]))
  33. conf.roomUsedLengths[1] = conf.roomUsedLengths[1]+conf.moduleLengths[blockIndex];
  34. elif (wallIndex == 2):
  35. blockReference.move(APoint(blockReference.InsertionPoint),APoint(conf.roomUsedLengths[2],conf.roomLengths[1]))
  36. conf.roomUsedLengths[2] = conf.roomUsedLengths[2]+conf.moduleLengths[blockIndex];
  37. else:
  38. blockReference.move(APoint(blockReference.InsertionPoint),APoint(0,conf.roomUsedLengths[3]))
  39. conf.roomUsedLengths[3] = conf.roomUsedLengths[3]+conf.moduleLengths[blockIndex];
  40. def resetConfUsed():
  41. conf.roomUsedLengths=[1200,0,0,1000]
  42. # printObjects()
  43. # printTheTypeObject("BlockReference")
  44. moveBlockReference('012')