How to place SketchPoint to the inside of the linear edge (element of EdgeLoop)

How to place SketchPoint to the inside of the linear edge (element of EdgeLoop)

Maxim-CADman77
Advisor Advisor
290 Views
4 Replies
Message 1 of 5

How to place SketchPoint to the inside of the linear edge (element of EdgeLoop)

Maxim-CADman77
Advisor
Advisor

I need help with placing sketch point to the INSIDE of the linear edge (element of EdgeLoop) no matter to be inside the EdgeLoop.

Here is screenshot of the sample-loop of top face of the attached IPT

MaximCADman77_0-1736621557487.png

 

Here is my attempt (iLogic) that places the point at 5mm of perpendicular from the middle of the only linear edge of the sketch:

 

 

 

 

Dim ptDoc As PartDocument = ThisDoc.Document
Dim ptDef As PartComponentDefinition = ptDoc.ComponentDefinition

Dim sk As PlanarSketch = ptDef.Sketches(1)

Dim linSkLine As SketchLine = sk.SketchLines(1)
' Logger.Info(If(linSkLine Is Nothing, "-", "+"))
' PtDoc.SelectSet.Select(linSkLine)

Dim body As SurfaceBody = ptDef.SurfaceBodies(1)
Dim topFace As Face = body.Faces(4)
Dim outerEdgeLoop As EdgeLoop = TopFace.EdgeLoops(1)
Dim linEdge As Edge = outerEdgeLoop.Edges(1)
' PtDoc.SelectSet.Select(linEdge)
sk.Edit
	Dim pnt2D As point2D = ThisApplication.TransientGeometry.CreatePoint2d(0, -0.6)
	Dim newSkPnt As SketchPoint = sk.SketchPoints.Add(pnt2D, True)
	Dim auxSkLine As SketchLine = sk.SketchLines.AddByTwoPoints(newSkPnt, linSkLine.Geometry.MidPoint)
	sk.GeometricConstraints.AddMidpoint(auxSkLine.EndSketchPoint, linSkLine)
	sk.GeometricConstraints.AddPerpendicular(linSkLine, auxSkLine)
	Dim offsetDim As OffsetDimConstraint = sk.DimensionConstraints.AddOffset(linSkLine, auxSkLine.StartSketchPoint, auxSkLine.Geometry.MidPoint, False)
	offsetDim.Parameter.Value = 0.5
sk.ExitEdit

 

 

 

 

I know the code is a bit clumsy but this is just a sample.

 

Unfortunately it does not respect the need for the INSIDE direction (the result is highlighted with red).

MaximCADman77_1-1736621632718.png

I want it always be at the "material side".

 

Any ideas are highly appreciated.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
291 Views
4 Replies
Replies (4)
Message 2 of 5

Maxim-CADman77
Advisor
Advisor
Accepted solution

Found the answer (need to use EdgeUse) in Get Edge Direction (Manufacturing Dev Blog).

Please vote for Inventor-Idea Text Search within Option Names

Message 3 of 5

lmc.engineering
Advocate
Advocate

Hi Maxim,

 

I've done this before by first creating a point very slightly perpendicularly offset from the edge in question, then testing if that point is on the face. If it is, I apply my desired offset in the default direction, if it is not on the face, I apply an offset in the opposite direction. This can be iterative if desired, but best to make use of points and vectors in place of sketchlines and sketchpoints. To test the point is on the face:

Dim oFace As Face = yourFace
Dim oPoint As Point = ThisApplication.TransientGeometry.CreatePoint(X, Y, Z)
Dim tol as double = 0.001 If oface.GetClosestPointTo(oPoint).IsEqualTo(oPoint, tol) Then 'Point is on the face, therefore direction OK. Else 'Point is not on the face, therefore reverse the direction End If

Happy to assist further if you need more code.

 

Regards

0 Likes
Message 4 of 5

Maxim-CADman77
Advisor
Advisor

@lmc.engineering 
Could you clarify what do you mean by "I apply an offset in the opposite direction"?
AFAIK offset value can't be negative.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 5 of 5

lmc.engineering
Advocate
Advocate

I realised we aren't quite on the same page, as I overlooked the use of constraints. 

My code wasn't an exact match to what you need, however, I have managed to fumble this together:

Sub Main()
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
Dim ptDoc As PartDocument = ThisApplication.ActiveDocument
Dim ptDef As PartComponentDefinition = ptDoc.ComponentDefinition

Dim sk As PlanarSketch = ptDef.Sketches(1)
Dim linSkLine As SketchLine = sk.SketchLines(1)
Dim body As SurfaceBody = ptDef.SurfaceBodies(1)

