浪尖玮 发表于 2019-4-23 17:24

Scripting in Maxwell的一个例子,仅供参考

例子是copy自Scripting in Maxwell,仅供初学者参考,大牛们请绕道而行{:1_551:}

浪尖玮 发表于 2019-4-23 17:25

Dim oAnsoftApp
Dim oDesktop
Dim oProject
Dim oDesign
Dim oEditor
Dim oModule
Set oAnsoftApp = CreateObject("AnsoftMaxwell.MaxwellScriptInterface")
Set oDesktop = oAnsoftApp.GetAppDesktop()
Set oProject = oDesktop.GetActiveProject()
Set oDesign = oProject.GetActiveDesign()
Set oEditor = oDesign.SetActiveEditor("3D Modeler")

Dim points(), segments()
Dim NumPoints, R(2), P(2), PointsPerTurn, Turns, Units

Pi = 4*Atn(1)

Units = InputBox("Select the units:"&Chr(13)& "(cm,mm,um,in,mil)", "Variable Helix","mil",50,50)

Select Case Units
Case "m"
Units = ""
Case "cm"
Case "mm"
Case "um"
Case "in"
Case "mil"
Case Else
MsgBox("Invalid Units - defaults to m")
Units = ""
End Select

Turns = InputBox("Select the number of turns (must be integer):","Variable Helix", 2,50,50)
PointsPerTurn = InputBox("Select the points per turn:", "Variable Helix",16,50,50)
R(0) = InputBox("Select the initial Radius: ", "Variable Helix",10,50,50)
R(1) = InputBox("Select the final Radius: ", "Variable Helix",10,50,50)
P(0) = InputBox("Select the initial Pitch: ", "Variable Helix", 4,50,50)
P(1) = InputBox("Select the final Pitch: ", "Variable Helix", 4,50,50)
NumPoints = Turns*PointsPerTurn

Redim points(NumPoints+1)
Redim segments(NumPoints)
points(0) = "NAME:PolylinePoints"
segments(0) = "NAME:PolylineSegments"

For n = 1 To (NumPoints+1)
Angle = (n-1)*2*Pi/PointsPerTurn
Radius = R(0) + ((n-1)/NumPoints)*(R(1)-R(0))
Pitch = P(0) + ((n-1)/NumPoints)*(P(1)-P(0))
Rise = (n-1)*Pitch/PointsPerTurn
XValue = cstr(Radius*cos(Angle)) & Units
YValue = cstr(Radius*sin(Angle)) & Units
ZValue = cstr(Rise) & Units
points(n) = Array("NAME:PLPoint", "X:=", XValue, "Y:=", YValue, "Z:=", ZValue)

If n<=NumPoints Then
segments(n) = Array("NAME:PLSegment", "SegmentType:=", "Line", "StartIndex:=", (n-1), "NoOfPoints:=", 2)
End If
Next

oEditor.CreatePolyline Array("NAME:PolylineParameters", "IsPolylineCovered:=", true, "IsPolylineClosed:=", false, points, segments), Array("NAME:Attributes", "Name:=", "Line_Helix","Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=",0.4, "PartCoordinateSystem:=", "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)

oEditor.CreateCircle Array("NAME:CircleParameters", "IsCovered:=", true, "XCenter:=",cstr(R(0))&Units, "YCenter:=", 0, "ZCenter:=", 0, "Radius:=", "1"&Units, "WhichAxis:=", "Y"), Array("NAME:Attributes", "Name:=", "Circle_Helix", "Flags:=", "", "Color:=", "(132 132 193)", "Transparency:=", 0.4, "PartCoordinateSystem:=", "Global", "MaterialName:=", "vacuum", "SolveInside:=", true)

oEditor.SweepAlongPath Array("NAME:Selections", "Selections:=", "Circle_Helix,Line_Helix"), Array("NAME:PathSweepParameters", "DraftAngle:=", "0deg", "DraftType:=", "Round", "TwistAngle:=", "0deg")

ayu 发表于 2019-4-23 18:58

能不能介绍一下模型的用途、代码的用途、以及如何运行,谢谢{:1_494:}

浪尖玮 发表于 2019-4-24 09:52

ayu 发表于 2019-4-23 18:58
能不能介绍一下模型的用途、代码的用途、以及如何运行,谢谢

直接复制代码到.vbs中,打开Maxwell软件,insert Maxwell 2D design,然后双击.vbs文件即可。

ayu 发表于 2019-4-24 14:43

小白一枚,麻烦再解答{:1_494:}:.vbs保存在哪个文件夹?还是Ansys的某位置?谢谢

浪尖玮 发表于 2019-4-25 09:49

ayu 发表于 2019-4-24 14:43
小白一枚,麻烦再解答:.vbs保存在哪个文件夹?还是Ansys的某位置?谢谢

我的是在桌面双击运行的,应该不必特定位置。双击运行之前要先打开Maxwell软件,并insert maxwell 2D模块,之后双击.vbs文件即可

ayu 发表于 2019-4-25 10:28

感谢指点{:1_490:}
页: [1]
查看完整版本: Scripting in Maxwell的一个例子,仅供参考