Introduction To Programming In Visual Basic Scripts For ElecNet

Transcription

LECTURE 3Introduction to programming in Visual Basic Scripts for ElecnetThe aim of this lecture is to present shortly the writing of ElecNet scripts using the VisualBasic Script language. Basic notions and operators of the language are presented firstly, then,some simple scripts and one fully commented script for creation of ECT sensor are given. Theinformation here about Visual Basic Script language is based on the ElecNet VB ScriptingManual [2].Why is scripting nesessary?The goal of the scripting is to provide a convenient tool to automate modeling, solving,and post-processing tasks with ElecNet. Complex and repetitive tasks can be simplified with ascript by reducing a series of many commands to several lines of code. The scripts can befully parameterized introducing variables, and such scripts can be used for variantcomputations and for optimization.User scripts and formsWithin the various Infolytica applications (MagNet, ElecNet, ThermNet), two types ofscripts can be generated:- Scripts that are created by a user or recorded by ElecNet scripting utilities- Script forms that are designed and coded by the user.Scripts are text files that contain a series of scripting commands, written in Visual BasicScript language. Script files can be created or modified with a text editor (Notepad,Notepad ) or can be automatically generated using Infolytica application scripting utilitiesand later modified by the user. The user scripts must be saved in text format with the .vbsextension. We recommend using the Notepad text editor, which is free, has good featuresas coloring the VB operators, has multi-documents interface and others.In order to automatically create a user script, select 'Start Recording User Script' from theScripting menu in the horizontal menu bar and choose a name for the script. The applicationthen records all of the commands and actions carried out by the user until the user stops orpauses the script. Then, the script can be run by selecting 'Run Script' from the Scriptingmenu and choosing the desired script file.These recorded user scripts can be used as a starting point in generating scripts that aremore functional, adding variables, loops, etc.A scripting form provides a graphical user interface (GUI) similar to a Windowsapplication, such that the user can interact with the script and affect the result that areobtained from a given script. Forms can take in user input and return values based on thisinput. This makes the form more flexible than the user scripts. Furthermore, user scripts canbe incorporated into a form in order to facilitate coding for the user. Forms can be written ineither VBScript or in JScript.Below, a script form for Example 1 from the first lecture is shown:1

