# -*- 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 moveBlockReferenceWithNewIndex(position,moduleIndex): print(conf.moduleLengths) blockReferences = [] for blockReference in acad.iter_objects("BlockReference"): print(blockReference.name) for item in conf.names: if(blockReference.name == item): blockReferences.append(blockReference) for index in moduleIndex: moveBlockReferenceToWall(blockReferences[index],position[conf.names.index(item)]) # 重置已使用墙的长度 def resetConfUsed(): conf.roomUsedLengths=[1200,0,0,1000] # 对模块重新排序 def changeConfModuleIndex(moduleIndex): names=[] moduleLengths=[] for index in range(len(conf.moduleLengths)): names.append(conf.names[moduleIndex[index]]) moduleLengths.append(conf.moduleLengths[moduleIndex[index]]) conf.names = names conf.moduleLengths = tuple(moduleLengths) # 重置模块顺序 def resetModuleIndex(): conf.names=['md_py','md_xs','md_rc'] conf.moduleLengths = (800,1000,800) # printObjects() # printTheTypeObject("BlockReference") # moveBlockReference('222') # a=[1,0,2] # moveBlockReferenceWithNewIndex('222',a)