• 易迪拓培训,专注于微波、射频、天线设计工程师的培养
首页 > HFSS > HFSS help > Scripting using Embedded VBScript or JavaScript

HFSS15: Scripting using Embedded VBScript or JavaScript

录入:edatop.com     点击:

Since script recording is still done in VBScript and users are expected to have a significant collection of VBScript or JavaScript assets, it is useful to continue to use existing script files and snippets even when scripting in IronPython. The various Run<*>Command methods have been designed for this purpose.

For instance: one can create a parameterized cone in HFSS by executing the following IronPython script from the Tools>Run Script menu.

# assign the VBScript snippet obtained from a script recording from HFSS to

# coneScript and replace the BottomRadius recorded value with botRadius

coneScript = """Dim oAnsoftApp

Dim oDesktop

Dim oProject

Dim oDesign

Dim oEditor

Dim oModule

Set oAnsoftApp = CreateObject("AnsoftHfss.HfssScriptInterface")

Set oDesktop = oAnsoftApp.GetAppDesktop()

oDesktop.RestoreWindow

Set oProject = oDesktop.GetActiveProject()

oProject.InsertDesign "HFSS", "HFSSPyTestDesign", "DrivenModal", ""

Set oDesign = oProject.SetActiveDesign("HFSSPyTestDesign")

Set oEditor = oDesign.SetActiveEditor("3D Modeler")

oEditor.CreateCone Array("NAME:ConeParameters", _

"XCenter:=", "0mm", "YCenter:=", "0mm", "ZCenter:=", "0mm",_

"WhichAxis:=", "Z", "Height:=", "2mm", _

"BottomRadius:=", “3mm”, _

"TopRadius:=", "0mm"), Array("NAME:Attributes", "Name:=", _

"Cone1", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=", 0, _

"PartCoordinateSystem:=", "Global", "UDMId:=", "", "MaterialValue:=", _

"" & Chr(34) & "vacuum" & Chr(34) & "", "SolveInside:=", _

true)

"""

SetScriptingLanguageToVBScript()

RunScriptCommand(coneScript)

Sample Script 11: Hybrid VBScript + IronPython scripting: parameterized Cone Creation

Even though recorded VBScript is used for scripting, the incremental functionality that is provided using IronPython is the ability to write a GUI using IronPython/.NET, collect information from the user and then modify or generate the VBScript commands to actually script the ANSYS EM desktop. This GUI functionality is cross platform and a significant positive. The following example demonstrates a contrived use of a .NET window form to display the argument supplied to the IronPython script (via the ScriptArgument variable).

 

#import the CLR references

import clr

clr.AddReference("System.Windows.Forms")

 

from System.Windows.Forms import Application, Form, Label, Button, DockStyle

 

# the GUI form to show some text

# the class below derives from From (System.Windows.Forms.Form)

# imported above from the .NET assembly.

class ShowPropertiesForm(Form):

def __init__(self, name, text):

self.Name = name

self._label = Label()

self._label.Text = text

self._label.Dock = DockStyle.Fill

 

_button = Button()

_button.Text = "Close"

_button.Dock = DockStyle.Bottom

_button.Click += self._buttonPressed

 

self.Controls.Add(self._label)

self.Controls.Add(_button)

 

def _buttonPressed(self,sender,args):

self.Close()

 

#----------------------------------------------------

# Main script code

#----------------------------------------------------

#display the ScriptArgument variable as the text label

# in the form.

gui = ShowPropertiesForm("Sample Form", ScriptArgument)

 

# This makes it a modal dialog.

gui.ShowDialog()

 

# the following will make it a non-modal dialog

#Application.Run(gui)

Sample Script 12: Demonstrates the use of a .NET form from IronPython

While creating cross platform user interfaces from scripts is one of the main motivations driving the adoption of IronPython, any .NET assembly can be used with the caveat that Linux use requires Mono compatibility of any used assemblies.

While this hybrid approach is useful when you have existing VBScript commands that you want to reuse or when you want to quickly parameterize a recorded sample, the one significant limitation of this approach is the inability to capture return values from VBScript or JavaScript calls that do return something. Full two way communication with the product requires the use of pure IronPython to directly invoke the script objects as described below.

HFSS 学习培训课程套装,专家讲解,视频教学,帮助您全面系统地学习掌握HFSS

上一篇:Seeding the Mesh
下一篇:Scaling Sources and Setting Delays for HFSS Transient Network

HFSS视频培训课程推荐详情>>
HFSS教程推荐

  网站地图