西莫电机圈

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

手机号码,快捷登录

查看: 6665|回复: 14

Maxwell 3D v11 VBScript Example

[复制链接]

该用户从未签到

发表于 2008-6-20 16:55 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
前言:参考官方的文档An M3DFS Macro Example编写了Maxwell 3D v11的脚本,与原文档格式基本一致,方便对照,主要的变动是原mac采用重新建立模型,这里采用修改模型的方法。没有采用中文编写,我英语水平超水(四级都没有过 ) ,语法、词汇错误就别指正了。

Defining the Problem
The device in this example is an actuator whose main parts are a magnetic circuit made of nonlinear steel and an energizing coil. In this analysis, you will plot the force on the armature as a function of the gap for
the coil current, as well as the coil’s self inductance as a function of the gap for the same currents. Both plots must be formatted in such a way that they can be imported directly into PlotData.
The macro reads all the necessary information from an ASCII file. This data set should contain the description of the geometry, range of gap values, range of current values, and the number of turns of the coil. The number of gaps and current steps will always be greater than two.
Finally, the macro should create the model to take advantage of the two-fold symmetry. Thus, only one- quarter of the model should be created. The results obtained from the macro (the plots of the force and inductance) should be scaled to represent the characteristics of the full model. Since Maxwell reports the
per turn inductance, an appropriate scaling must be performed to represent the measurable inductance.
1.PNG
The magnetic circuit is composed of a U-shaped object (in the quarter model it appears as an L-shaped object), a cylindrical core (one-quarter of it in the quarter model) and an armature. The cylindrical coil is wound around the core. The quarter model of the device is shown above.

Create the Script
The easiest way to create a script is to record the operations performed during the normal creation of the model. Once the model is created some editing is required to replace values used in the model with variables . Additional lines will usually be needed inside the script.
Start recording the script:
1 Click Tools>Record Script.
The Save As dialog box appears.
2 Use the file browser to locate the folder in which you want to save the script, such as C:\Ansoft\Maxwell11\Scripts, and then double-click the folder’s name.
3 Type “actuator” in the File name text box, and then click Save.
The script is saved in the folder you selected by the file name actuator.vbs.

Create the Model for the Macro
Now that the script is recording steps, create the 3D model in the Maxwell 3D Modeler.
        Create the model
1.        Click Project>Maxwell Design and select mm as units for the geometry.
2.        Create a box with the first corner at (0, 0, 0) and a size (40, 40, 5). Name this box u_plate.
3.        Create an additional box (part of the U-plate subassembly) with the first corner at (0, 35, 5) and the opposite corner at (40, 40, 65). Name this box u_plate1.
4.        Unite the two boxes. The U-plate subassembly is now complete.
5.        Create a new box with the first corner at (0, 0, 70) and the diagonally opposed corner at (50, 50,75). Name this box armature.
6.        Choose Lines/Rectangle and create a rectangle with the first corner at (0, 0, 5) in the xz plane with size x=10, z=60. Name this rectangle core.
7.        Choose Draw/Sweep/Around Axis… and sweep the rectangle clockwise around the z-axis by 90 degrees, using 8 segments. The magnetic circuit is now complete and only the coil needs to be added to the model.
8.        Choose Lines/Rectangle and create a rectangle with the first corner at (15, 0, 20) in the xz plane and the opposite corner at (25, 0, 50). Name this rectangle coil.
9.        Choose Draw/Sweep/Around Axis and create the coil by sweeping the rectangle around the z- axis 90 degrees using 8 segments. You should now add terminals to both end faces of the quarter coil.
10.        Select coil and choose 3D Modeler/Surface/Section and create two rectangles on the end faces and name them term1 and term2.
11.        Choose Draw/Region and create a region with the padding percentages:–X:0, +X: 300, -Y:0, +Y:300, -Z:50, +Z:100.
12.        Choose File/Save to save the project.

Assign Materials and Sources
Once the model is complete, you can assign material properties and the current sources to the objects in the model.
        Define the materials, sources, and executive parameters:
1.        Assign steel_1010 to the armature, u_plate, and core.
2.        Assign copper to the coil.
3.        Assign 1000 amperes to the two terminals of the coil.
4.        Choose File/Save to save the project.

Define Executive Parameters and Solution Options
Now define which solutions are to be generated, and the conditions with which they are to be solved.
        Define the executive parameters and solution options:
1.        Select the virtual force calculation for the armature.
2.        Choose coil as the object to be included in the inductance matrix calculation.
3.        Choose Maxwell/Anlysis setup/Add solution setup. The Solve Setup window appears.
4.        Set percent refinement per pass to 50% and leave the rest of the parameters at their default values.
5.        Choose OK.

Stop Recording the Macro
All steps needed for the script have now been completed.
To stop recording a script:
• On the Tools menu, click Stop Script Recording.
Maxwell stops recording to the script.
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过

该用户从未签到

 楼主| 发表于 2008-6-20 16:56 | 显示全部楼层
