2021年4月23日 星期五

在Q3D當中如何輸出self RLCG值

 # User Input

matrix_name = "Original"
frequency = 1000000000

# Don't Revise Code Below!-----------------------------------------------------
import os

os.chdir(os.path.dirname(__file__))

import ScriptEnv

ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oDesktop.ClearMessages("", "", 2)
oProject = oDesktop.GetActiveProject()
oDesign = oProject.GetActiveDesign()
oDesign.ExportMatrixData("matrix.csv", "C, DC RL, AC RL", "", "Setup1:LastAdaptive", matrix_name, "ohm", "nH", "pF",
"mSie", frequency, "Maxwell,Spice,Couple", 0, True, 15, 20, 1)
Q3D_name = oDesign.GetName()

alltype = ['DCPlusAC Resistance Matrix',
'DCPlusAC Resistance Matrix Coupling Coefficient',
'Capacitance Matrix',
'Capacitance Matrix Coupling Coefficient',
'Spice Capacitance Matrix',
'Conductance Matrix',
'Conductance Matrix Coupling Coefficient',
'Spice Conductance Matrix',
'DC Inductance Matrix',
'DC Inductance Matrix Coupling Coefficient',
'DC Resistance Matrix',
'DC Resistance Matrix Coupling Coefficient',
'AC Inductance Matrix',
'AC Inductance Matrix Coupling Coefficient',
'AC Resistance Matrix',
'AC Resistance Matrix Coupling Coefficient', ]

group = {}
with open("matrix.csv") as f:
for i in f:
if len(i.strip()) == 0:
continue

if i.strip() in alltype:
mtype = i.strip()
group[mtype] = []
continue

try:
data = i.strip().split(',')
if data:
group[mtype].append(data)
except:
pass

result = {}
for mtype in group:
result[mtype] = []
for n, data in enumerate(group[mtype][1:]):
name = data[0]
values = data[1:]
result[mtype].append((name, values[n]))

with open('self.csv', 'w') as f:
f.writelines('Q3D Design: {}\n'.format(Q3D_name))
for mtype in result:
f.writelines('\n[{}]\n'.format(mtype))
for item, value in result[mtype]:
f.writelines('{:20} {:20}\n'.format(item, value))

AddWarningMessage('"self.csv" is saved!')

(圖一) 輸出self.csv的內容


1 則留言: