Sketch Text position (relative to the parent Sheet printable area)

Sketch Text position (relative to the parent Sheet printable area)

Maxim-CADman77
Advisor Advisor
1,033 Views
12 Replies
Message 1 of 13

Sketch Text position (relative to the parent Sheet printable area)

Maxim-CADman77
Advisor
Advisor

I'd like to know is it possible to check wheteher Sketch Text placed on the Drawing fits the printable area of the parent Sheet ?

I tried experimenting with TextBox.RangeBox Min and Max Points but it occured  that TextBox doesn't have direct relation to the Text itself.

I guess values of FittedTextHeight and FittedTextWidth properties need to be used, but I still don't understand how. I believe TextBox.Origin point is a key for the solution but it returns some unexpectedvalues.

Till now I have such iLogic code:

Dim oIDW As DrawingDocument=ThisDoc.Document
Dim oSh As Sheet=oIDW.Sheets(1)
Dim oDS As DrawingSketch=oSh.Sketches(1)
Dim oTB As TextBox=oDS.TextBoxes(1)
Dim MsgBody As String

MsgBody &= "Sheet Height = " & oSh.Height & vbCrLf
MsgBody &= "Sheet Width = " & oSh.Width & vbCrLf
MsgBody &= vbCrLf & "Text Height = " & Round(oTB.FittedTextHeight,1)
MsgBody &= vbCrLf & "Text Width = " & Round(oTB.FittedTextWidth,1) & vbCrLf
MsgBody &= vbCrLf & "TextBox.Origin.X = " & oTB.Origin.X
MsgBody &= vbCrLf & "TextBox.Origin.Y = " & oTB.Origin.Y

MsgBox(MsgBody,,oTB.Text)

PS: The sample Drawing is attached.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Accepted solutions (1)
1,034 Views
12 Replies
Replies (12)
Message 2 of 13

JhoelForshav
Mentor
Mentor

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 🙂

0 Likes
Message 3 of 13

Maxim-CADman77
Advisor
Advisor

But "Fit" option is grayed-out in the sample IDW:

Fit_Text_Option.png

 

Doesn't it actual for 3Dmodel's sketches only?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 4 of 13

JhoelForshav
Mentor
Mentor

I actually don't know how to go from non fitted to fitted...

The easiest way seems to be to create a new textbox.

After some more testing i saw that the rangebox isn't very reliable in this method if the text is rotated... Maybe the entire rangebox gets returned upside down or something 🤔

 

I'll have a look at it tomorrow. It's getting very late here in sweden now.

 

EDIT: It's actually oshX anf oshY that are wrong. The point at (0;0) is not exactly the bottom left corner of the sheet.

This complicates things because now I don't know how to get the extents of the sheet correctly since we only have the sheet height and width to work with...

0 Likes
Message 5 of 13

Maxim-CADman77
Advisor
Advisor

Invert (multiply to -1) Y ?

 

PS:  I still knew less then you ...

You don't know how to convert  non-fitted to fitted ...

...but I even don't know how to create fitted TextBox from scratch 😉

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 6 of 13

JhoelForshav
Mentor
Mentor

@Maxim-CADman77 

These textboxes are so frustrating... The only way I know of how to create a fitted textbox is to just click (not drag out a box) when using the text command in the sketch 🙂

 

Also, as I mentioned in the "EDIT" part of my last reply. It seems the points are actually correct with regards to the textbox. It's the actual sheet boundaries that is a bit off

 

0 Likes
Message 7 of 13

JhoelForshav
Mentor
Mentor

Sorry, I was wrong. (0, 0) is the bottom left corner

The problem is that the fitted texbox isn't that fitted...

 

fittedText.PNG

 

0 Likes
Message 8 of 13

Maxim-CADman77
Advisor
Advisor

That minor misfiting (I believe due to italic) seems not critical for me.

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 9 of 13

Maxim-CADman77
Advisor
Advisor

Just FYI

Seems like I finally managed to achieve my goal

 

SketchToSheetSpace method should be used for solving such tasks.

 

I ended up with something like:

 

Function WithinSheetBorder (ByRef oDS As DrawingSketch) As Boolean

Dim oTG As TransientGeometry=ThisApplication.TransientGeometry
Dim oSh As Sheet=oDS.Parent

''' Initial Sketch RangeBox Coordinates
Dim SkMinX As Double=oSh.Width/2
Dim SkMinY As Double=oSh.Height/2
Dim SkMaxX As Double=oSh.Width/2
Dim SkMaxY As Double=oSh.Height/2

For Each oTB In oDS.TextBoxes

	Dim PntMin As Point2d=oDS.SketchToSheetSpace(oTG.CreatePoint2d(oTB.RangeBox.MinPoint.X,oTB.RangeBox.MinPoint.Y))
	If PntMin.X<SkMinX Then SkMinX=PntMin.X 
	If PntMin.X>SkMaxX Then SkMaxX=PntMin.X
	If PntMin.Y<SkMinY Then SkMinY=PntMin.Y
	If PntMin.Y>SkMaxY Then SkMaxY=PntMin.Y

	Dim PntMax As Point2d=oDS.SketchToSheetSpace(oTG.CreatePoint2d(oTB.RangeBox.MaxPoint.X,oTB.RangeBox.MaxPoint.Y))
	If PntMax.X<SkMinX Then SkMinX=PntMax.X 
	If PntMax.X>SkMaxX Then SkMaxX=PntMax.X
	If PntMax.Y<SkMinY Then SkMinY=PntMax.Y
	If PntMax.Y>SkMaxY Then SkMaxY=PntMax.Y

	If SkMinX<0 Or SkMinY<0 Or SkMaxX>oSh.Width Or SkMaxY>oSh.Height Then Return False

Next

Return True

End Function

 

 

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 10 of 13

Maxim-CADman77
Advisor
Advisor

Yet, one thing remains uncovered:

TextBox sometimes bigger than the text itself.

In such cases  my check will return pseudo-Fail (means there would be no real problems with printing such drawing).

TextBox_Gap.png

It's not a big deal to drag TexBox border closer to text but I'd rather prefer my check be smarter...

Wonder if it possible?

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 11 of 13

JhoelForshav
Mentor
Mentor

Hi @Maxim-CADman77 

I couldn't find a way to handle this. That's why I suggested that you always make sure the textbox is fitted 🙂

0 Likes
Message 12 of 13

Maxim-CADman77
Advisor
Advisor

It's impossible.
I'm not the man who creates those drawings.

I'm cad manager who developes the on-the-go checking system that is supposed to warn InvDoc authors about possible problems (automatically on open and after save, or by pressing special "check" button).

Please vote for Inventor-Idea Text Search within Option Names

0 Likes
Message 13 of 13

marcin_otręba
Advisor
Advisor
Accepted solution

use:

 

For Each otb In oDS.TextBoxes
If otb.Fitted = False Then
otb.Height = otb.FittedTextHeight
otb.Width = otb.FittedTextWidth
End If
Next

Hi, maybe you want to check my apps:


DrawingTools   View&ColoringTools   MRUFolders