The creation of scripting forms will not be covered here as these are more advancedfeatures. Sufficient information on scripting forms can be found in the VB Scripting Manual[2] (reached via the Help menu).Three more manuals on ElecNet can be accessed via the Help menu: Introduction to ElecNet [1] ( Highly recommended ! Read it entirely ! ) Tutorials [3] Getting Started GuideSession logElecNet automatically generate a script file ( ElecNetSessionLog.vbs ) every time it isaccessed. This session log, located by default in the folder “C:\Documents andSettings\USERNAME\Application Data\Infolytica\elecnet(64-bit)\LogFiles”, can also be usedas a user script and run from within the application. The file contains a log of all the activitiesfrom the moment one enters the program until the program is closed. The ElecNet backup thesession log for up to ten times before the file is removed. The phrase 'Backup-' followed by anumber is appended to the front of the session log file name).One can view the contents of the session file by selecting 'View ElecNetSessionLog' from theHelp menu.Scripting infoElecNet 's scripting technology lets you use ElecNet to communicate with any applicationon your desktop that supports OLE Automation, such as Microsoft Word, Microsoft Excel,MATLAB or Mathcad. The implementation of Microsoft's ActiveX Scripting specificationsallows running ElecNet using VBScript (Microsoft Visual Basic, Scripting Edition) or JScript(Microsoft's version of a Java scripting language).Once the script has been built, it can be interfaced to a scripting form. The scripting form,which operates much like a dialog box, allows to hide the programming from the user and toleave him to operate only with several controls of the GUI.2

Scripting syntax guidelines:1. All commands are prefaced with a CALL statement. The default CALL statement usedin the ElecNet scripting commands is "CALL getDocument()".CALL getDocument().newDocument()2. Arguments should be enclosed in parentheses.CALL getDocument().selectAt(-1.0, -2.0, 3.0)3. Parentheses should be included even when empty.CALL getDocument().undo()4. Strings must be enclosed in quotes (" ").CALL getDocument().setDescription ("Sensor")5. Strings are case-sensitive (for example, material names are strings).6. Comments can follow to the right of an REM statement or an apostrophe (').REM rotate by 10 degrees' rotate by 10 degrees7. Extra blank lines, spaces, and tabs are ignored by VBScript.8. A line of code can be continue to the next line, using underscore sign at the end ofthat line.Declaring constants and variablesConstants are values within formulas that need to be used many times, without need ofchanging their values (e.g., the number pi 3.14159265, the permittivity of the aireps0 8.854E-12, etc.). To declare a constant pi, the following syntax should be used:Const pi 3.14159265Variables are items used to store data within a program. For example, if input data mustbe read, you could simply declare a variable and equate it to the value being read in from theuser form (or file). The values of the variables can be changed during program execution.In order to declare a variable, one uses the Dim command. The Dim command reservesspace in memory such that the variable can store any type of data.Dim VariableThe variable here is automatically declared as a variant such that it can store a string,numerical data, an array or any other variable type.Option ExplicitIn VBScript, one may use variables without first defining them. In order to have aprogram that only allows the use of variables that have been previously declared, the ‘OptionExplicit’ command must be used.The Option Explicit command is placed before all other statements in a script, apart from anysub or function. The advantage to using the Option Explicit command is that it prevents onefrom misspelling the names of variables.Declaring ArraysAn array is a special type of variable that can hold several different values. In order todeclare an array that can hold a given number of values, you need only enter the index of thelast element in the array in parentheses, directly after the variable declaration. Since the firstelement in the array has an index value of zero, you would declare a value one less than thetotal number of elements in the array. For example, to declare an array with 10 values, youwould use the statement:Dim ArrayName(9)3

The indices of the data within the array would range from zero to nine inclusive, a total of 10separate values.Once an array is declared with a given number of inputs, the same array name canlater be declared again with a different number of elements using the ReDim command.Furthermore, the ReDim command can be used to declare a previous variant variable as anarray. Examples:1.Dim MyArray1(4)ReDim MyArray1(9) - Resizing an existing array;2.Dim MyArray2ReDim MyArray2(9) - Converting from a variant to an array;3.Dim MyArray3()ReDim MyArray3(9) - Adding the size of an empty array.When inputting values into an array, one need only declare the name of the array andthe index and equate it to a value. Each index of a given array can contain values of differenttypes such as strings, integers, dates, etc.When resizing an array with the ReDim command, all of the information contained inan array is lost. In order to preserve the contents of an array while it is being resized, use the‘Preserve’ command:ReDim Preserve MyArray(15)This function call resizes an already existing array to another size while keeping all of theinformation that was previously stored in the array. Note that this statement can only be usedto increase the size of an array and not to decrease it.In order to delete the contents of an array, one would use the Erase command. Thesyntax for the Erase command isErase MyArrayThe dimensions of the array remain unchanged after the erase command is executed. Youmust take care not to name arrays ‘Array’. This is because Array is a function that is definedwithin VBScript that generates an array from a given list of elements. For example, thestatementMyArray Array(0,1,2,3,4,5)creates an array called MyArray which contains six elements: 0, 1, 2, 3, 4 and 5. Theseelements are placed in the array, in the listed order. Note that the array can contain values ofdifferent types such as strings, integers and dates.Variable manipulationWhen a program contains a variable, this variable can be manipulated by the programcode. In addition to equating different values to a variable, in the case of strings, differentstrings can be concatenated to form one long string.In order to concatenate two or more strings, use the ‘&’ or the ‘ ’ symbol between theindividual strings. Example:String1 “The rain in Spain”String2 “ falls mainly on the plain.”String3 String1 & String2‘String3’ will contain the value “The rain in Spain falls mainly on the plain.”Strings can be concatenated with other strings as well as to any other type of variable such asintegers and dates. All concatenated information will be stored as a string by the program.When variables are concatenated to strings, they are not placed in quotation marks.VBScript contains the following mathematical functions, that can be used inmathematical expressions:4

SymbolFunction Addition-Subtraction*Multiplication/\ DivisionInteger Division (keeps only the integerpart of the result)Returns the modulus (remainder) of adivisionExponent (e.g. 2 3 23)Cos(value)Cosine – Input value is in radiansSin(value)Sine – Input value is in radiansTan(value)Tangent – Input value is in radiansAtn(value)Arctangent – Input value is in radiansLog(value)Natural LogarithmExp(value)Exponentiation (evalue)Sqr(value)Square RootAbs(value)Absolute ValueModSubs and functionsA Sub refers to a subroutine that does not return a value. It executes a series ofstatements and then it returns control to the point in the program from which it was called.The syntax for a sub is:Sub Name(parameters)CodeEnd SubA Function, on the other hand, returns a value to the point that it was called in theprogram. Its structure is similar to that of subs. In order to return the value calculated by thefunction, the name of the function must be equated to the result obtained.Function Name(parameters)CodeName ResultEnd FunctionThe names of both functions and subs cannot contain any spaces. The names muststart with a letter and may include underscores and numbers.Parameters are the input values that a sub or a function needs in order to carry out atask. The parameters are enclosed within brackets after the name of the sub or function. Ifthere are no parameters, no parentheses are necessary.If a function or a sub has more than one parameter, the different parameters in the listare separated by commas.5

Subs and functions can be called from within other subs or functions. In order to call asub, you would merely enter the name of the sub along with any input parameters that the subwould require. In order to call a function, a value must be equated to the function call suchthat the program stores the returned value. Again, the parameters in the list are separated bycommas.SubName(parameters)Value FunctionName(parameters)Writing subs and functions can help to minimize the amount of coding necessary. If there is aseries of statements that must be used many times in a script, they can be written once insubroutines and accessed repeatedly. Furthermore, by using these subroutines, the code can bebroken down into functional sections such that each subroutine is responsible for a specifictask.Scope of a variableIf a single variable or a constant needs to be accessed by more than one subroutine,then the variable can be declared outside of all subroutines. Variables that are defined outsideall subs and functions are said to have a scope that includes the entire program. The scope of avariable indicates the region in which the variable can be accessed. Variables and constantsthat are defined within one sub cannot be accessed in another sub unless it is passed as aninput parameter.The if-then-else and select case statementsThe If-Then-Else statement is a structure that will execute a series of statementscontained within its structure, only if the criterion set within the control statement of the loopis met.The control statement in the loop is a statement that can evaluate to either True or False.Some control loops will be executed only if the control statement evaluates to True whileothers require the statement to evaluate to False. Within control statements, the mostcommonly used symbols are mathematical expressions of equality and inequality.Mathematical Symbols EqvSymbol MeaningLess thanGreater thanLess than and equal toGreater than and equal toNot equal toEqual toLogically equivalent toThe equality statement can be used to compare two strings of text as well as two numericalvalues. In instances where more than one criterion must be met, you can compound twostatements using the compound operators:Compound OperatorsAndOrXorNotPropertyTrue if both statements are TrueTrue if either of the two statements preceding is True.Exclusive Or. True if only one of the statements is True.Toggles the value of a Boolean statement.6

Together, these mathematical and compound operators can be used to form control statementsfor the If-Then-Else statement.The structure of the statement isIf (a 0 And a 10) Thena a –5Elsea a 5End IfOnly one of the statements is executed when the script is run, dependent upon the Booleanvalue of the control statement.This structure is additionally flexible in that the Else clause of the statement is optional.If there are more than two possible outcomes, one can nest the If-Then-Else statements withineach other.The syntax for the Select Case statement is as follows:Select Case VariableCase value1Statements1Case value2Statements2Case value3Statements3End SelectThis statement will execute one of three different sections of code depending on whether‘variable’ is equal to value1, value2 or value3. If it is not equal to any of these three values,the code is ignored and the statement after the select case statement is executed.Control loopsControl loops are similar to If-Then-Else statements in that they contain a control statementand they are only executed when an initial criterion is met. However, unlike the previousstructures, control loops will repeat the series of statements until the criterion is no longermet. There are several different types of control loops:1. For-NextFor i 1 To 20a a 1NextFor i 1 To 20 Step 2a a 1NextThe body of the loop executes the number of times indicated in the first line of the forstatement or until an exit statement is reached. The ‘Exit For’ statement may be includedwithin the loop.2. For Each-NextFor Each Value in ArrayNameMsgBox (Value)Next7

This body of the loop executes once for each value in an array or until an exit statement isreached. Within the loop, each array element, in turn, is assigned to the variable ‘Value’. The‘Exit For’ statement may be included within the loop.3. Do-LoopDo a a 1If (a 20) ThenExit DoEnd IfLoopIn this loop, the exit statement must be included within the statements in the loop or else theloop would continue infinitely. This is accomplished in the example by using an if statement.4. Do-Loop UntilDoa a–1Loop Until (a 20)The body of this loop executes at least once until the control statement at the end of the loopevaluates to True. The ‘Exit Do’ statement may be used within the Do-Until loop.5. Do-Loop WhileDo While (a 20)a a 1LoopThe body of this loop executes while the control statement at the beginning of the loopevaluates to True. The ‘Exit Do’ statement may be used within the Do-While loop.Further control can be added to a program by nesting loops.Input boxAn input box is a function that outputs a screen to the user and returns the user’s input.The input box can only take in one input at a time from a user. Example:VariableName InputBox (“Please enter the material name”)The value input by the user is held in ‘VariableName’ and can then be manipulated by thecode once the user hits ‘OK’. If the user hits on the Cancel button, then an empty string, “”, isreturned.In order to change the title of the input box from the default (‘Visual Basic’), a secondstring needs to be included in the declaration of the input box. If one wishes to declare theinput box with default text written within as input, then a third string must be added to thedeclaration:VariableName InputBox (“String Message”, “Input Box title”, “Default input”)Example:Var1 InputBox (“Enter Material:”, “Materials page”, “Copper”)8

Message boxes and outputsMessage boxes are small windows in VBScript that output messages to the user. Bydefault, message boxes have an ‘OK’ button. You can change the types of buttons that appearin a message box. Each different type of button has its own value. This value is returned fromthe Message Box function, indicating to the program code which button was clicked by theuser. Since the default form for a message box only has one button, in this instance, it is notnecessary to retain the return value and you can call a message box using the followingnotationMsgBox(“Place your message here”)When this is called, a message box will appear with the string appearing as the message andthe OK button appearing by default.When a message box appears, it suspends all activity of an application. Therefore, otherelements of a given program cannot be accessed until a message box is closed by clicking onone of its buttons.Apart from the default type of message box, in all other types of message boxes there is morethan one button that the user may click. In this instance, it is important to note which buttonthe user presses and have the program respond accordingly.By default, messages boxes output the message string in a single line. In order to havea multiple-lined message, in either a message box or a text box, you need to use the ‘Chr’array. The ‘Chr’ array is an array that contains all of the different ASCII characters that canbe output in a text message. In addition to the printable characters located on the keyboard,the ASCII characters provide for non-printable characters such as tabs and line carriages.The non-printable characters most commonly used are: Chr(9) – Horizontal Tab Chr(10) – Carriage Return (New Line) Chr(11) – Vertical Tab Chr(34) – Quotation marksSince this array already comes pre-defined with the program, you may not declare an arraywith the same name within the program code. In order to include these characters within anoutput string, one needs only to concatenate the array name and index of the character with astring.Five fully commented scripts are shown below:9

Example Script 1 – computing the capacitance of cylindrical capacitorOption Explicit' Title: Capacitance of cylindrical capacitor with two layers' Set problem optionsCall SetLocale("en-us")Call all getDocument().getView().showGrid(True)Call setViewingCurveSmoothnessAngle(1, False)Call all getDocument().setMaxElementSize("", 0.1)Call getDocument().setPolynomialOrder("", 2)Call getDocument().setImproveMeshQuality(True)' Specify input dataConst r1 1‘ inner radiusConst r2 2‘ middle radiusConst r3 3‘ outer radiusConst L 10‘ capacitor lengthConst Volts 1 ‘ potential of the outer electrodeConst epsr1 2.5 ‘ permittivity of the outer layerConst epsr2 3.5 ‘ permittivity of the inner layerConst pi 3.141592653589793238462643383Const e0 8.854e-12‘ permittivity of AirDim path, name, fname1, fname2name ”ex1”path "C:\Documents and Settings\kosta\My Documents\ElecNet\ElecNet course examples\"fname1 path & name & “.en"' name of the ElecNet model file ( en-file)fname2 path & name & ” cap.txt"' name of capacitance file (text file)' create 2 new materials, if they do no existDim matname1, matname2matname1 "New 2.5"matname2 "New 3.5"Call mater exist(matname1,epsr1, "blue" )Call mater exist(matname2,epsr2, "green2" )' available colors in the sub are: blue, green, green2, red, violet' Draw the 3 circles of the capacitorCall getDocument().getView().newCircle(0, 0, r3)Call getDocument().getView().newCircle(0, 0, r2)Call getDocument().getView().newCircle(0, 0, r1)Call getDocument().getView().setScaledToFit(True)' Create capacitor layer 2 (outside layer)Call getDocument().getView().selectAt( (r2 r3)/2, 0, infoSetSelection, Array(infoSliceSurface))Call getDocument().getView().makeComponentInALine(L, Array("Component#1"),"Name " matname1,infoMakeComponentUnionSurfaces Or infoMakeComponentRemoveVertices)' Create capacitor layer 1 (inner layer)Call getDocument().getView().selectAt( (r1 r2)/2, 0, infoSetSelection, Array(infoSliceSurface))Call getDocument().getView().makeComponentInALine(L, Array("Component#2"),"Name " matname2,infoMakeComponentUnionSurfaces Or infoMakeComponentRemoveVertices)' Make electrodes10

REDIM ArrayOfValues(1)ArrayOfValues(0) "Component#1,Face#3"ArrayOfValues(1) "Component#1,Face#4"Call getDocument().makeElectrode(ArrayOfValues)REDIM ArrayOfValues(1)ArrayOfValues(0) "Component#2,Face#5"ArrayOfValues(1) "Component#2,Face#6"Call getDocument().makeElectrode(ArrayOfValues)' Specify voltage 1 V on the Electrode 1 /Volts 1/Call , infoSetSelection)Call getDocument().setElectrodeVoltage("Electrode#1", Volts, 0)' make the construction grid invisibleCall getDocument().getView().showGrid(False)' fit the drawing to screen sizeCall getDocument().getView().setScaledToFit(True)' delete construction plane lines and arcsCall , Array(infoSliceLine, infoSliceArc))Call getDocument().getView().deleteSelection()' Start of code used to start a static solve.' The subroutines and functions defined below help do the work.Dim Doc' Make the call to solveStatic2dSet Doc getDocument()If (Doc.isValidForStatic2dSolver()) ThenIf (Doc.solveStatic2d()) ThenCall RefreshSolutionMeshesInViews(Doc)Call RefreshFieldsInViews(Doc, "Contour", infoScalarField)Call RefreshFieldsInViews(Doc, "Shaded", infoScalarField)Call RefreshFieldsInViews(Doc, "Arrow", infoVectorField)End IfEnd IfSet Doc Nothing' Post-processing' save the en-fileCall getDocument().save(fname1)' Compute chargesDim charge, CC, C1, C2, CA, err, L1, ssscharge getDocument().getSolution().getChargeOnElectrode (1, "Electrode#1")CC abs(charge/Volts)' Analytical formulas for the capacitanceL1 L*1e-3' C for the outer cylinderC1 2*pi*epsr1*e0*L1/log(r3/r2)' C for the inner cylinderC2 2*pi*epsr2*e0*L1/log(r2/r1)' equivalent C of the series connectionCA C1*C2/(C1 C2)' relative error in percentserr abs(CA-CC)/CA*100 ' in percentssss "Capacitance from ElecNet: " & CC & vbNewLine &11

"Capacitance analytical : "& CA & vbNewLine &"relative error in percents :" & errMsgBox sss' output a message box with the capacitances' write the capacitances in a text fileCall WriteTextFile(fname2, sss)' -- end of main ---Sub mater exist(matname,epsr, color)' create new material with specified name, permittivity and color' first, it checks if the material exists and whether the permittivity is as requiredDim mat exist, epsx, Arr(0,1), c1epsx 0if color "green" thenc1 Array(128,255,0,255)elseif color "green2" thenc1 Array(64,128,128,255)elseif color "blue" thenc1 Array(0,128,255,255)elseif color "red" thenc1 Array(255,0,128,255)elsec1 Array(128,0,255,255)' violetend ifmat exist name)if mat exist thenCALL matname, Arr, infoLinearIsotropicReal)epsx Arr(0,1)End Ifif not mat exist Or epsx epsr thenif mat exist thenCall nd IfCall getUserMaterialDatabase().newMaterial(matname)Call , c1(0), c1(1), c1(2), c1(3) )Call tname, Array())REDIM ArrayOfValues(0, 1)ArrayOfValues(0, 0) 20ArrayOfValues(0, 1) epsrCall matname, ArrayOfValues,infoLinearIsotropicReal)If (hasDocument()) ThenCall erial(matname, False)End IfEnd IfEnd Sub12