Completed Macro
The following script can be executed as it appears. As a result, the model will be reproduced exactly as it was created. However, because the intent is to create a more complex script, some editing is required.
  1. Dim oAnsoftApp
  2. Dim oDesktop
  3. Dim oProject
  4. Dim oDesign
  5. Dim oEditor
  6. Dim oModule

  7. Set oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface")
  8. Set oDesktop = oAnsoftApp.GetAppDesktop()
  9. oDesktop.RestoreWindow
  10. Set oProject = oDesktop.SetActiveProject("Project1")
  11. oProject.InsertDesign "Maxwell", "MaxwellDesign1", "Magnetostatic", ""
  12. Set oDesign = oProject.SetActiveDesign("MaxwellDesign1")
  13. Set oEditor = oDesign.SetActiveEditor("3D Modeler")

  14. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  15.   "0mm", "YPosition:=", "0mm", "ZPosition:=", "0mm", "XSize:=", "40mm", "YSize:=",  _
  16.   "40mm", "ZSize:=", "5mm"), Array("NAME:Attributes", "Name:=", "u_plate", "Flags:=", "", "Color:=",  _
  17.   "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  18.   "vacuum", "SolveInside:=", true)
  19.   
  20. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  21.   "0mm", "YPosition:=", "35mm", "ZPosition:=", "5mm", "XSize:=", "40mm", "YSize:=",  _
  22.   "5mm", "ZSize:=", "60mm"), Array("NAME:Attributes", "Name:=", "u_plate1", "Flags:=", "", "Color:=",  _
  23.   "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  24.   "vacuum", "SolveInside:=", true)
  25.   
  26. oEditor.Unite Array("NAME:Selections", "Selections:=", "u_plate,u_plate1"), Array("NAME:UniteParameters", "CoordinateSystemID:=",  _
  27.   -1, "KeepOriginals:=", false)
  28. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  29.   "0mm", "YPosition:=", "0mm", "ZPosition:=", "70mm", "XSize:=", "50mm", "YSize:=",  _
  30.   "50mm", "ZSize:=", "5mm"), Array("NAME:Attributes", "Name:=", "armature", "Flags:=",  _
  31.   "", "Color:=", "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  32.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  33. oEditor.CreateRectangle Array("NAME:RectangleParameters", "CoordinateSystemID:=",  _
  34.   -1, "IsCovered:=", true, "XStart:=", "0mm", "YStart:=", "0mm", "ZStart:=", "5mm", "Width:=",  _
  35.   "60mm", "Height:=", "10mm", "WhichAxis:=", "Y"), Array("NAME:Attributes", "Name:=",  _
  36.   "core", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  37.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  38. oEditor.SweepAroundAxis Array("NAME:Selections", "Selections:=", "core"), Array("NAME:AxisSweepParameters", "CoordinateSystemID:=",  _
  39.   -1, "DraftAngle:=", "0deg", "DraftType:=", "Round", "CheckFaceFaceIntersection:=",  _
  40.   false, "SweepAxis:=", "Z", "SweepAngle:=", "90deg", "NumOfSegments:=", "8")
  41. oEditor.CreateRectangle Array("NAME:RectangleParameters", "CoordinateSystemID:=",  _
  42.   -1, "IsCovered:=", true, "XStart:=", "15mm", "YStart:=", "0mm", "ZStart:=",  _
  43.   "20mm", "Width:=", "30mm", "Height:=", "10mm", "WhichAxis:=", "Y"), Array("NAME:Attributes", "Name:=",  _
  44.   "coil", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  45.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  46. oEditor.SweepAroundAxis Array("NAME:Selections", "Selections:=", "coil"), Array("NAME:AxisSweepParameters", "CoordinateSystemID:=",  _
  47.   -1, "DraftAngle:=", "0deg", "DraftType:=", "Round", "CheckFaceFaceIntersection:=",  _
  48.   false, "SweepAxis:=", "Z", "SweepAngle:=", "90deg", "NumOfSegments:=", "8")
  49. oEditor.Section Array("NAME:Selections", "Selections:=", "coil"), Array("NAME:SectionToParameters", "CoordinateSystemID:=",  _
  50.   -1, "SectionPlane:=", "ZX")
  51. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  52.   "Section1"), Array("NAME:ChangedProps", Array("NAME:Name", "Value:=", "term1"))))
  53. oEditor.Section Array("NAME:Selections", "Selections:=", "coil"), Array("NAME:SectionToParameters", "CoordinateSystemID:=",  _
  54.   -1, "SectionPlane:=", "YZ")
  55. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  56.   "Section1"), Array("NAME:ChangedProps", Array("NAME:Name", "Value:=", "term2"))))
  57. oEditor.CreateRegion Array("NAME:RegionParameters", "CoordinateSystemID:=", -1, "+XPadding:=",  _
  58.   "300", "-XPadding:=", "0", "+YPadding:=", "300", "-YPadding:=", "0", "+ZPadding:=",  _
  59.   "100", "-ZPadding:=", "50"), Array("NAME:Attributes", "Name:=", "Region", "Flags:=",  _
  60.   "Wireframe#", "Color:=", "(255 0 0)", "Transparency:=", 0, "PartCoordinateSystem:=",  _
  61.   "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)
  62. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  63.   "armature", "u_plate", "core"), Array("NAME:ChangedProps", Array("NAME:Material", "Material:=",  _
  64.   "steel_1010"))))
  65. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",  _
  66.   "coil"), Array("NAME:ChangedProps", Array("NAME:Material", "Material:=", "copper"))))
  67. Set oModule = oDesign.GetModule("BoundarySetup")
  68. oModule.AssignCurrent Array("NAME:Current1", "Current:=", "1000A", "IsSolid:=",  _
  69.   true, "Point out of terminal:=", false, "Objects:=", Array("term1"))
  70. oModule.AssignCurrent Array("NAME:Current2", "Current:=", "1000A", "IsSolid:=",  _
  71.   true, "Point out of terminal:=", true, "Objects:=", Array("term2"))
  72. Set oModule = oDesign.GetModule("MaxwellParameterSetup")
  73. oModule.AssignForce Array("NAME:Force1", "Is Virtual:=", true, "Reference CS:=",  _
  74.   "Global", "Objects:=", Array("armature"))
  75. oModule.AssignMatrix Array("NAME:Matrix1", Array("NAME:MatrixEntry", Array("NAME:MatrixEntry", "Source:=", _
  76.   "Current1", "NumberOfTurns:=", "1")), Array("NAME:MatrixGroup"), "Objects:=", Array( _
  77.   "coil"))
  78. Set oModule = oDesign.GetModule("AnalysisSetup")
  79. oModule.InsertSetup "Magnetostatic", Array("NAME:Setup1", "MaximumPasses:=", 10, "MinimumPasses:=",  _
  80.   2, "MinimumConvergedPasses:=", 1, "PercentRefinement:=", 30, "LinearResidual:=",  _
  81.   1E-005, "ConvergenceDispParamId:=", -1, "SolveFieldOnly:=", false, "PercentError:=",  _
  82.   1, "SolveMatrixAtLast:=", true, "UseOutputVariable:=", false, "PreAdaptMesh:=",  _
  83.   false, "NonLinearResidual:=", 0.01, "SolverType:=", 0, "MuNonLinearBH:=", true, "ComputeHc:=",  _
  84.   false, "HcNonLinearBH:=", true)
