淘宝官方店 推荐课程 在线工具 联系方式 关于我们 | |
微波射频仿真设计 Ansoft Designer 中文培训教程 | HFSS视频培训教程套装 |
|
首页 >> Ansoft Designer >> Ansoft Designer在线帮助文档 |
Script Guide > Scripting using Embedded VBScript or JavaScriptSince 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 Designer by executing the following IronPython script from the Tools>Run Script menu. # assign the VBScript snippet obtained from a script recording from Designer 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("AnsoftDesigner.DesignerScriptInterface") Set oDesktop = oAnsoftApp.GetAppDesktop() oDesktop.RestoreWindow Set oProject = oDesktop.GetActiveProject() oProject.InsertDesign "Designer", "DesignerPyTestDesign", "DrivenModal", "" Set oDesign = oProject.SetActiveDesign("DesignerPyTestDesign") 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 CreationEven 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 Ansoft 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 IronPythonWhile 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. Related Topics IronPython Script Execution Environment HFSS视频教程 ADS视频教程 CST视频教程 Ansoft Designer 中文教程 |
Copyright © 2006 - 2013 微波EDA网, All Rights Reserved 业务联系:mweda@163.com |