Thank you for taking the time to reply. I have come across a really difficult situation from the last time we were here.
I have managed to add the textbox according to the rule you suggested. but there are some pesky parts that require the textbox to have some sort of feature detection. For example:

in this part We would like to ensure the part number does not go off the edge of the hole which will make the etching useless. And, in next part

We would have to avoid the part number touching the slots. Lastly,

in this, We have to make sure that the part number to be etched does not interfere with the previous etching. The old etching was done using extrude cut feature not the mark feature like I will be using for all the part numbers.
I was thinking maybe we could use edgeloops and edgeuse in some manner. But I have never worked with them nor am I too experienced with ilogic. Any kind of help would be appreciated. I am posting my code below; There are some unnecessary lines that help me visualize. so, feel free to comment them out.
Dim asmDoc As AssemblyDocument = ThisDoc.Document
Dim asmDef As AssemblyComponentDefinition = asmDoc.ComponentDefinition
Dim oTransGeom As TransientGeometry = ThisServer.TransientGeometry
For Each oDoc As Document In asmDoc.AllReferencedDocuments
If oDoc.DocumentType = kPartDocumentObject Then
Dim oPDoc As PartDocument = oDoc
Dim oCompDef As PartComponentDefinition = oPDoc.ComponentDefinition
oDocName = oPDoc.DisplayName
Dim oCompDefSM As SheetMetalComponentDefinition = oPDoc.ComponentDefinition
If oCompDefSM.HasFlatPattern Then
oCompDefSM.FlatPattern.Delete()
End If
oCompDef.Unfold
Dim oFlatPattern As FlatPattern = oCompDefSM.FlatPattern
Dim natural As Boolean
Dim osketch2 As PlanarSketch = oFlatPattern.Sketches.Add(oFlatPattern.TopFace)
If osketch2.NaturalAxisDirection = True Then
natural = True
Else
natural = False
End If
For Each oSketch1 As Sketch In oFlatPattern.Sketches
oSketch1.Delete
Next
Dim oSketch As PlanarSketch = oFlatPattern.Sketches.AddWithOrientation(oFlatPattern.TopFace, oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints.Item(1))
Dim oTextPosition As Point2d
Dim oTextBox As Inventor.TextBox
Dim oBox As Box = oFlatPattern.RangeBox
Dim minPoint As Point = oBox.MinPoint
Dim maxPoint As Point = oBox.MaxPoint
Dim minPointX As Double = minPoint.X
Dim maxPointY As Double = maxPoint.Y
closestpoint = oFlatPattern.TopFace.GetClosestPointTo(minPoint)
xminymax = oTransGeom.CreatePoint(minPoint.X, maxPoint.Y, 0)
closestpoint2 = oFlatPattern.TopFace.GetClosestPointTo(xminymax)
If natural = True Then
oTextPosition = oTransGeom.CreatePoint2d(closestpoint.X + 1, closestpoint.Y + 1)
oTextBox = oSketch.TextBoxes.AddFitted(oTextPosition, "Part Number")
If oBox.Contains(oSketch.SketchToModelSpace(oTextBox.Origin)) Then
' MessageBox.Show("Textbox is Inside the flatpattern")
Else
MessageBox.Show("Textbox is Outside the flatpattern")
oTextPosition = oTransGeom.CreatePoint2d(closestpoint.X, closestpoint.Y)
End If
Else
oTextPosition = oTransGeom.CreatePoint2d(closestpoint2.X + 1, closestpoint2.Y - 1)
oTextBox = oSketch.TextBoxes.AddFitted(oTextPosition, "<Part Number>")
' otextbox.Rotation = 4 * Math.Atan(1)
End If
oTextBox.FormattedText = oPDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
' Helps to visualize the bounding box
'[
minPoint = oBox.MinPoint
maxPoint = oBox.MaxPoint
Dim point1 As Point2d = oTransGeom.CreatePoint2d(minPoint.X, minPoint.Y)
Dim point2 As Point2d = oTransGeom.CreatePoint2d(minPoint.X, maxPoint.Y)
Dim point3 As Point2d = oTransGeom.CreatePoint2d(maxPoint.X, maxPoint.Y)
Dim point4 As Point2d = oTransGeom.CreatePoint2d(maxPoint.X, minPoint.Y)
Dim oLines1 As SketchLine
Dim oLines2 As SketchLine
Dim oLines3 As SketchLine
Dim oLines4 As SketchLine
oLines1 = oSketch.SketchLines.AddByTwoPoints(point1, point2) ' Left vertical line
oLines2 = oSketch.SketchLines.AddByTwoPoints(point2, point3) ' Top horizontal line
oLines3 = oSketch.SketchLines.AddByTwoPoints(point3, point4) ' Right vertical line
oLines4 = oSketch.SketchLines.AddByTwoPoints(point4, point1) ' Bottom horizontal line
]'
End If
End If
Next