复制代码

[ 本帖最后由 Hottomson 于 2008-6-20 17:05 编辑 ]
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2008-6-20 16:57 | 显示全部楼层
Parameterizing the Macro Geometry
In cases where the geometry needs to be parameterized, substantial editing is required. First, several variables defining the geometry have to be defined. Variables are initialized as follows:
  1. 'Define
  2. Dim        u_plate_length
  3. Dim        u_plate_width
  4. Dim        u_plate_thick
  5. Dim        u_plate_high
  6. Dim        armature_length       
  7. Dim        armature_width
  8. Dim        armature_thick
  9. Dim        core_radius       
  10. Dim        core_height       
  11. Dim        coil_1_height
  12. Dim        coil_1_inner_rad
  13. Dim        coil_1_outer_rad
  14. Dim        coil_1_position       
  15. Dim        no_current_steps
  16. Dim        no_turns_coil1
  17. Dim        current_min
  18. Dim        current_max
  19. Dim        no_gaps       
  20. Dim        gap_min
  21. Dim        gap_max

  22. u_plate_length = 100
  23. u_plate_width =        60
  24. u_plate_thick =        5
  25. u_plate_high = 75
  26. armature_length        = 120
  27. armature_width = 80
  28. armature_thick = 5
  29. core_radius        = 10
  30. core_height        = 70
  31. coil_1_height =        5
  32. coil_1_inner_rad = 15
  33. coil_1_outer_rad = 25
  34. coil_1_position        = 25
  35. no_current_steps = 2
  36. no_turns_coil1 = 1000
  37. current_min        = 0.5
  38. current_max        = 1
  39. no_gaps        = 2
  40. gap_min        = 0.01
  41. gap_max        = 1
复制代码
The current range, number of current steps, and number of turns of the coil are also included because it is a good programming style to keep the initialization of all the parameters together. Names chosen for the variables are meaningful and describe their role in the model.

These names correspond with the following figure:
2.PNG


Parameterization
Next, the dimensions and locations of all the objects in the model are parameterized by replacing some of the numerical values with corresponding variables. Some calculations are also performed where needed.
As an example of how to do this, examine the following lines. Here, both the original and revised format of a geometry command are shown:
  1. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  2.   "0mm", "YPosition:=", "0mm", "ZPosition:=", "0mm", "XSize:=", "40mm", "YSize:=",  _
  3.   "40mm", "ZSize:=", "5mm"), Array("NAME:Attributes", "Name:=", "u_plate", "Flags:=", "", "Color:=",  _
  4.   "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  5.   "vacuum", "SolveInside:=", true)
复制代码
is replaced with the sequence
  1. Dim        u_plate_x,u_plate_y
  2. u_plate_x=u_plate_width/2
  3. u_plate_y=u_plate_length/2
  4. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  5.   "0mm", "YPosition:=",        "0mm", "ZPosition:=", "0mm", "XSize:=",        CStrmm(u_plate_x), "YSize:=",  _
  6.   CStrmm(u_plate_y), "ZSize:=",        CStrmm(u_plate_thick)),        Array("NAME:Attributes", "Name:=", "u_plate", _
  7.   "Flags:=", "", "Color:=",         "(132 132 193)", "Transparency:=",        0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  8.   "vacuum",        "SolveInside:=", true)
复制代码
Here used a self define function named CStrmm, which convert digital number to string with mm as the unit.
  1. Function CStrmm(nDig)
  2.         CStrmm = CStr(nDig)+"mm"
  3. End        Function
