|
@@ -7,30 +7,32 @@ import math
|
|
|
acad = Autocad(create_if_not_exists = False)
|
|
|
# 组件实体点位置
|
|
|
positoins={}
|
|
|
+currentPosition = {}
|
|
|
# 组件使用点位置
|
|
|
useAreaPositions={}
|
|
|
# acad.prompt("Hello, Autocad from Python\n")
|
|
|
-# print(acad.doc.Name)
|
|
|
+# conf.myprint(acad.doc.Name)
|
|
|
def printObjects():
|
|
|
#遍历cad图形对象
|
|
|
for obj in acad.iter_objects():
|
|
|
- print(obj.ObjectName)
|
|
|
+ conf.myprint(obj.ObjectName)
|
|
|
def printBlockObjects():
|
|
|
#遍历cad图形对象
|
|
|
for obj in acad.iter_objects("BlockReference"):
|
|
|
- print(obj.name,obj.HasAttributes)
|
|
|
+ conf.myprint(obj.name,obj.HasAttributes)
|
|
|
if obj.HasAttributes:
|
|
|
attrs = obj.GetAttributes()
|
|
|
for attrib in attrs:
|
|
|
- print(" {}: {}".format(attrib.TagString, attrib.TextString))
|
|
|
+ conf.myprint(" {}: {}".format(attrib.TagString, attrib.TextString))
|
|
|
def printTheTypeObject(type):
|
|
|
#按类型查找出所有某种图元
|
|
|
for text in acad.iter_objects(type):
|
|
|
- print(text.name)
|
|
|
+ conf.myprint(text.name)
|
|
|
def moveBlockReference(position):
|
|
|
- print(conf.moduleLengths)
|
|
|
+ positoins.clear()
|
|
|
+ conf.myprint(conf.moduleLengths)
|
|
|
for blockReference in acad.iter_objects("BlockReference"):
|
|
|
- print(blockReference.name)
|
|
|
+ conf.myprint(blockReference.name)
|
|
|
for item in conf.names:
|
|
|
if(blockReference.name == item):
|
|
|
moveBlockReferenceToWall(blockReference,position[conf.names.index(item)])
|
|
@@ -38,7 +40,7 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
|
|
|
wallIndex = int(wallIndex)
|
|
|
blockReference.rotate(APoint(blockReference.InsertionPoint),0.5*(wallIndex+1)*math.pi)
|
|
|
blockIndex = conf.names.index(blockReference.name)
|
|
|
- print("begin to put ",blockReference.name)
|
|
|
+ conf.myprint("begin to put ",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];
|
|
@@ -53,17 +55,21 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
|
|
|
conf.roomUsedLengths[3] = conf.roomUsedLengths[3]+conf.moduleLengths[blockIndex];
|
|
|
checkPositionIntersect = tempStoragePosition(blockReference.InsertionPoint[0],blockReference.InsertionPoint[1],wallIndex,blockIndex)
|
|
|
if(checkPositionIntersect == 0):
|
|
|
- print("wallIndex=",wallIndex,blockReference.name," not walkable......")
|
|
|
+ conf.myprint("wallIndex=",wallIndex,blockReference.name," not walkable......")
|
|
|
# 根据新顺序移动模块
|
|
|
def moveBlockReferenceWithNewIndex(position,moduleIndex):
|
|
|
- print(conf.moduleLengths)
|
|
|
+ positoins.clear()
|
|
|
+ conf.myprint(conf.moduleLengths)
|
|
|
blockReferences = []
|
|
|
for blockReference in acad.iter_objects("BlockReference"):
|
|
|
- print(blockReference.name)
|
|
|
+ conf.myprint(blockReference.name)
|
|
|
for item in conf.names:
|
|
|
if(blockReference.name == item):
|
|
|
blockReferences.append(blockReference)
|
|
|
for index in moduleIndex:
|
|
|
+ currentPosition[0] = position
|
|
|
+ currentPosition[1] = moduleIndex
|
|
|
+ currentPosition[2] = moduleIndex.index(index)
|
|
|
moveBlockReferenceToWall(blockReferences[index],position[moduleIndex.index(index)])
|
|
|
# 重置已使用墙的长度
|
|
|
def resetConfUsed():
|
|
@@ -84,14 +90,13 @@ def resetModuleIndex():
|
|
|
# 判断位置是否可行
|
|
|
def isWorkable(position):
|
|
|
resetConfUsed()
|
|
|
- positoins.clear()
|
|
|
- print("position=",position)
|
|
|
+ conf.myprint("position=",position)
|
|
|
needLength=[0]*4
|
|
|
for positionIndex in range(len(position)):
|
|
|
wallIndex = int(position[positionIndex])
|
|
|
needLength[wallIndex]+=conf.moduleLengths[positionIndex]
|
|
|
if(needLength[wallIndex]+conf.roomUsedLengths[wallIndex] > conf.roomLengths[wallIndex%2]):
|
|
|
- print(needLength[wallIndex]+conf.roomUsedLengths[wallIndex],conf.roomLengths[math.floor(wallIndex/2)],wallIndex)
|
|
|
+ conf.myprint(needLength[wallIndex]+conf.roomUsedLengths[wallIndex],conf.roomLengths[math.floor(wallIndex/2)],wallIndex)
|
|
|
return 0
|
|
|
return 1
|
|
|
# 获取组件的四点坐标
|
|
@@ -103,7 +108,7 @@ def getCenterPoint(wallIndex, x, y, blockIndex):
|
|
|
usePointPosition = conf.moduleUsePoint[blockIndex]
|
|
|
useCenterPointPosition = conf.moduleUseCenterPoint[blockIndex]
|
|
|
pointA = (x,y)
|
|
|
- print("insertPoint=",x,y)
|
|
|
+ conf.myprint("insertPoint=",x,y)
|
|
|
if(wallIndex == 0):
|
|
|
pointB = (x,y+width)
|
|
|
pointC = (x-height,y+width)
|
|
@@ -141,9 +146,9 @@ def getCenterPoint(wallIndex, x, y, blockIndex):
|
|
|
centerPointOffset = (width,height)
|
|
|
useCenterPointOffset = (useWidth,useHeight)
|
|
|
positoin = [centerPoint,centerPointOffset,usePoint,useCenterPoint,useCenterPointOffset];
|
|
|
- print(wallIndex,width,height)
|
|
|
+ conf.myprint(wallIndex,width,height)
|
|
|
drawPointCircle((pointA, pointB, pointC, pointD, centerPoint, usePoint, useCenterPoint))
|
|
|
- print(positoin)
|
|
|
+ conf.myprint(positoin)
|
|
|
return positoin
|
|
|
# 打印辅助点
|
|
|
def drawPointCircle(points):
|
|
@@ -156,13 +161,12 @@ def tempStoragePosition(x,y,wallIndex,blockIndex):
|
|
|
for item in positoins:
|
|
|
# 判断实体是否相交
|
|
|
result = isPositionFeasible(positoin,positoins[item],0)
|
|
|
- if(result == 0):
|
|
|
- positoins.clear()
|
|
|
- return result
|
|
|
- else:
|
|
|
+ if(result == 1):
|
|
|
# 判断可用区域是否与实体相交
|
|
|
usePosition = (positoin[3],positoin[4])
|
|
|
result = isPositionFeasible(usePosition,positoins[item],1)
|
|
|
+ if(result == 0):
|
|
|
+ return result
|
|
|
if(result == 1):
|
|
|
positoins[len(positoins)] = positoin
|
|
|
return result
|
|
@@ -174,15 +178,11 @@ def isPositionFeasible(position1,position2,type):
|
|
|
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 = "实体"
|
|
|
- if(abs(position1[0][0]-position2[0][0]) < (position1[1][0]+position2[1][0])/2):
|
|
|
- print(areaName,"begin to check y")
|
|
|
- if(abs(position1[0][1]-position2[0][1]) < (position1[1][1]+position2[1][1])/2):
|
|
|
- print(areaName,"sorry! can not put here","position1=",position1,"position2=",position2)
|
|
|
- return 0
|
|
|
- print(areaName,"can put here 1")
|
|
|
- return 1
|
|
|
+ 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
|
|
|
else:
|
|
|
- print(areaName,"can put here 2")
|
|
|
+ conf.myprint(areaName,"can put here")
|
|
|
return 1
|
|
|
# printObjects()
|
|
|
# printBlockObjects()
|
|
@@ -191,5 +191,5 @@ def isPositionFeasible(position1,position2,type):
|
|
|
# moveBlockReference('222')
|
|
|
# a=[0,1,2]
|
|
|
# moveBlockReferenceWithNewIndex('001',a)
|
|
|
-# print(isWorkable('222'))
|
|
|
-# getCenterPoint(3,2200,0,1)
|
|
|
+# conf.myprint(isWorkable('222'))
|
|
|
+getCenterPoint(3,4162.85,0,2)
|