Hi @Maxim-CADman77
My suggestion to you would be to always use fitted textboxes for this purpose. Then you can use the Rangebox.
The key is to transform the points of the textbox from sketch to sheet space.
I've written a rule for you for text in fitted textboxes. Not much to say about that except the box isn't perfectly tight to the text. But good enough for practical use I'd say...
Dim oIDW As DrawingDocument = ThisDoc.Document
Dim oSh As Sheet = oIDW.Sheets(1)
Dim oDS As DrawingSketch = oSh.Sketches(1)
Dim oTB As Inventor.TextBox = oDS.TextBoxes(1)
Dim oshY As Double = oSh.Height
Dim oshX As Double = oSh.Width
Dim otbYmax As Double
Dim otbYmin As Double
Dim otbXmax As Double
Dim otbXmin As Double
If oTB.Fitted
Dim oRangeBox As Box2d = oTB.RangeBox
otbYmax = oDS.SketchToSheetSpace(oRangeBox.MaxPoint).Y
otbYmin = oDS.SketchToSheetSpace(oRangeBox.MinPoint).Y
otbXmax = oDS.SketchToSheetSpace(oRangeBox.MaxPoint).X
otbXmin = oDS.SketchToSheetSpace(oRangeBox.MinPoint).X
If otbYmax <= oshY And otbYmin >= 0 _
And otbXmax <= oshX And otbXmin >= 0
MsgBox("inside")
Else
MsgBox("not inside")
End If
Else
MsgBox("Only for fitted textbox")
End If
If you must use text in non fitted textboxes It'll be a lot of work to code it. You'll have to check for vertical and horizontal alignment, rotation of the box and so on. I wrote this code to give you an Idea.
It only works for a textbox with the alignments and rotation as in your sample file!
Dim oIDW As DrawingDocument = ThisDoc.Document
Dim oSh As Sheet = oIDW.Sheets(1)
Dim oDS As DrawingSketch = oSh.Sketches(1)
Dim oTB As Inventor.TextBox = oDS.TextBoxes(1)
Dim oshY As Double = oSh.Height
Dim oshX As Double = oSh.Width
Dim otbYmax As Double
Dim otbYmin As Double
Dim otbXmax As Double
Dim otbXmin As Double
Select Case oTB.VerticalJustification
Case VerticalTextAlignmentEnum.kAlignTextUpper
Select Case oTB.HorizontalJustification
Case HorizontalTextAlignmentEnum.kAlignTextLeft
If oTB.Rotation = Math.PI
otbYmax = oDS.SketchToSheetSpace(oTB.Origin).Y + oTB.FittedTextHeight
otbYmin = oDS.SketchToSheetSpace(oTB.Origin).Y
otbXmax = oDS.SketchToSheetSpace(oTB.Origin).X
otbXmin = oDS.SketchToSheetSpace(oTB.Origin).X - oTB.FittedTextWidth
Else
MsgBox("Havn't written code for these specific conditions yet...")
Exit Sub
End If
Case Else
MsgBox("Havn't written code for these specific conditions yet...")
End Select
Case Else
MsgBox("Havn't written code for these specific conditions yet...")
Exit Sub
End Select
If otbYmax <= oshY And otbYmin >= 0 _
And otbXmax <= oshX And otbXmin >= 0
MsgBox("inside")
Else
MsgBox("not inside")
End If
If you want to go down this road you have a lot of work ahead of you writing the code for how the text relates to the textbox origin in every possible scenario with regards to text alignments and rotation.
Hope this helps and good luck 🙂