复制代码
The rest of the geometry section is modified along these guidelines, using mathematical operations and defining temporary variables whenever needed. The rest of the geometry section can be observed in the final form of the script at the end of the application note. Since the intent is to sweep the gap between the U-plate and armature, a gap variable is also defined and used in constructing the parametrized geometry.
The structure of the gap loop is shown below. The format chosen here is a WHILE (condition)- loop body- WEND. The body of the loop is executed as long as the WHILE condition holds true:
  1. Dim        gap_loop_index,no_gaps
  2. no_gaps = 2
  3. gap_loop_index = 0
  4. While gap_loop_index < no_gaps
  5.         temp = gap_max - gap_min
  6.         temp3 =        no_gaps        - 1
  7.         temp1 =        temp/temp3
  8.         temp2 =        temp1*gap_loop_index
  9.         gap        = gap_min +        temp2
  10.         temp = u_plate_thick
  11.         temp = temp        + u_plate_high
  12.         temp = temp        + gap

  13.         oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DCmdTab", Array("NAME:PropServers",  _
  14.                 "armature:CreateBox:1"), Array("NAME:ChangedProps", Array("NAME:Position", "X:=", "0mm", "Y:=",  _
  15.                 "0mm", "Z:=", CStrmm(temp)))))
  16.         '………………………… (body of the loop)
  17.         gap_loop_index = gap_loop_index+1
  18. 'loop back for gap
  19. Wend
复制代码
The loop counter (gap_loop_index) is incremented at the end of the loop, and if the condition of the WHILE statement still holds true, the geometry is modified.


Assigning Variable Values from Files
Another way to assign values to variables is to read the data from a specified text file or access databse. About this you can reference the books of VBScript.


Material Assignment Section
The material assignment section remains unchanged since the objects in our model are always the same. The structure of the material section inside the macro is shown below. Note that the materials must exist in the database prior to launching the execution of the script.
This section takes the following format:
  1. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers", _
  2.   "armature", "u_plate", "core"), Array("NAME:ChangedProps", Array("NAME:Material",        "Material:=",  _
  3.   "steel_1010"))))
  4. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers", _
  5.   "coil1"),        Array("NAME:ChangedProps", Array("NAME:Material", "Material:=",        "copper"))))
复制代码
Boundary/Source Section
The structure of the boundary and source assignment section of the macro is presented below. Here you must add a new loop to sweep the current in the specified range. The structure of the current loop is the same as that of the gap loop. For the current source, the ampere-turns are calculated and assigned to terminals:
  1. loop_index = 0
  2. loop_limit = no_current_steps
  3. temp = current_max - current_min
  4. temp3 =no_current_steps        -1
  5. temp1 =        temp/temp3
  6. temp2 =        temp1*loop_index
  7. curr = current_min + temp2
  8. curr = curr        * no_turns_coil1
  9. oModule.AssignCurrent Array("NAME:curr1_in", "Current:=", CStrA(curr), "IsSolid:=",         _
  10.   true,        "Point out of terminal:=", false, "Objects:=", Array("term1"))
  11. oModule.AssignCurrent Array("NAME:curr1_out", "Current:=", CStrA(curr),        "IsSolid:=",  _
  12.   true,        "Point out of terminal:=", true, "Objects:=", Array("term2"))
  13. '....................
  14. loop_limit = no_current_steps
  15. While        loop_index < loop_limit
  16.         temp = current_max - current_min
  17.         temp3 =no_current_steps        -1
  18.         temp1 =        temp/temp3
  19.         temp2 =        temp1*loop_index
  20.         curr = current_min + temp2
  21.         curr = curr        * no_turns_coil1
  22.         '....................       
  23.         oDesign.ChangeProperty Array("NAME:AllTabs", Array("NAME:MaxwellTab", Array("NAME:PropServers",  _
  24.                 "BoundarySetup:curr1_in"), Array("NAME:ChangedProps", Array("NAME:Current", "Value:=",  _
  25.                 CStrA(curr)))))
  26.         oDesign.ChangeProperty Array("NAME:AllTabs", Array("NAME:MaxwellTab", Array("NAME:PropServers",  _
  27.                 "BoundarySetup:curr1_out"), Array("NAME:ChangedProps", Array("NAME:Current", "Value:=",  _
  28.                 CStrA(curr)))))
  29.         '.........................
  30.         loop_index = loop_index +1
  31. Wend
复制代码
Force and Matrix Setup Section
The following section contains the force and inductance matrix setup:
  1. Set        oModule        = oDesign.GetModule("MaxwellParameterSetup")
  2. oModule.AssignForce        Array("NAME:group1", "Is Virtual:=", true, "Reference CS:=",  _
  3.   "Global",        "Objects:=", Array("armature"))
  4.   
  5. oModule.AssignMatrix Array("NAME:Matrix1", Array("NAME:MatrixEntry", Array("NAME:MatrixEntry", "Source:=",        _
  6.   "curr1_in", "NumberOfTurns:=", "1")),        Array("NAME:MatrixGroup"), "Objects:=",        Array( _
  7.   "coil1"))
复制代码
Solver Setup Section
The following section contains the solver setup:
  1. Set        oModule        = oDesign.GetModule("AnalysisSetup")
  2. oModule.InsertSetup        "Magnetostatic", Array("NAME:SolnOptnSetup", "MaximumPasses:=",        10, "MinimumPasses:=",  _
  3.   2, "MinimumConvergedPasses:=", 1,        "PercentRefinement:=", 50, "LinearResidual:=",        _
  4.   1E-006, "ConvergenceDispParamId:=", -1, "SolveFieldOnly:=", false, "PercentError:=",        _
  5.   1, "SolveMatrixAtLast:=",        true, "UseOutputVariable:=", false,        "PreAdaptMesh:=",  _
  6.   false, "NonLinearResidual:=",        0.01, "SolverType:=", 0, "MuNonLinearBH:=",        true, "ComputeHc:=",  _
  7.   false, "HcNonLinearBH:=",        true)
