12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- # -*- coding: UTF-8 -*-
- from pyautocad import Autocad, APoint
- from utils import conf
- import math
- #这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
- acad = Autocad(create_if_not_exists = False)
- # acad.prompt("Hello, Autocad from Python\n")
- # print(acad.doc.Name)
- def printObjects():
- #遍历cad图形对象
- for obj in acad.iter_objects():
- print(obj.ObjectName)
- def printTheTypeObject(type):
- #按类型查找出所有某种图元
- for text in acad.iter_objects(type):
- print(text.name)
- def moveBlockReference(position):
- print(conf.moduleLengths)
- for blockReference in acad.iter_objects("BlockReference"):
- 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];
- def resetConfUsed():
- conf.roomUsedLengths=[1200,0,0,1000]
- # printObjects()
- # printTheTypeObject("BlockReference")
- moveBlockReference('012')
|