Example Script 2 - 32-electrode ----------------Option Explicit' Sensor32 – example script for' dept KIS standard sensor (4-layer, rectangular, 2 axial shields)' with inhomogeneity in the center with r 25 mm' Available cases:'1st Case :'2nd Case :'3rd Case:'4th Case :er media 3er media 3er media 1er media 1er bar 1er bar 3 - homogeneous fuller bar 3er bar 1 – homogeneous empty'Solving statistics p 2'No. of tetrahedra 430611'No. of nodes 85185'No. of Unary Faces 42726' Time 0:01:15 508.7 MB' optionsCall SetLocale("en-us")Call newDocument()Call all setViewingCurveSmoothnessAngle(1, False)Call getDocument().setMaxElementSize("", 6)Call getDocument().setPolynomialOrder("", 2)Call getDocument().setImproveMeshQuality(True)Call all getDocument().getView().setScaledToFit(True)' Input dataConst pi 3.141592653589793238462643383Const r1 75' inner radius of the sensor (mm)Const pipeth 3' pipe thickness [mm]Const thickness 1' thickness of the electrode (mm)Const h1 30' height of the inner layer electrodesConst h2 70' height of the outer layer electrodesConst n 8' number of electrodes in a layerConst sh 50' height of the guard shieldsConst d1 1' interelectrode angle (degrees) in theta-directionConst d2 1' interelectrode distance in z-directionConst dr 14' air distance from the electrode to the outer screenConst kind 4' kind of analysis: 1-4Const r0 25' radius of the inhomogeneity in the centerConst Volts 1' electrode voltageConst ElectrodeMaterial "Copper: 5.77e7 Siemens/meter"Const path "C:\Documents and Settings\kosta\My Documents\ElecNet\ElecNet course examples\"Const name "sensor32"Dim fname1, fname2fname1 path name ".en"fname2 path name " cap.txt"Dim Plastic1, Plastic1 5, Plastic3, Plastic, Plastic media, Plastic inhomPlastic1 "EP01: Relative permittivity 1"Plastic1 5 "EP1.5: Relative permittivity 1.5"Plastic3 "EP03: Relative permittivity 3"13

