In AEDT, the Automation panel’s recorder captures most actions, but it doesn’t reliably record file-selection steps. Use the snippets below to add file pickers to your scripts so users can choose the correct input and specify where to save the new AEDT file.
Open an AEDT file:
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
import clr, System
clr.AddReference("System.Windows.Forms")
clr.AddReference("Microsoft.VisualBasic")
from System.Windows.Forms import OpenFileDialog, DialogResult
from Microsoft.VisualBasic import Interaction
import System.IO as io
dlg = OpenFileDialog()
dlg.Title = "Select an AEDT Project (.aedt)"
dlg.Filter = "AEDT Project (*.aedt)|*.aedt|All files (*.*)|*.*"
dlg.Multiselect = False
if dlg.ShowDialog() != DialogResult.OK:
raise System.Exception("No project selected.")
project_path = dlg.FileName
default_name = io.Path.GetFileNameWithoutExtension(project_path)
oDesktop.OpenProject(project_path)
oProject = oDesktop.GetActiveProject()
try:
current_name = oProject.GetName()
except:
current_name = ""
# (Optional) Make it the active project explicitly
oDesktop.SetActiveProject(oProject.GetName())
print("Opened project:", oProject.GetName())
Import an EDB file:
import ScriptEnv, os, clr
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import FolderBrowserDialog, DialogResult
dlg = FolderBrowserDialog()
dlg.Description = "Select the .aedb folder"
if dlg.ShowDialog() != DialogResult.OK:
raise SystemExit("No EDB folder selected.")
edb_def = os.path.join(dlg.SelectedPath, "edb.def")
if not os.path.isfile(edb_def):
raise SystemExit("edb.def not found in the selected folder.")
oTool = oDesktop.GetTool("ImportExport")
oTool.ImportEDB(edb_def)
Import IPC2581 file
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
import os, clr, System
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import OpenFileDialog, FolderBrowserDialog, DialogResult, MessageBox, MessageBoxButtons
from System.IO import Path
dlg = OpenFileDialog()
dlg.Title = "Select IPC-2581 file"
dlg.Filter = "IPC-2581 (*.xml;*.zip)|*.xml;*.zip|All files (*.*)|*.*"
dlg.Multiselect = False
if dlg.ShowDialog() != DialogResult.OK:
raise SystemExit("No IPC-2581 file selected.")
ipc_path = dlg.FileName
default_aedb_name = Path.GetFileNameWithoutExtension(ipc_path) + ".aedb"
outDirDlg = FolderBrowserDialog()
outDirDlg.Description = "Choose output directory for the .aedb"
if outDirDlg.ShowDialog() != DialogResult.OK:
raise SystemExit("No output directory selected.")
out_aedb = Path.Combine(outDirDlg.SelectedPath, default_aedb_name)
if os.path.isdir(out_aedb):
res = MessageBox.Show("EDB already exists:\n{}\nOverwrite?".format(out_aedb),
"Overwrite?",
MessageBoxButtons.YesNo)
if str(res) != "Yes":
raise SystemExit("Cancelled to avoid overwrite.")
oTool = oDesktop.GetTool("ImportExport")
oTool.ImportIPC(ipc_path, out_aedb, "")
print("Imported IPC-2581 to:", out_aedb)
Import ODB++ file
import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
import os, clr, System
clr.AddReference("System.Windows.Forms")
from System.Windows.Forms import OpenFileDialog, FolderBrowserDialog, DialogResult, MessageBox, MessageBoxButtons
from System.IO import Path
dlg = OpenFileDialog()
dlg.Title = "Select ODB++ file"
dlg.Filter = "ODB++ (*.tgz;*.zip)|*.tgz;*.zip|All files (*.*)|*.*"
dlg.Multiselect = False
if dlg.ShowDialog() != DialogResult.OK:
raise SystemExit("No ODB++ file selected.")
odb_path = dlg.FileName
default_aedb_name = Path.GetFileNameWithoutExtension(odb_path) + ".aedb"
outDirDlg = FolderBrowserDialog()
outDirDlg.Description = "Choose output directory for the .aedb"
if outDirDlg.ShowDialog() != DialogResult.OK:
raise SystemExit("No output directory selected.")
out_aedb = Path.Combine(outDirDlg.SelectedPath, default_aedb_name)
if os.path.isdir(out_aedb):
res = MessageBox.Show("EDB already exists:\n{}\nOverwrite?".format(out_aedb),
"Overwrite?",
MessageBoxButtons.YesNo)
if str(res) != "Yes":
raise SystemExit("Cancelled to avoid overwrite.")
xml_dlg = OpenFileDialog()
xml_dlg.Title = "Optional: select control XML (Cancel to skip)"
xml_dlg.Filter = "XML (*.xml)|*.xml|All files (*.*)|*.*"
xml_path = ""
if xml_dlg.ShowDialog() == DialogResult.OK:
xml_path = xml_dlg.FileName
oTool = oDesktop.GetTool("ImportExport")
oTool.ImportODB(odb_path, out_aedb, xml_path)
print("Imported ODB++ from:", odb_path)
print("Created EDB:", out_aedb)