So basically, Trying to create this type of design using API from Visual Basic, Following are the steps:
- Create geometrically lines A, B sketch intersecting at origin
- create bi-directional offset
- extrude the offset
- generate a hole at origin
- curve driven pattern to produce the number of holes.
- Applying Fillet.
The problem is at No.5 as per my assessment, I am unable to select the edge to run the pattern. Highlighted the relevant code in Red.
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Module Program
Sub Main(args As String())
'Definitions
Dim ePointCX, ePointCY, midAx, midAy, midAz, midBx, midBy, midBz, ePointAX2, ePointAY2, ePointBX2, ePointBY2, lenA, lenB, lenBY, lenBX, angBEnd, angAB, widXY, exDim, radHole, noHoleA, noHoleB, holeSpacing As Double
Dim swApp As SldWorks
'Dimensions
lenB = 0.016931
lenA = 0.053264
angAB = 120
widXY = 0.01
exDim = 0.01
radHole = 0.0025
noHoleA = 6
noHoleB = 3
'Calculations
Dim angRad As Double
angRad = angAB * Math.PI / 180
angBEnd = angRad - Math.PI / 2
lenBX = lenB * Math.Cos(angRad)
lenBY = lenB * Math.Sin(angRad)
ePointCX = (widXY / 2) * Math.Tan(angBEnd)
Console.WriteLine("Cos angBEnd= {0}", (Math.Cos(angBEnd)))
Console.WriteLine("ePointCX= {0}", ePointCX)
ePointCY = (widXY / 2)
Console.WriteLine("ePointCY= {0}", ePointCY)
ePointAY2 = ePointCY
ePointAX2 = lenA
Console.WriteLine("ePointAX2= {0}", ePointAX2)
ePointBX2 = lenBX + ((widXY / 2) * Math.Cos(angBEnd))
Console.WriteLine("ePointBX2= {0}", ePointBX2)
ePointBY2 = (ePointCY * Math.Sin(angBEnd)) + lenBY
Console.WriteLine("ePointBY2= {0}", ePointBY2)
midAx = 0.5 * (ePointAX2 - ePointCX)
midAy = ePointCY
midBx = (0.5 * (ePointBX2 - ePointCX)) + (widXY / 2)
midBy = (0.5 * (ePointBY2 - ePointCY)) + (widXY / 2)
'Openning the SolidWorks with New Part
swApp = CreateObject("SldWorks.application")
swApp.Visible = True
Dim part As ModelDoc2 = swApp.NewPart() 'inserting a part
'inserting a sketch
part.SketchManager.InsertSketch(True)
Dim skSegment As Object
'drawing lines - 1
skSegment = part.SketchManager.CreateLine(0#, 0#, 0#, lenBX, lenBY, 0#)
skSegment = part.SketchManager.CreateLine(0#, 0#, 0#, lenA, 0#, 0#)
'selecting lines
part.SetPickMode()
part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", (lenBX - 0.001), (lenBY - 0.001), 0, False, 1, Nothing, 0)
'Creating offset - 2
part.SketchManager.SketchOffset2((widXY / 2), True, True, 1, 0, True)
'Setting Contruction Geometry - 1
part.Extension.SelectByID2("Line1", "SKETCHSEGMENT", (lenBX - 0.001), (lenBY - 0.001), 0, False, 1, Nothing, 0)
part.SketchManager.CreateConstructionGeometry()
part.Extension.SelectByID2("Line2", "SKETCHSEGMENT", (lenA - 0.001), 0, 0, False, 1, Nothing, 0)
part.SketchManager.CreateConstructionGeometry()
part.SketchManager.InsertSketch(True) 'End Sketch Mode
'Extrusions - 3
part.ClearSelection2(True)
part.Extension.SelectByID2("Sketch1", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)
part.Extension.SelectByID2("Sketch1", "SKETCHCONTOUR", (lenBX - 0.001), (lenBY - 0.001), 0, True, 4, Nothing, 0)
Dim extrude As Object
extrude = part.FeatureManager.FeatureExtrusion2(True, False, False, 0, 0, exDim, 0, False, False, False, False, 0, 0, False, False, False, False, True, True, True, 0, 0, False)
'Creating Hole - 4
part.SketchManager.InsertSketch(True)
part.Extension.SelectByRay(0, 0, exDim, lenBX, lenBY, exDim, 0.000347562946540947, 1, False, 0, 0)
part.ClearSelection2(True)
Dim skSegment2 As Object
skSegment2 = part.SketchManager.CreateCircle(0#, 0#, 0#, radHole, 0#, 0#)
part.ClearSelection2(True)
part.SketchManager.InsertSketch(True) 'End Sketch Mode
part.Extension.SelectByID2("Arc1@Sketch2", "EXTSKETCHSEGMENT", radHole, 0#, 0#, False, 0, Nothing, 0)
Dim hole As Object
hole = part.FeatureManager.FeatureCut4(True, False, True, 0, 0, exDim, exDim, False, False, False, False, 0, 0, False, False, False, False, False, True, True, True, True, False, 0, 0, False, False)
'Curve Driven Pattern Formation - 5
Dim swFeat As Feature
Dim swFeatMgr As FeatureManager
swFeatMgr = part.FeatureManager
Dim swFeatData As LocalCurvePatternFeatureData
swFeatData = swFeatMgr.CreateDefinition(swFeatureNameID_e.swFmLocalCurvePattern)
'Holes in Segment A
part.ClearSelection2(True)
part.Extension.SelectByID2("Cut-Extrude1", "BODYFEATURE", 0, 0, 0, False, 4, Nothing, 0)
part.Extension.SelectByID2("", "EDGE", midAx, midAy, 0, False, 1, Nothing, 0)
swFeatMgr = part.FeatureManager
swFeatData = swFeatMgr.CreateDefinition(swFeatureNameID_e.swFmLocalCurvePattern)
swFeatData.D1AlignmentMethod = 1
swFeatData.D1CurveMethod = 0
swFeatData.D1InstanceCount = noHolesA
swFeatData.D1IsEqualSpaced = True
swFeatData.D1ReverseDirection = False
swFeatData.D1Spacing = 0.01
swFeatData.D2InstanceCount = 1
swFeatData.D2IsEqualSpaced = False
swFeatData.D2PatternSeedOnly = False
swFeatData.D2ReverseDirection = False
swFeatData.D2Spacing = 0.01
swFeatData.Dir2Specified = False
swFeat = swFeatMgr.CreateFeature(swFeatData)
End Sub
End Module