复制代码
Executing the MacroOnce the macro is complete, you can execute it from the Maxwell 3D Field Simulator.
To run a script:
1 Click Tools>Run Script.
The Open dialog box appears.
2 Use the file browser to locate the folder in which you saved the script, and then double-click the folder’s name.
3 Type the name of the script in the File name text box, or click its name, and then click Open.
Maxwell executes the script.
To supply script arguments when running from Tools>Run Script, use the edit field at the bottom of the file selection dialog. You can access the script arguments using the AnsoftScriptHost.arguments collection from vbscript. This is a standard COM collection.
To run a script from a command line (as described in the Maxwell Online Help):
1 Type one of the following command line options at the command line:
-runscriptandexit or -runscript
2 Press Enter.

Solution Results
The following section contains getting the results and extracting the results:
  1. oDesign.AddOutputVariable "ForceVal", "Force_magnitude"  ‘Note: Here can’t work well
  2. oDesign.AddOutputVariable "MatrixVal", "L(curr1_in,curr1_in)"

  3. Dim        ForceVal,MatrixVal
  4. '  
  5. 'Create the file, open it for data entry
  6. '
  7. Set oFS = CreateObject("Scripting.FileSystemObject")
  8. Set ofile1 = oFS.CreateTextFile ("force.txt")
  9. line = chr(9) & "Force vs gap"
  10. ofile1.WriteLine line
  11. line = "GAP [ mm ]" & chr(9)& "FORCE [ Newtons ]"
  12. ofile1.WriteLine line

  13. Set ofile2 = oFS.CreateTextFile ("L11.txt")
  14. line = chr(9) & "L_11 vs gap"
  15. ofile2.WriteLine line
  16. line = "GAP [ mm ]" & chr(9)& "INDUCTANCE [ Henries ]"
  17. ofile2.WriteLine line

  18. oDesign.Analyze        "SolnOptnSetup"

  19. ForceVal = oDesign.GetOutputVariableValue("ForceVal", "SolnOptnSetup : LastAdaptive","", "")
  20. MatrixVal =        oDesign.GetOutputVariableValue("MatrixVal",        "SolnOptnSetup : LastAdaptive","", "")

  21. ForceVal = ForceVal*4
  22. line = gap & chr(9) & ForceVal
  23. ofile1.WriteLine line

  24. MatrixVal = MatrixVal*4*no_turns_coil1*no_turns_coil1
  25. line = gap & chr(9) & MatrixVal
  26. ofile2.WriteLine line
复制代码

