|
@@ -5,12 +5,24 @@ import math
|
|
|
|
|
|
#这个true表示没有文件则打开一个,CAD有弹窗时会打开或者创建失败
|
|
|
acad = Autocad(create_if_not_exists = False)
|
|
|
+# 组件实体点位置
|
|
|
+positoins={}
|
|
|
+# 组件使用点位置
|
|
|
+useAreaPositions={}
|
|
|
# acad.prompt("Hello, Autocad from Python\n")
|
|
|
# print(acad.doc.Name)
|
|
|
def printObjects():
|
|
|
#遍历cad图形对象
|
|
|
for obj in acad.iter_objects():
|
|
|
print(obj.ObjectName)
|
|
|
+def printBlockObjects():
|
|
|
+ #遍历cad图形对象
|
|
|
+ for obj in acad.iter_objects("BlockReference"):
|
|
|
+ print(obj.name,obj.HasAttributes)
|
|
|
+ if obj.HasAttributes:
|
|
|
+ attrs = obj.GetAttributes()
|
|
|
+ for attrib in attrs:
|
|
|
+ print(" {}: {}".format(attrib.TagString, attrib.TextString))
|
|
|
def printTheTypeObject(type):
|
|
|
#按类型查找出所有某种图元
|
|
|
for text in acad.iter_objects(type):
|
|
@@ -26,6 +38,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)
|
|
|
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];
|
|
@@ -38,6 +51,9 @@ def moveBlockReferenceToWall(blockReference,wallIndex):
|
|
|
else:
|
|
|
blockReference.move(APoint(blockReference.InsertionPoint),APoint(0,conf.roomUsedLengths[3]))
|
|
|
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......")
|
|
|
# 根据新顺序移动模块
|
|
|
def moveBlockReferenceWithNewIndex(position,moduleIndex):
|
|
|
print(conf.moduleLengths)
|
|
@@ -65,8 +81,10 @@ def changeConfModuleIndex(moduleIndex):
|
|
|
def resetModuleIndex():
|
|
|
conf.names=['md_py','md_xs','md_rc']
|
|
|
conf.moduleLengths = (800,1000,800)
|
|
|
+# 判断位置是否可行
|
|
|
def isWorkable(position):
|
|
|
resetConfUsed()
|
|
|
+ positoins.clear()
|
|
|
print("position=",position)
|
|
|
needLength=[0]*4
|
|
|
for positionIndex in range(len(position)):
|
|
@@ -76,10 +94,100 @@ def isWorkable(position):
|
|
|
print(needLength[wallIndex]+conf.roomUsedLengths[wallIndex],conf.roomLengths[math.floor(wallIndex/2)],wallIndex)
|
|
|
return 0
|
|
|
return 1
|
|
|
+# 获取组件的四点坐标
|
|
|
+def getCenterPoint(wallIndex, x, y, blockIndex):
|
|
|
+ height = conf.moduleLengths[blockIndex];
|
|
|
+ width = conf.moduleHeights[blockIndex];
|
|
|
+ useHeight = conf.moduleUseLength[blockIndex]
|
|
|
+ useWidth = conf.humenLenght
|
|
|
+ usePointPosition = conf.moduleUsePoint[blockIndex]
|
|
|
+ useCenterPointPosition = conf.moduleUseCenterPoint[blockIndex]
|
|
|
+ pointA = (x,y)
|
|
|
+ print("insertPoint=",x,y)
|
|
|
+ if(wallIndex == 0):
|
|
|
+ pointB = (x,y+width)
|
|
|
+ pointC = (x-height,y+width)
|
|
|
+ pointD = (x-height,y)
|
|
|
+ centerPoint = (x-height/2,y+width/2)
|
|
|
+ usePoint= (x-usePointPosition[1],y+usePointPosition[0])
|
|
|
+ useCenterPoint= (x-useCenterPointPosition[1],y+useCenterPointPosition[0])
|
|
|
+ centerPointOffset = (height,width)
|
|
|
+ useCenterPointOffset = (useHeight,useWidth)
|
|
|
+ elif(wallIndex == 1):
|
|
|
+ pointB = (x-width,y)
|
|
|
+ pointC = (x-width,y-height)
|
|
|
+ pointD = (x,y-height)
|
|
|
+ centerPoint = (x-width/2,y-height/2)
|
|
|
+ usePoint= (x-usePointPosition[0],y-usePointPosition[1])
|
|
|
+ useCenterPoint= (x-useCenterPointPosition[0],y-useCenterPointPosition[1])
|
|
|
+ centerPointOffset = (width,height)
|
|
|
+ useCenterPointOffset = (useWidth,useHeight)
|
|
|
+ elif(wallIndex == 2):
|
|
|
+ pointB = (x,y-width)
|
|
|
+ pointC = (x+height,y-width)
|
|
|
+ pointD = (x+height,y)
|
|
|
+ centerPoint = (x+height/2,y-width/2)
|
|
|
+ usePoint= (x+usePointPosition[1],y-usePointPosition[0])
|
|
|
+ useCenterPoint= (x+useCenterPointPosition[1],y-useCenterPointPosition[0])
|
|
|
+ centerPointOffset = (height,width)
|
|
|
+ useCenterPointOffset = (useHeight,useWidth)
|
|
|
+ else:
|
|
|
+ pointB = (x+width,y)
|
|
|
+ pointC = (x+width,y+height)
|
|
|
+ pointD = (x,y+height)
|
|
|
+ centerPoint = (x+width/2,y+height/2)
|
|
|
+ usePoint= (x+usePointPosition[0],y+usePointPosition[1])
|
|
|
+ useCenterPoint= (x+useCenterPointPosition[0],y+useCenterPointPosition[1])
|
|
|
+ centerPointOffset = (width,height)
|
|
|
+ useCenterPointOffset = (useWidth,useHeight)
|
|
|
+ positoin = [centerPoint,centerPointOffset,usePoint,useCenterPoint,useCenterPointOffset];
|
|
|
+ print(wallIndex,width,height)
|
|
|
+ drawPointCircle((pointA, pointB, pointC, pointD, centerPoint, usePoint, useCenterPoint))
|
|
|
+ print(positoin)
|
|
|
+ return positoin
|
|
|
+# 打印辅助点
|
|
|
+def drawPointCircle(points):
|
|
|
+ for point in points:
|
|
|
+ acad.model.AddCircle(APoint(point[0],point[1]), 50)
|
|
|
+# 从插入点开始顺时针记录已摆放的组件
|
|
|
+def tempStoragePosition(x,y,wallIndex,blockIndex):
|
|
|
+ positoin = getCenterPoint(wallIndex, x, y, blockIndex);
|
|
|
+ result = 1
|
|
|
+ for item in positoins:
|
|
|
+ # 判断实体是否相交
|
|
|
+ result = isPositionFeasible(positoin,positoins[item])
|
|
|
+ if(result == 0):
|
|
|
+ positoins.clear()
|
|
|
+ return result
|
|
|
+ else:
|
|
|
+ # 判断可用区域是否与实体相交
|
|
|
+ usePoint = positoin[3]
|
|
|
+ positoin[0] = usePoint
|
|
|
+ positoin[1] = positoin[4]
|
|
|
+ result = isPositionFeasible(positoin,positoins[item])
|
|
|
+ if(result == 1):
|
|
|
+ positoins[len(positoins)] = positoin
|
|
|
+ return result
|
|
|
+
|
|
|
+# 计算位置是否可行
|
|
|
+def isPositionFeasible(position1,position2):
|
|
|
+ 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)
|
|
|
+ if(math.ceil(position1[0][0]-position2[0][0]) < (position1[1][0]+position2[1][0])/2):
|
|
|
+ if(math.ceil(position1[0][1]-position2[0][1]) < (position1[1][1]+position2[1][1])/2):
|
|
|
+ print("sorry! can not put here")
|
|
|
+ return 0
|
|
|
+ print("can put here 1")
|
|
|
+ return 1
|
|
|
+ else:
|
|
|
+ print("can put here 2")
|
|
|
+ return 1
|
|
|
# printObjects()
|
|
|
+# printBlockObjects()
|
|
|
# printTheTypeObject("BlockReference")
|
|
|
|
|
|
# moveBlockReference('222')
|
|
|
# a=[0,1,2]
|
|
|
# moveBlockReferenceWithNewIndex('001',a)
|
|
|
-# print(isWorkable('222'))
|
|
|
+# print(isWorkable('222'))
|
|
|
+# getCenterPoint(3,2200,0,1)
|