The code below aligns the middle point of a sketch line with the center point of the sketch.
Sub AlignPoints() ' assume we have got Inventor application Dim oDocDef As PartComponentDefinition = _ _InvApplication.ActiveDocument.ComponentDefinition() Dim oSketch As PlanarSketch = _ oDocDef.Sketches(1) Dim oSketchLine As SketchLine = _ _InvApplication.ActiveDocument.SelectSet(1) 'get center workpoint Dim oCenterWorkPt As WorkPoint = _ oDocDef.WorkPoints("Center Point") 'create the center point on sketch Dim oCenterPt As SketchPoint = _ oSketch.SketchPoints.Add( _ oSketch.ModelToSketchSpace (oCenterWorkPt.Point)) 'create the mid point of the line Dim oMidPt As SketchPoint = _ oSketch.SketchPoints.Add( _ oSketchLine.Geometry.MidPoint) 'fix the center point oSketch.GeometricConstraints.AddGround(oCenterPt) 'creates a new midpoint constraint between the point ‘and line oSketch.GeometricConstraints.AddMidpoint( oMidPt, oSketchLine) 'constraint the midpoint and center point by HorizontalAlign oSketch.GeometricConstraints.AddHorizontalAlign( oCenterPt, oMidPt) End Sub

Leave a Reply to MucipCancel reply