Call mater exist(Plastic1, 1, "blue")Call mater exist(Plastic1 5, 1.5, "green")Call mater exist(Plastic3, 3, "green2")if kind 1 thenPlastic media Plastic3Plastic inhom Plastic1elseif kind 2 thenPlastic media Plastic3Plastic inhom Plastic3elseif kind 3 thenPlastic media Plastic1Plastic inhom Plastic3elseif kind 4 thenPlastic media Plastic1Plastic inhom Plastic1elseMsgBox " Error in the kind number (1-4)" & vbNewLine & "kind " & kind& vbNewLine & "Default kind 4 is taken !"kind 4Plastic media Plastic1Plastic inhom Plastic1end ifDim dh, r2, theta, theta1, theta2, x1, y1, x2, y2, x3, y3, x4, y4, r3, r4dh dr' air distance from the top electrode to the outer airbox surface in zr2 r1 thickness ' outer radius of the electrodes (mm)r3 r1-pipeth' inner radius of the plastic pipe [mm]r4 r2 dr' the radius of the outer screen ( radius of the airbox)theta 2*pi/n' one electrode gap division in radianstheta1 d1/180*pi' the inter-electrode gap angle in radianstheta2 theta-theta1 ' the electrode angle in radians'ATTENTION - all arguments of the trigonometric functions in VBS are in RADIANS !'BUT, the angular arguments in ElecNet-functions are in degrees !'points coordinates of the cross-section of one electrodex1 r1*cos(0)y1 r1*sin(0)x2 r1*cos(theta2)y2 r1*sin(theta2)x3 r2*cos(0)y3 r2*sin(0)x4 r2*cos(theta2)y4 r2*sin(theta2)' Draw the cross-section of Electrode 1' draw 2 arc segmentsCall getDocument().getView().newArc(0, 0, x1, y1, x2, y2)Call getDocument().getView().newArc(0, 0, x3, y3, x4, y4)' draw 2 connecting linesCall nt)Call getDocument().getView().newLine(x1, y1, x3, y3)Call getDocument().getView().newLine(x2, y2, x4, y4)' Copy and rotate the electrode cross-section, to obtain the layer cross-sectionCall , Array(infoSliceLine, infoSliceArc))Dim thetagr, i, xc, yc, rr, ii, hhh14

thetagr 360/nFor i 1 to n-1Call getDocument().getView().rotateSelectedEdges(0, 0, thetagr*i, True)Next' Create four layers of electrodes by extrusion of the cross-section' hh1 electrode layers heights' hh2 distance to move the construction slice for each layerDim hh1, hh2, jhh1 Array(h2,h1,h1,h2)hh2 Array(0, h2 d2, h1 d2, h1 d2)rr r1 thickness/2 ' middle point radius of the electrodesii 0For j 1 to 4 ' loop on layers‘ move the construction planeif j 1 thenCall (j-1))end ifFor i 1 to n ' loop on electrodesii ii 1xc rr*cos(theta*(i-1) theta2/2) ' the electrode center point x-coordyc rr*sin(theta*(i-1) theta2/2) ' the electrode center point y-coordCall getDocument().getView().selectAt(xc, yc, infoSetSelection, Array(infoSliceSurface))Call getDocument().get

The creation of scripting forms will not be covered here as these are more advanced features. Sufficient information on scripting forms can be found in the VB Scripting Manual [2] (reached via the Help menu). Three more manuals on ElecNet can be accessed via the Help menu: Introduction to ElecNet [1] ( Highly recommended ! Read it entirely !