Variable Helix Script

This sample script creates a tapered helix. Tapering helices is not supported from the interface.

The script includes comment lines, which are preceded by an apostrophe ( ') and offer explanations for each subsequent line or lines.

 

Dim oAnsoftApp

Dim oDesktop

Dim oProject

Dim oDesign

Dim oEditor

Dim oModule

Set oAnsoftApp = CreateObject("Ansoft.ElectronicsDesktop")

Set oDesktop = oAnsoftApp.GetAppDesktop()

Set oProject = oDesktop.GetActiveProject()

Set oDesign = oProject.GetActiveDesign()

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

 

’ Declare the arrays and variables needed for building the polyline.

’

Dim points(), segments()

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

’

’ Establish the constant Pi.

Pi = 4*Atn(1)

’ Retrieve the variable helix parameters from the user.

’ Start with the input for unit selection.

’

Units = InputBox("Select the units:"&Chr(13)& _

"(cm,mm,um,in,mil)", "Variable Helix","mil",50,50)

’

’ Check to make sure it is a valid unit.

’

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

’

’ Obtain the other user-defined parameters.

’

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

’

’ Initialize the points and segments arrays.

’

Redim points(NumPoints+1)

Redim segments(NumPoints)

points(0) = "NAME:PolylinePoints"

segments(0) = "NAME:PolylineSegments"

’

’ Build the Point and Segment Arrays needed in the HFSS polyline call.

’

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)

’

’ Create the line segments between each of the pairs of points.

’

If n<=NumPoints Then

segments(n) = Array("NAME:PLSegment", "SegmentType:=", _

"Line", "StartIndex:=", (n-1), "NoOfPoints:=", 2)

End If

Next

’

’ Create the polyline.

’

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)

’

’ Create the helix cross-section.

’

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)

’

’ Sweep the cross-section along the path.

’

oEditor.SweepAlongPath _

Array("NAME:Selections", "Selections:=", _

"Circle_Helix,Line_Helix"),

Array("NAME:PathSweepParameters", "DraftAngle:=", "0deg", _

"DraftType:=", "Round", "TwistAngle:=", "0deg")