2021年5月26日 星期三

如何根據Pin Group自動設Circuit Port

以下代碼會在設有Pin Group的元件上設circuit ports。

create_circuit_port.py

import ScriptEnv

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

import clr

clr.AddReference('Ansys.Ansoft.Edb')
clr.AddReference('Ansys.Ansoft.SimSetupData')
import Ansys.Ansoft.Edb as edb

DB = edb.Database.Attach(int(oProject.GetEDBHandle()))
cells = list(DB.TopCircuitCells)

for i in cells:
if i.GetName() == (oDesign.GetName() if ';' not in oDesign.GetName() else oDesign.GetName().split(';')[1]):
layout = i.GetLayout()
break

all_ports = oEditor.FindObjects('Type', 'Port')

for pg in layout.PinGroups:
pg_name = pg.GetName()

pins = pg.GetPins()
comp_name = pins[0].GetComponent().GetName()
pg_net = pins[0].GetNet().GetName()

pinnames_to_set = []
portnames_to_set = []

for pin_name in oEditor.GetComponentPins(comp_name):
short_pin_name = oEditor.GetPropertyValue('BaseElementTab', pin_name, 'Component Pin')
pin_net = oEditor.GetPropertyValue('BaseElementTab', pin_name, 'Net')

if pin_net == pg_net:
continue

if pin_net == '':
for port_name in ('Port{}'.format(i) for i in range(1, 1000000)):
if port_name not in all_ports:
all_ports.append(port_name)
break
else:
port_name = '{}.{}.{}'.format(comp_name, short_pin_name, pin_net)

pinnames_to_set.append(pin_name)
portnames_to_set.append(port_name)

try:
oEditor.ToggleViaPin(["NAME:elements", ] + pinnames_to_set)
oEditor.AddPinGroupRefPort(portnames_to_set, [pg_name])
AddWarningMessage('{} excitations are added in {}!'.format(len(portnames_to_set), comp_name))

except:
pass
(圖一)自動加上circuit ports


沒有留言:

張貼留言