In a recent query, a developer wanted to retrieve the points of tangency of sketch lines with circles. The way to do get that information is to set up the sketch constraints right just as you would with the Inventor UI. The geometry can then be retrieved from the tangent lines using SketchLine.Geometry. Here is a sample code snippet and the screenshot of sketch that it generates.
Dim partDoc As PartDocument = _
TryCast (_invApp.ActiveDocument, PartDocument)
Dim oCompDef As PartComponentDefinition _
= partDoc.ComponentDefinition
Dim oSketch As PlanarSketch = _
oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))
oSketch.Name = "MySketch"
Dim oTG As TransientGeometry = _
_invApp.TransientGeometry
Dim geomConstraints As GeometricConstraints _
= oSketch.GeometricConstraints
Dim points As SketchPoints = oSketch.SketchPoints
Dim skp0 As SketchPoint = points.Add( _
oTG.CreatePoint2d(0, 0), False )
Dim skp1 As SketchPoint = points.Add( _
oTG.CreatePoint2d(10, 0), False )
Dim oCenLine As SketchLine = _
oSketch.SketchLines.AddByTwoPoints(skp0, skp1)
oCenLine.Construction = True
geomConstraints.AddHorizontal(oCenLine)
Dim oCircle1 As SketchCircle = _
oSketch.SketchCircles.AddByCenterRadius( _
oCenLine.StartSketchPoint, 4)
Dim oCircle2 As SketchCircle = _
oSketch.SketchCircles.AddByCenterRadius( _
oCenLine.EndSketchPoint, 2)
geomConstraints.AddGround(oCircle1.CenterSketchPoint)
geomConstraints.AddGround(oCircle2.CenterSketchPoint)
Dim skp2 As SketchPoint = _
points.Add(oTG.CreatePoint2d(0, 4), False )
Dim skp3 As SketchPoint = _
points.Add(oTG.CreatePoint2d(10, 2), False )
Dim oTanLine1 As SketchLine = _
oSketch.SketchLines.AddByTwoPoints(skp2, skp3)
Dim skp4 As SketchPoint = points.Add( _
oTG.CreatePoint2d(0, -4), False )
Dim skp5 As SketchPoint = points.Add( _
oTG.CreatePoint2d(10, -2), False )
Dim oTanLine2 As SketchLine = _
oSketch.SketchLines.AddByTwoPoints(skp4, skp5)
geomConstraints.AddTangent(oCircle1, oTanLine1)
geomConstraints.AddTangent(oCircle2, oTanLine1)
geomConstraints.AddTangent(oCircle1, oTanLine2)
geomConstraints.AddTangent(oCircle2, oTanLine2)
geomConstraints.AddCoincident( _
oTanLine1.StartSketchPoint, oCircle1)
geomConstraints.AddCoincident( _
oTanLine1.EndSketchPoint, oCircle2)
geomConstraints.AddCoincident( _
oTanLine2.StartSketchPoint, oCircle1)
geomConstraints.AddCoincident( _
oTanLine2.EndSketchPoint, oCircle2)
Dim oTanLine1Geom As LineSegment2d _
= oTanLine1.Geometry
Dim oTanLine2Geom As LineSegment2d _
= oTanLine2.Geometry
Dim sp1 As Point2d = oTanLine1Geom.StartPoint
Dim ep1 As Point2d = oTanLine1Geom.EndPoint
MessageBox.Show(String .Format( _
"Tangent 1 SP : {0} {1} EP : {2} {3}" , _
sp1.X, sp1.Y, ep1.X, ep1.Y))