Macro Breakdown
UserForm
This macro starts by opening a Userform. In this form the user has the ability to choose the diameter of one strand in the braid and the total length of the braid, although in this version of the macro the total length of the braid cannot be changed all it does is create one link of the braid.
Braid Macro UserForm |
Create Planes
Next the macro inserts 3 3D sketches and draws a spline in each of the sketches. The points of the sketches are determined by multiple of the inputted diameter measurements. Below is an example of the spline creation:
Public Sub Create_Spline_1(Diameter As Double) Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc Part.SketchManager.Insert3DSketch True ' Create Spline Dim pointArray As Variant Dim points() As Double ReDim points(0 To 17) As Double points(0) = -1 * Diameter points(1) = -1 * (Diameter / 1.5) points(2) = 0 points(3) = -1 * Diameter points(4) = -1 * (Diameter / 1.5) points(5) = Diameter / 8 points(6) = -1 * (Diameter) points(7) = Diameter / 1.5 points(8) = Diameter * 2 points(9) = 0 points(10) = 0 points(11) = (Diameter * 4) points(12) = Diameter points(13) = (Diameter / -1.5) points(14) = (Diameter * 6) - (Diameter / 8) points(15) = Diameter points(16) = Diameter / -1.5 points(17) = Diameter * 6 pointArray = points Dim skSegment As Object Set skSegment = Part.SketchManager.CreateSpline((pointArray)) Part.SketchManager.Insert3DSketch True Part.ClearSelection2 True End Sub
Circle Sketches
In order to create a swept braid strand later it needs a sketch to sweep a long the spline. The macro then creates 3 sketches on the front plane with their center points intersecting with end points of the splines and the diameter set to the value taken in the UserForm. Below is an example of the code:
Public Sub Draw_Circles(Diameter As Double) Set swApp = Application.SldWorks Set Part = swApp.ActiveDoc ' Cirlce 1 Part.SketchManager.InsertSketch True boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", -5.10703921288805E-03, -2.59649850538866E-03, -4.90350149461128E-03, False, 0, Nothing, 0) Part.ClearSelection2 True Dim skSegment As Object Set skSegment = Part.SketchManager.CreateCircle(-1 * Diameter, -1 * (Diameter / 1.5), 0#, -1 * Diameter, (Diameter / -1.5) - (Diameter / 2), 0#) Part.ClearSelection2 True Part.SketchManager.InsertSketch True Part.ClearSelection2 True ' Circle 2 Part.SketchManager.InsertSketch True boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", -5.10703921288805E-03, -2.59649850538866E-03, -4.90350149461128E-03, False, 0, Nothing, 0) Part.ClearSelection2 True Set skSegment = Part.SketchManager.CreateCircle(0#, 0#, 0#, 0#, Diameter / 2, 0#) Part.ClearSelection2 True Part.SketchManager.InsertSketch True Part.ClearSelection2 True ' Circle 3 Part.SketchManager.InsertSketch True boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", -5.10703921288805E-03, -2.59649850538866E-03, -4.90350149461128E-03, False, 0, Nothing, 0) Part.ClearSelection2 True Set skSegment = Part.SketchManager.CreateCircle(Diameter, Diameter / 1.5, 0#, Diameter, (Diameter / 1.5) + (Diameter / 2), 0#) Part.ClearSelection2 True Part.SketchManager.InsertSketch True Part.ClearSelection2 True End Sub
Swept Boss\ Base
The final step is to create the strands. the macro selects 1 spline and 1 circle and preforms a swept boss. This process is repeated 3 times to make all the strands. Below is an example of the code:
boolstatus = Part.Extension.SelectByID2("Sketch1", "SKETCH", 7.11112277789861E-03, 1.27021790098527E-03, 0, False, 1, Nothing, 0) boolstatus = Part.Extension.SelectByID2("3DSketch1", "SKETCH", 6.81458693163701E-03, 4.54305795442467E-03, 4.79044795270839E-03, True, 4, Nothing, 0) Dim swFeat As Object Dim swFeatMgr As Object Set swFeatMgr = Part.FeatureManager Dim swFeatData As Object Set swFeatData = swFeatMgr.CreateDefinition(swFeatureNameID_e.swFmSweep) swFeatData.AdvancedSmoothing = False swFeatData.AlignWithEndFaces = 0 swFeatData.AutoSelect = True swFeatData.D1ReverseTwistDir = False swFeatData.Direction = -1 swFeatData.EndTangencyType = 0 swFeatData.FeatureScope = True swFeatData.MaintainTangency = False swFeatData.Merge = True swFeatData.MergeSmoothFaces = True swFeatData.PathAlignmentType = 10 swFeatData.StartTangencyType = 0 swFeatData.ThinFeature = False swFeatData.ThinWallType = 0 swFeatData.TwistControlType = 0 swFeatData.SetTwistAngle 0 swFeatData.SetWallThickness True, 0 Set swFeat = swFeatMgr.CreateFeature(swFeatData) Part.ClearSelection2 True
Future Plans
- Add the ability to chose the length of the braid.
- Create the braid with a taper
- Braid in a circle
- Transpose the braid onto different surfaces
- Create the a braided tube
Macro File