'get the face
Dim topFace As Face = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select the face")
If topFace Is Nothing Then Exit Sub

'get mid point of sketchline
Dim midP As Point2d = linSkLine.Geometry.MidPoint

'create a vector of the lineLine
Dim linVect As New VectorXY(New PointXY(linSkLine.Geometry.StartPoint.X, linSkLine.Geometry.StartPoint.Y),
New PointXY(linSkLine.Geometry.EndPoint.X, linSkLine.Geometry.EndPoint.Y))

'create a perpendicular vector
Dim perpVect As VectorXY = linVect.CreatePerpendicularVectorFromPoint(linVect.MidPoint, 0.01)

'create a sketchpoint on the end of the vector
Dim testPoint As SketchPoint = sk.SketchPoints.Add(tg.CreatePoint2d(perpVect.EndPoint.X, perpVect.EndPoint.Y))

'create a workpoint so we can get the true x,y,z coordinates of the point in respect to UCS
Dim testWP As WorkPoint = ptDef.WorkPoints.AddByPoint(testPoint)
testPoint.Delete()

'create our new point to test if this is on the face
Dim newPoint As Point = tg.CreatePoint(testWP.Point.X, testWP.Point.Y, testWP.Point.Z)

Dim offset As Double = 0.0
If PointIsOnFace(topFace, newPoint) Then
	offset = 0.5
	'MsgBox("Is on face")
Else
	offset = -0.5
	'MsgBox("Is not on face")
End If

'delete the workpoint
testWP.Delete()

'create the new perp vector to place our sketchpoint:
Dim newperpVect As VectorXY = linVect.CreatePerpendicularVectorFromPoint(linVect.MidPoint, offset)
'create a sketchpoint on the end of the vector
Dim finalskPoint As SketchPoint = sk.SketchPoints.Add(tg.CreatePoint2d(newperpVect.EndPoint.X, newperpVect.EndPoint.Y))
End Sub

Function PointIsOnFace(f As Face, oPoint As Point) As Boolean
	If f.GetClosestPointTo(oPoint).IsEqualTo(oPoint, 0.001) Then
		'"Point is on face"
		Return True
	Else
		'"Point is not on face"
		Return False
	End If
End Function

Public Class PointXY
	Public Property X As Double
	Public Property Y As Double
	Public Sub New(x As Double, y As Double)
		Me.X = x
		Me.Y = y
	End Sub
End Class

Public Class VectorXY
	Public Property StartPoint As PointXY
	Public Property EndPoint As PointXY
	Public Sub New(StartPoint As PointXY, EndPoint As PointXY)
		Me.StartPoint = StartPoint
		Me.EndPoint = EndPoint
	End Sub

	Public Function DX() As Double
		Return EndPoint.X - StartPoint.X
	End Function

	Public Function DY() As Double
		Return EndPoint.Y - StartPoint.Y
	End Function

	Public Function Length() As Double
		Return Math.Sqrt(DX() * DX() + DY() * DY())
	End Function

	Public Function Normalize() As VectorXY
		Return New VectorXY(New PointXY(0, 0), New PointXY(DX() / Length(), DY() / Length()))
	End Function

	Public Shared Function MovePointAlongVector(ByVal p As PointXY, ByVal v As VectorXY, ByVal distance As Double) As PointXY
		Dim normalizedVector As VectorXY = v.Normalize()
		Dim newPoint As PointXY
		newPoint.X = Math.Round(p.X + normalizedVector.DX() * distance, 6)
		newPoint.Y = Math.Round(p.Y + normalizedVector.DY() * distance, 6)
		Return newPoint
	End Function

	Public Function MidPoint() As PointXY
		Return New PointXY((StartPoint.X + EndPoint.X) / 2, (StartPoint.Y + EndPoint.Y) / 2)
	End Function
	Public Function CreatePerpendicularVectorFromPoint(refpoint As PointXY, length As Double) As VectorXY
		Dim dx As Double = EndPoint.X - StartPoint.X
		Dim dy As Double = EndPoint.Y - StartPoint.Y

		' Calculate the length of the vector
		Dim mag As Double = Math.Sqrt(dx * dx + dy * dy)

		' Normalize the vector to a unit vector
		dx /= mag
		dy /= mag

		' Create the perpendicular vector (-dy, dx) or (dy, -dx)
		Dim newpoint As New PointXY(refpoint.X - dy * length, refpoint.Y + dx * length)
		Return New VectorXY(refpoint, newpoint)
	End Function
End Class



0 Likes