2020年11月29日 星期日

3D Layout當中該如何找出Overlap物件?

(圖一) 部分紅色圓形與藍色方塊重疊


藍色方塊在Top層,紅色圓形在Bottom層。假設想要找出所有與藍色方塊重疊的紅色圓形並加以刪除,可參考底下程式碼:

import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oEditor = oDesign.GetActiveEditor()

x1 = set(oEditor.FindObjects('Type', 'rect'))
y1 = set(oEditor.FindObjects('Layer', 'Top'))
z1 = x1.intersection(y1)

x2 = set(oEditor.FindObjects('Type', 'circle'))
y2 = set(oEditor.FindObjects('Layer', 'Bottom'))
z2 = x2.intersection(y2)

todelete = []
for i in z1:
poly_i = oEditor.GetPolygon(i)
for j in z2:
poly_j = oEditor.GetPolygon(j)
if poly_i.GetIntersectionType(poly_j):
todelete.append(j)

oEditor.Delete(todelete)


(圖二)執行程式之後,重疊紅色圓形已被刪除




沒有留言:

張貼留言