Data Export Script

The following sample script demonstrates how to export data and save it to a file. The output data in the example script is in 3 columns. The first column is frequency in GHz, the second is the Real part of S11, and the third is the Img part of S11. It uses a tab-delimited format. The output is done using output variables.

The frequency sweep data must be entered correctly. If it is incorrect, the script will request a freq point that does not exist and execution will stop.

The script includes comment lines, which are preceded by an apostrophe ( ') and offer explanations for each subsequent line or lines.

Dim oAnsoftApp

Dim oDesktop

Dim oProject

Dim oDesign

Dim oEditor

Dim oModule

Set oAnsoftApp = CreateObject("Ansoft.ElectronicsDesktop")

Set oDesktop = oAnsoftApp.GetAppDesktop()

set oProject = oDesktop.GetActiveProject

set oDesign = oProject.GetActiveDesign()

Dim oFS,ofile,x,y,z,path,range,

Dim arr2,del_f,freq,cfreq,val,temp,stn,stw,i,line

'

' Input the desired file name.

'

path = inputbox("Input the file name" &chr(13) & _

"Note: If you do not specify a path the file will " & _

"be placed in the script directory", _

"File","C:\hfss_export.txt",50,50)

'

' If the user clicks Cancel the path will be blank, in which case the script should just exit.

If path <>"" then

'

' Create the file, open it for data entry, and output the column labels.

'

Set oFS = CreateObject("Scripting.FileSystemObject")

Set ofile = oFS.CreateTextFile (path)

line = "Freq" & chr(9) & "RE(S11)" & chr(9) & "IMG(S11)"

ofile.WriteLine line

'

' Input the needed freq, solution, and sweep data and clean it up.

'

msgbox("For the following input make sure it matches " & _

"the frequencies defined in your sweep")

range = inputbox("Input the range of frequencies in GHz " & _

"and number of points",_

"Frequency","8,12,10",50,50)

'

' The following 2 lines define the 2 output variables.

'

oDesign.CreateOutputVariable "re_S", "re(S(port1,port1))"

oDesign.CreateOutputVariable "im_S", "im(S(port1,port1))"

arr = split (range, ",")

arr(0) = Trim(arr(0))

arr(1) = Trim(arr(1))

arr(2) = Trim(arr(2))

if cint(arr(2)) <> 1 then

del_f = (arr(1)-arr(0))/(arr(2)-1)

else

del_f = 0

end if

temp = InputBox("Input the Setup and Sweep number to use:"_

& chr(13) & "(e.g. input 1,2 for Setup1 and Sweep2)", _

"Solution Data","1,1",50,50)

arr2 = split(temp,",")

stn = arr2(0)

swn = arr2(1)

stn = Trim(stn)

swn = Trim(swn)

'

' Loop through the freq points.

'

for i=1 to arr(2) step 1

freq = arr(0) + (cint(i)-1)*del_f

x=freq

cfreq="Freq='" & freq & "Ghz'"

'

' Get the values of the output variables for the desired freq.

'

val = oDesign.GetOutputVariableValue("re_S","Setup" & _

stn & " :Sweep" & swn,cfreq, "")

y = val

val = oDesign.GetOutputVariableValue("im_S","Setup" & _

stn & " : Sweep" & swn,cfreq, "")

z = val

'

' Create the line of text to send to the file and write it to the file.

'

line = x & chr(9) & y & chr(9) &z

ofile.WriteLine line

Next

'

' Delete the 2 output variables before finishing.

'

oDesign.DeleteOutputVariable "re_S"

oDesign.DeleteOutputVariable "im_S"

'

' Close the file.

'

ofile.close

End if