How to determine direction to place sketch entity to fall within solid body.

How to determine direction to place sketch entity to fall within solid body.

A.Acheson
Mentor Mentor
327 Views
3 Replies
Message 1 of 4

How to determine direction to place sketch entity to fall within solid body.

A.Acheson
Mentor
Mentor

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?

AAcheson_0-1683422066751.png

AAcheson_1-1683422131773.png

 

 

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
0 Likes
328 Views
3 Replies
Replies (3)
Message 2 of 4

Andrii_Humeniuk
Advisor
Advisor

Hi @A.Acheson . I suggest you measure the distance between two vertical lines (those perpendicular to the pipe) and then measure the distance from your sketch (rectangle) to these lines. So that the distance is not greater than that between the lines. And it doesn't hurt to add a selection of faces to which to bind your sketch. So that the user can choose whether the insert will be at the beginning or at the end of the pipe.

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

Message 3 of 4

WCrihfield
Mentor
Mentor

If your pipe axis is parallel with an origin axis, then you can determine which direction is positive or negative for that specific axis, by comparing that to the Normal of the pipe's end face you are Picking, to see if they are the same direction or not.  If they are the same direction, then you know that the picked face is pointing in the positive direction, and know to use negative numbers to position the rectangle rearward from that face, to be along the pipe, instead of out in front of it.  This means more code, but once the code is done and working, code length doesn't matter much anymore.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 4

A.Acheson
Mentor
Mentor

Thanks @WCrihfield and @Andrii_Humeniuk  I will give those recommendations a shot and see how I go. I do know that one end will have the origin and one won't so the extrusion should be in one direction or another based on the origin. Assuming I'm using consistently modeled parts from the content center. 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes