Message 1 of 4
How to determine direction to place sketch entity to fall within solid body.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to put a groove on a pipe by selecting either end face. The problem arises in knowing which direction to send the rectangle to only cut within the tube. Any one know how to go about positioning the sketch within the range box of the solid body?
Sub Main
' Create a new part document, using the default part template.
Dim partFace As Face = ThisApplication.CommandManager.Pick _
(SelectionFilterEnum.kPartFaceFilter, "Select a face")
Dim partDoc As PartDocument = ThisDoc.Document
Dim compDef As PartComponentDefinition = partDoc.ComponentDefinition
Dim sketch As PlanarSketch = compDef.Sketches.Add(compDef.WorkPlanes(3))
sketch.Edit
Dim transGeom As TransientGeometry = ThisApplication.TransientGeometry
Dim line1 As SketchLine = sketch.AddByProjectingEntity(partFace.Edges(2))
Dim sketchPoint As SketchPoint = line1.StartSketchPoint
Dim recCenterpt As Point2d
Dim cornerEdge As Point2d
Dim centerDistX As Double = 3 ' 3 =30mm from edge
Dim edgeDistX As Double = centerDistX + 0.3 '0.3 = 6mm wide' center to edge distance. Double this distance for width
Dim centerDistY As Double = 0.1 ' center to edge distance.
Dim edgeDistY As Double = centerDistY+0.1
recCenterpt = transGeom.CreatePoint2d(sketchPoint.Geometry.X + centerDistX,sketchPoint.Geometry.Y - centerDistY)'/10 for cm, gets center of groove
cornerEdge = transGeom.CreatePoint2d(sketchPoint.Geometry.X + edgeDistX,sketchPoint.Geometry.Y - edgeDistY)
Dim recCenterSkPt As sketchPoint = sketch.SketchPoints.Add(recCenterpt, False)
Dim rectangleLines As SketchEntitiesEnumerator = sketch.SketchLines.AddAsTwoPointCenteredRectangle(recCenterSkPt ,cornerEdge)
Dim recCornerPoint As sketchPoint = rectangleLines(1).StartSketchPoint
sketch.GeometricConstraints.AddHorizontalAlign(recCornerPoint,sketchPoint)
CreateLengthConstraint (rectangleLines(1))
CreateLengthConstraint(rectangleLines(2))
Dim textPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d((recCenterSkPt.Geometry.X + sketchPoint.Geometry.X) / 2, (recCenterSkPt.Geometry.Y + sketchPoint.Geometry.Y) / 2)
sketch.DimensionConstraints.AddOffset(line1,recCenterSkPt,textPoint,False)
Dim profile As Profile = sketch.Profiles.AddForSolid()
Dim revolveFeat As RevolveFeature = compDef.Features.RevolveFeatures.AddFull(profile, compDef.WorkAxes("X Axis"), PartFeatureOperationEnum.kCutOperation)
End Sub
Sub CreateLengthConstraint(line As SketchLine)
'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/to-constraint-a-rectangle-from-centerpoint/td-p/8982929
'https://forums.autodesk.com/t5/inventor-ilogic-api-vba-forum/adding-dimension-constraints-to-a-sketch/td-p/8406914
Dim point1 As SketchPoint
Dim point2 As SketchPoint
Dim textPoint As Point2d
point1 = line.Constraints(1).EntityTwo
point2 = line.Constraints(2).EntityTwo
textPoint = ThisApplication.TransientGeometry.CreatePoint2d((point1.Geometry.X + point2.Geometry.X) / 2, (point1.Geometry.Y + point2.Geometry.Y) / 2)
Call line.Parent.DimensionConstraints.AddTwoPointDistance(point1, point2, kAlignedDim, textPoint)
End Sub
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan
Or if this helped you, please, click (like)
Regards
Alan