I am creating sketch segments and then giving them constraints (coincident, etc). The problem I am running into is selecting the correct sketch segment when I am working with them after creating. To my code, each segment looks the same as any other. Solidworks names line segments in the format "lines" + a number i.e. Line1, Line2, etc. The number that it appends on the end seems to be driven by more than just how many line segments in a sketch. In other words...it seems a bit unpredictable. It is getting incrimented somewhere but if seems like it is the total number of lines created in the session of solidworks up to that point or something.
Anyway...does anybody know a way to retrieve the name of the line segment (Line5) so I could use that name in the SelectByID method? Or maybe there is a better way to do this? Here is a snippit of code below...
SolidworksApi macrosswDoc.SetAddToDB(True)
swDoc.Insert3DSketch2(False)
line1 = swDoc.CreateLine2(vPt1(0), vPt1(1), vPt1(2), vPt2(0), vPt2(1), vPt2(2))
Dim startPoint As SketchPoint = line1.GetStartPoint2
Dim endPoint As SketchPoint = line1.GetEndPoint2'select the two and add the coincident
swDoc.ClearSelection2(True)
swDoc.Extension.SelectByID("Line1", "SKETCHPOINT", startPoint.X, startPoint.Y, startPoint.Z, False, 0, Nothing)
swDoc.Extension.SelectByID("", "EDGE", startPoint.X, startPoint.Y, startPoint.Z, True, 0, Nothing)
swDoc.SketchAddConstraints("sgCOINCIDENT")
'Select the opposite two and make them coincident
swDoc.ClearSelection2(True)
swDoc.Extension.SelectByID("Line1", "SKETCHPOINT", endPoint.X, endPoint.Y, endPoint.Z, False, 0, Nothing)
swDoc.Extension.SelectByID("", "EDGE", endPoint.X, endPoint.Y, endPoint.Z, True, 0, Nothing)
swDoc.SketchAddConstraints("sgCOINCIDENT")'Create vertical line
line2 = swDoc.CreateLine2(0, 0, 0, 1, 1, 1)
boolstatus = swDoc.Extension.SelectByID2("Line1", "SKETCHSEGMENT", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = swDoc.Extension.SelectByID2("Line2", "SKETCHPOINT", 0, 0, 0, True, 0, Nothing, 0)
swDoc.SketchAddConstraints("sgATMIDDLE")