[ 本帖最后由 Hottomson 于 2008-6-20 17:11 编辑 ]
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2008-6-20 16:59 | 显示全部楼层
Complete Macro
The final script is presented below:
  1. Dim        oAnsoftApp
  2. Dim        oDesktop
  3. Dim        oProject
  4. Dim        oDesign
  5. Dim        oEditor
  6. Dim        oModule

  7. 'Define
  8. Dim        u_plate_length
  9. Dim        u_plate_width
  10. Dim        u_plate_thick
  11. Dim        u_plate_high
  12. Dim        armature_length       
  13. Dim        armature_width
  14. Dim        armature_thick
  15. Dim        core_radius       
  16. Dim        core_height       
  17. Dim        coil_1_height
  18. Dim        coil_1_inner_rad
  19. Dim        coil_1_outer_rad
  20. Dim        coil_1_position       
  21. Dim        no_current_steps
  22. Dim        no_turns_coil1
  23. Dim        current_min
  24. Dim        current_max
  25. Dim        no_gaps       
  26. Dim        gap_min
  27. Dim        gap_max

  28. u_plate_length = 100
  29. u_plate_width =        60
  30. u_plate_thick =        5
  31. u_plate_high = 75
  32. armature_length        = 120
  33. armature_width = 80
  34. armature_thick = 5
  35. core_radius        = 10
  36. core_height        = 70
  37. coil_1_height =        5
  38. coil_1_inner_rad = 15
  39. coil_1_outer_rad = 25
  40. coil_1_position        = 25
  41. no_current_steps = 2
  42. no_turns_coil1 = 1000
  43. current_min        = 0.5
  44. current_max        = 1
  45. no_gaps        = 2
  46. gap_min        = 0.01
  47. gap_max        = 1

  48. Set        oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface.11")
  49. Set        oDesktop = oAnsoftApp.GetAppDesktop()

  50. oDesktop.RestoreWindow
  51. Set        oProject = oDesktop.NewProject
  52. oProject.InsertDesign "Maxwell", "MaxwellDesign1", "Magnetostatic",        ""
  53. Set        oDesign        = oProject.SetActiveDesign("MaxwellDesign1")
  54. Set        oEditor        = oDesign.SetActiveEditor("3D Modeler")

  55. Dim        temp,temp1,temp2,temp3,gap,gap_loop_index

  56. gap_loop_index=0
  57. temp = gap_max - gap_min
  58. temp3 =        no_gaps        - 1
  59. temp1 =        temp/temp3
  60. temp2 =        temp1*gap_loop_index
  61. gap        = gap_min +        temp2

  62. Dim        u_plate_x,u_plate_y
  63. u_plate_x=u_plate_width/2
  64. u_plate_y=u_plate_length/2
  65. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  66.   "0mm", "YPosition:=",        "0mm", "ZPosition:=", "0mm", "XSize:=",        CStrmm(u_plate_x), "YSize:=",  _
  67.   CStrmm(u_plate_y), "ZSize:=",        CStrmm(u_plate_thick)),        Array("NAME:Attributes", "Name:=", "u_plate", _
  68.   "Flags:=", "", "Color:=",         "(132 132 193)", "Transparency:=",        0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  69.   "vacuum",        "SolveInside:=", true)
  70. '
  71. 'Calculate dimensions for quarter model        U Plate
  72. '  
  73. temp1 =        u_plate_x*(-1)
  74. temp2 =        u_plate_thick*(-1)
  75. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  76.   CStrmm(u_plate_x), "YPosition:=",        CStrmm(u_plate_y), "ZPosition:=", CStrmm(u_plate_thick), "XSize:=",        CStrmm(temp1), "YSize:=",  _
  77.   CStrmm(temp2), "ZSize:=",        CStrmm(u_plate_high)), Array("NAME:Attributes",        "Name:=", "u1",        _
  78.   "Flags:=", "", "Color:=",         "(132 132 193)", "Transparency:=",        0, "PartCoordinateSystem:=", "Global", "MaterialName:=",  _
  79.   "vacuum",        "SolveInside:=", true)

  80. oEditor.Unite Array("NAME:Selections", "Selections:=", "u_plate,u1"), Array("NAME:UniteParameters",        "CoordinateSystemID:=",         _
  81.   -1, "KeepOriginals:=", false)
  82. '
  83. 'Calculate dimensions for armature
  84. '  
  85. temp = u_plate_thick
  86. temp = temp        + u_plate_high
  87. temp = temp        + gap
  88. arm_y =        armature_length/2
  89. arm_x =        armature_width/2
  90. oEditor.CreateBox Array("NAME:BoxParameters", "CoordinateSystemID:=", -1, "XPosition:=",  _
  91.   "0mm", "YPosition:=",        "0mm", "ZPosition:=", CStrmm(temp),        "XSize:=", CStrmm(arm_x), "YSize:=",  _
  92.   CStrmm(arm_y), "ZSize:=",        CStrmm(armature_thick)), Array("NAME:Attributes", "Name:=",        "armature",        "Flags:=",        _
  93.   "", "Color:=", "(132 132 193)", "Transparency:=",        0, "PartCoordinateSystem:=",  _
  94.   "Global",        "MaterialName:=", "vacuum",        "SolveInside:=", true)
  95. '
  96. 'Calculate dimensions for the core
  97. '
  98. temp = u_plate_thick
  99. oEditor.CreateRectangle        Array("NAME:RectangleParameters", "CoordinateSystemID:=",  _
  100.   -1, "IsCovered:=", true, "XStart:=", "0mm", "YStart:=", "0mm", "ZStart:=", CStrmm(temp), "Width:=",  _
  101.   CStrmm(core_height), "Height:=", CStrmm(core_radius),        "WhichAxis:=", "Y"), Array("NAME:Attributes", "Name:=",         _
  102.   "core", "Flags:=", "", "Color:=",        "(132 132 193)", "Transparency:=", 0, "PartCoordinateSystem:=",         _
  103.   "Global",        "MaterialName:=", "vacuum",        "SolveInside:=", true)
  104. oEditor.SweepAroundAxis        Array("NAME:Selections", "Selections:=", "core"), Array("NAME:AxisSweepParameters",        "CoordinateSystemID:=",         _
  105.   -1, "DraftAngle:=", "0deg", "DraftType:=", "Round", "CheckFaceFaceIntersection:=",  _
  106.   false, "SweepAxis:=",        "Z", "SweepAngle:=", "90deg", "NumOfSegments:=", "8")
  107. '
  108. 'Calculate dimensions for coil_1
  109. '
  110. temp = u_plate_thick
  111. temp = temp        + coil_1_position
  112. temp1 =        coil_1_outer_rad - coil_1_inner_rad

  113. oEditor.CreateRectangle        Array("NAME:RectangleParameters", "CoordinateSystemID:=",  _
  114.   -1, "IsCovered:=", true, "XStart:=", CStrmm(coil_1_inner_rad), "YStart:=", "0mm",        "ZStart:=",         _
  115.   CStrmm(temp),        "Width:=", CStrmm(temp1), "Height:=", CStrmm(coil_1_height), "WhichAxis:=",        "Y"), Array("NAME:Attributes", "Name:=",  _
  116.   "coil1", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=",        0, "PartCoordinateSystem:=",  _
  117.   "Global",        "MaterialName:=", "vacuum",        "SolveInside:=", true)
  118. oEditor.SweepAroundAxis        Array("NAME:Selections", "Selections:=", "coil1"), Array("NAME:AxisSweepParameters", "CoordinateSystemID:=",  _
  119.   -1, "DraftAngle:=", "0deg", "DraftType:=", "Round", "CheckFaceFaceIntersection:=",  _
  120.   false, "SweepAxis:=",        "Z", "SweepAngle:=", "90deg", "NumOfSegments:=", "8")
  121.   
  122. oEditor.Section        Array("NAME:Selections", "Selections:=", "coil1"), Array("NAME:SectionToParameters", "CoordinateSystemID:=",  _
  123.   -1, "SectionPlane:=",        "ZX")

  124. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",         _
  125. "Section1"), Array("NAME:ChangedProps", Array("NAME:Name", "Value:=",        "term1"))))
  126. oEditor.Section        Array("NAME:Selections", "Selections:=", "coil1"), Array("NAME:SectionToParameters", "CoordinateSystemID:=",  _
  127. -1,        "SectionPlane:=", "YZ")
  128. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",         _
  129.   "Section1"), Array("NAME:ChangedProps",        Array("NAME:Name", "Value:=", "term2"))))
  130. '
  131. 'the new region        defination
  132. '
  133. oEditor.CreateRegion Array("NAME:RegionParameters",        "CoordinateSystemID:=",        -1,        "+XPadding:=",        _
  134.   "300", "-XPadding:=",        "0", "+YPadding:=",        "300", "-YPadding:=", "0", "+ZPadding:=",  _
  135.   "100", "-ZPadding:=",        "50"), Array("NAME:Attributes",        "Name:=", "Region",        "Flags:=",        _
  136.   "Wireframe#",        "Color:=", "(255 0 0)",        "Transparency:=", 0, "PartCoordinateSystem:=",        _
  137.   "Global",        "MaterialName:=", "vacuum",        "SolveInside:=", true)

  138. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",         _
  139.   "armature", "u_plate", "core"), Array("NAME:ChangedProps", Array("NAME:Material",        "Material:=",  _
  140.   "steel_1010"))))
  141. oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DAttributeTab", Array("NAME:PropServers",         _
  142.   "coil1"),        Array("NAME:ChangedProps", Array("NAME:Material", "Material:=",        "copper"))))
  143. Set        oModule        = oDesign.GetModule("BoundarySetup")
  144. '
  145. 'Loop for current steps
  146. '
  147. loop_index = 0
  148. loop_limit = no_current_steps
  149. temp = current_max - current_min
  150. temp3 =no_current_steps        -1
  151. temp1 =        temp/temp3
  152. temp2 =        temp1*loop_index
  153. curr = current_min + temp2
  154. curr = curr        * no_turns_coil1
  155. oModule.AssignCurrent Array("NAME:curr1_in", "Current:=", CStrA(curr), "IsSolid:=",         _
  156.   true,        "Point out of terminal:=", false, "Objects:=", Array("term1"))
  157. oModule.AssignCurrent Array("NAME:curr1_out", "Current:=", CStrA(curr),        "IsSolid:=",  _
  158.   true,        "Point out of terminal:=", true, "Objects:=", Array("term2"))
  159.   
  160. Set        oModule        = oDesign.GetModule("MaxwellParameterSetup")
  161. oModule.AssignForce        Array("NAME:group1", "Is Virtual:=", true, "Reference CS:=",  _
  162.   "Global",        "Objects:=", Array("armature"))
  163.   
  164. oModule.AssignMatrix Array("NAME:Matrix1", Array("NAME:MatrixEntry", Array("NAME:MatrixEntry", "Source:=",        _
  165.   "curr1_in", "NumberOfTurns:=", "1")),        Array("NAME:MatrixGroup"), "Objects:=",        Array( _
  166.   "coil1"))
  167.   
  168. Set        oModule        = oDesign.GetModule("AnalysisSetup")
  169. oModule.InsertSetup        "Magnetostatic", Array("NAME:SolnOptnSetup", "MaximumPasses:=",        10, "MinimumPasses:=",  _
  170.   2, "MinimumConvergedPasses:=", 1,        "PercentRefinement:=", 50, "LinearResidual:=",        _
  171.   1E-006, "ConvergenceDispParamId:=", -1, "SolveFieldOnly:=", false, "PercentError:=",        _
  172.   1, "SolveMatrixAtLast:=",        true, "UseOutputVariable:=", false,        "PreAdaptMesh:=",  _
  173.   false, "NonLinearResidual:=",        0.01, "SolverType:=", 0, "MuNonLinearBH:=",        true, "ComputeHc:=",  _
  174.   false, "HcNonLinearBH:=",        true)
