從3D Layout匯出HFSS,HFSS物件的名稱為層數及編號。用net命名更加清楚,底下兩組腳本可以用來完成重新命名的工作。
在3D Layout執行,從3D Layout輸出座標訊息到rename.json檔案當中。
Rename_Net_1.py
import ScriptEnv
import json, os
from collections import OrderedDict
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oDesktop.ClearMessages("", "", 2)
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oEditor = oDesign.SetActiveEditor("Layout")
os.chdir(os.path.dirname(__file__))
db = {}
layerinfo = OrderedDict()
lower_elevation = 0
for layer in oEditor.GetStackupLayerNames()[::-1]:
info = oEditor.GetLayerInfo(layer)
layer_thickness = float(info[12].split(':')[1])
layerinfo[layer] = lower_elevation + layer_thickness / 2
lower_elevation += layer_thickness
db[layer] = []
for i in oEditor.FindObjects('Layer', layer):
otype = oEditor.GetPropertyValue('BaseElementTab', i, 'Type')
if otype in ['Pin', 'Via']:
location = oEditor.GetPropertyValue('BaseElementTab', i, 'Location')
elif otype in ['line', 'poly']:
location = oEditor.GetPropertyValue('BaseElementTab', i, 'Pt1')
else:
continue
x, y = location.split(',')
net = oEditor.GetPropertyValue('BaseElementTab', i, 'Net')
db[layer].append((x.strip(), y.strip(), net, otype))
with open('rename.json', 'w') as f:
json.dump((layerinfo, db), f, indent=4)
AddWarningMessage('Completed!')
在HFSS執行,讀取rename.json完成重新命名工作
Rename_Net_2.py
# ----------------------------------------------
# Script Recorded by ANSYS Electronics Desktop Version 2021.1.0
# 14:33:37 Apr 16, 2021
# ----------------------------------------------
import json, os
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oDesktop.ClearMessages("", "", 2)
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oEditor = oDesign.SetActiveEditor("3D Modeler")
os.chdir(os.path.dirname(__file__))
unit = oEditor.GetModelUnits()
with open('rename.json') as f:
layer_info, db = json.load(f)
result = {}
dielectric = []
for layer in db:
z = layer_info[layer]
for obj in db[layer]:
x, y, net, otype = obj
if net not in result:
result[net] = []
names = oEditor.GetBodyNamesByPosition(["NAME:Parameters",
"XPosition:=", "{}{}".format(x, unit),
"YPosition:=", "{}{}".format(y, unit),
"ZPosition:=", "{}{}".format(z * 1000, 'mm')
])
for name in names:
if name in dielectric:
continue
else:
dk = oEditor.GetPropertyValue('Geometry3DAttributeTab', name, 'Solve Inside')
if str(dk) == 'true':
dielectric.append(name)
elif name not in result[net]:
result[net].append(name)
else:
pass
# AddWarningMessage(str(result))
total = len(result)
n = 0
for net in result:
try:
n += 1
oDesktop.AddMessage(oProject.GetName(), oDesign.GetName(), 0, '{}/{}'.format(n, total))
oEditor.ChangeProperty(
[
"NAME:AllTabs",
[
"NAME:Geometry3DAttributeTab",
[
"NAME:PropServers"
] + result[net],
[
"NAME:ChangedProps",
[
"NAME:Name",
"Value:=" , ''.join(x if x.isalnum() else '_' for x in net)
]
]
]
])
except:
AddErrorMessage(str(result[name]))
oDesktop.AddMessage(oProject.GetName(), oDesign.GetName() ,0 ,'Completed!')
|
(圖一)以netname命名物件 |