复制代码

[ 本帖最后由 Hottomson 于 2008-6-20 17:12 编辑 ]
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2008-6-20 17:00 | 显示全部楼层
continue...
  1. oDesign.AddOutputVariable "ForceVal", "Force_magnitude"
  2. oDesign.AddOutputVariable "MatrixVal", "L(curr1_in,curr1_in)"

  3. Dim        ForceVal,MatrixVal
  4. '  
  5. 'Create the file, open it for data entry
  6. '
  7. Set oFS = CreateObject("Scripting.FileSystemObject")
  8. Set ofile1 = oFS.CreateTextFile ("force.txt")
  9. line = chr(9) & "Force vs gap"
  10. ofile1.WriteLine line
  11. line = "GAP [ mm ]" & chr(9)& "FORCE [ Newtons ]"
  12. ofile1.WriteLine line

  13. Set ofile2 = oFS.CreateTextFile ("L11.txt")
  14. line = chr(9) & "L_11 vs gap"
  15. ofile2.WriteLine line
  16. line = "GAP [ mm ]" & chr(9)& "INDUCTANCE [ Henries ]"
  17. ofile2.WriteLine line

  18. While gap_loop_index        < no_gaps

  19.         temp = gap_max - gap_min
  20.         temp3 =        no_gaps        - 1
  21.         temp1 =        temp/temp3
  22.         temp2 =        temp1*gap_loop_index
  23.         gap        = gap_min +        temp2
  24.         temp = u_plate_thick
  25.         temp = temp        + u_plate_high
  26.         temp = temp        + gap

  27.         oEditor.ChangeProperty Array("NAME:AllTabs", Array("NAME:Geometry3DCmdTab", Array("NAME:PropServers",  _
  28.                 "armature:CreateBox:1"), Array("NAME:ChangedProps", Array("NAME:Position", "X:=", "0mm", "Y:=",  _
  29.                 "0mm", "Z:=", CStrmm(temp)))))
  30.   
  31.         loop_limit = no_current_steps
  32.         While        loop_index < loop_limit
  33.                 temp = current_max - current_min
  34.                 temp3 =no_current_steps        -1
  35.                 temp1 =        temp/temp3
  36.                 temp2 =        temp1*loop_index
  37.                 curr = current_min + temp2
  38.                 curr = curr        * no_turns_coil1
  39.                
  40.                 line = "Current: "  & curr
  41.                 ofile1.WriteLine line
  42.                 ofile2.WriteLine line
  43.                
  44.                 oDesign.ChangeProperty Array("NAME:AllTabs", Array("NAME:MaxwellTab", Array("NAME:PropServers",  _
  45.                         "BoundarySetup:curr1_in"), Array("NAME:ChangedProps", Array("NAME:Current", "Value:=",  _
  46.                         CStrA(curr)))))
  47.                 oDesign.ChangeProperty Array("NAME:AllTabs", Array("NAME:MaxwellTab", Array("NAME:PropServers",  _
  48.                         "BoundarySetup:curr1_out"), Array("NAME:ChangedProps", Array("NAME:Current", "Value:=",  _
  49.                         CStrA(curr)))))
  50.                
  51.                 oDesign.Analyze        "SolnOptnSetup"
  52.                
  53.                 ForceVal = oDesign.GetOutputVariableValue("ForceVal", "SolnOptnSetup : LastAdaptive","", "")
  54.                 MatrixVal =        oDesign.GetOutputVariableValue("MatrixVal",        "SolnOptnSetup : LastAdaptive","", "")
  55.                
  56.                 ForceVal = ForceVal*4
  57.                 line = gap & chr(9) & ForceVal
  58.                 ofile1.WriteLine line
  59.                
  60.                 MatrixVal = MatrixVal*4*no_turns_coil1*no_turns_coil1
  61.                 line = gap & chr(9) & MatrixVal
  62.                 ofile2.WriteLine line
  63.                 loop_index = loop_index +1
  64.         Wend
  65.         gap_loop_index = gap_loop_index+1
  66. Wend

  67. ofile1.close
  68. ofile2.close

  69.   
  70. Function CStrmm(nDig)
  71.         CStrmm = CStr(nDig)+"mm"
  72. End        Function
  73. Function CStrA(nDig)
  74.         CStrA =        CStr(nDig)+"A"
  75. End        Function
复制代码
这个问题不用宏,直接采用参数化分析就可以完成。该脚本仅做参考,不保证正常运行 。

[ 本帖最后由 Hottomson 于 2008-6-20 17:13 编辑 ]
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

 楼主| 发表于 2008-6-20 17:01 | 显示全部楼层
这个问题不用宏,直接采用参数化分析就可以完成。该脚本仅做参考,不保证正常运行 。

遗留问题:关于Force的输出存在问题,以下语句不对:
oDesign.AddOutputVariable "ForceVal", "Force_magnitude"
该语句采用宏录制的,但实际不能运行,还请高手帮忙解决Force的输出问题。
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2008-7-29 10:07 | 显示全部楼层
能用脚本做已经是高人了,而且还能慷慨的拿出来与大家交流,难能可贵啊!
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-1-3 16:40 | 显示全部楼层
高手就是高手啊,让人仰望啊!
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-4-14 16:53 | 显示全部楼层
太难了,凡夫俗子根本看不懂
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-4-28 09:59 | 显示全部楼层
ansoft_maxwell_3d_v11 crack.rar (305.14 MB)
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-7-1 00:18 | 显示全部楼层
谢谢楼主提供!!
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-7-1 15:18 | 显示全部楼层
太强了
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-12-17 19:28 | 显示全部楼层
我哭死了,就没有一篇用中文的?!俺都不是学英语的~~~~~~~~~~~~
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2009-12-17 20:42 | 显示全部楼层
这些都不是自己写的,只不过是录制的脚本而已,这也拿上来贴,笑死人了。
有什么意义?!
有时间看看我写VB脚本和MATLAB脚本吧!
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

该用户从未签到

发表于 2010-1-7 10:07 | 显示全部楼层
楼主就是人才
西莫电机论坛微信公众平台正式上线!★详情请点击★ 西莫电机论坛会员交流专用群欢迎您西莫电机论坛加群请注明论坛用户名及所从事专业,否则不予通过
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|西莫电机圈 ( 浙ICP备10025899号-3 浙公网安备:33028202000436号

GMT+8, 2024-11-22 12:46 , Processed in 0.114395 second(s), 29 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表