Revision Table Cell Determine If Text Will Be Single Line

Revision Table Cell Determine If Text Will Be Single Line

Matthew_Policelli
Advocate Advocate
371 Views
2 Replies
Message 1 of 3

Revision Table Cell Determine If Text Will Be Single Line

Matthew_Policelli
Advocate
Advocate

I have an iLogic for automating some operations with the revision table. One of the operations allows the user to add to the current revision if certain conditions are met. The user is prompted for text to add to the revision description with an input box, which then inserts it in to the current revision description cell.

 

I am trying to add a check to this process to see if the text the user wants to add (not including the existing text) will fit on a single line or will wrap. I attempted to use this code to do so:

Dim moreDescText As String
Do
	moreDescText = InputBox("Description text to add:", "Insert additional info to Model Change Rev")

	If System.Windows.Forms.TextRenderer.MeasureText(moreDescText, New System.Drawing.Font("Tahoma", (.05 * 72), System.Drawing.FontStyle.Regular)).Width < 120 Then
	Logger.Info(System.Windows.Forms.TextRenderer.MeasureText(moreDescText, New System.Drawing.Font("Tahoma", (.05 * 72), System.Drawing.FontStyle.Regular)).Width.ToString)
	Exit Do
	Else
	Select Case MessageBox.Show("The new description you are adding will go onto two lines. Do you want to retry?", "Text Wrap Detected", MessageBoxButtons.AbortRetryIgnore)
		Case DialogResult.Ignore
			Exit Do
		Case DialogResult.Abort
			Return
		Case DialogResult.Retry
			'loop
		Case Else
			Logger.Info("what else could there be?")
	End Select
	End If
Loop

 

The 120 value for the string measurement was selected through trial and error, but doesn't always work which is why I'm here 🙂

 

Is there a better way to check for wrapping text, or to determine how many pixels are available in the revision table cell on a single line in the file the rule is being run in?

Accepted solutions (1)
372 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @Matthew_Policelli.  Interesting routine.  I haven't tried that process of checking text length, because our things like PartsList & RevisionTable are modular (not built into the Border or TitleBlock), so that way can move them around or dock them in different places, and length needs to be variable to fit into various situations.  I created a routine to automatically resize our RevisionTable (and one for PartsList too) to fit all text onto one line, to avoid multi-line entries.  Since it is sort of related to this topic, I thought you may find it interesting or useful.  It used to be posted in the knowledge base area, but they took all personal articles down a while back, so we had to save them off locally in order to keep them.  Attached is a PDF of the article which includes some code for the routine.  It is not as fully developed as some may want to go, such as fixing docking position after resize, but it's still pretty nice.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

Matthew_Policelli
Advocate
Advocate
Accepted solution

Thanks 🙂 Unfortunately, our drawing standards are such that we can't really resize the revision table much, and our revision table is at times prohibitively small.

 

I think I did figure out the solution to my issue though. Check it out:

 

Function CheckForTextWrap(ByRef inputText As String, oRevTable As Inventor.RevisionTable) As Nullable(Of Boolean)
		''will return true if the input string will wrap, and false if it will fit on a single line. This function is looped in main sub

		'Prompt for user to add text to description, writing over argument value
		inputText = InputBox("Description text to add:", "Insert additional info to Model Change Rev")

		'convert column width from centimeters to point units
		Dim AvailableRevTableWidth As Double = oRevTable.RevisionTableColumns("Description").Width / 0.03527777
		
		'get font information from rev table style to calculate text measurement
		Dim FontSize As Double = oRevTable.Style.DataTextStyle.FontSize * 28.3465	'convert from centimeters to points for measuretext function
		Dim TblFont As String = oRevTable.Style.DataTextStyle.Font	'get font name

		'measure text function includes a buffer. We need to account for that because otherwise it will say that text will wrap when it's right on the cusp of wrapping.
		Dim buffer_width As Double = System.Windows.Forms.TextRenderer.MeasureText(".", New System.Drawing.Font(TblFont, Convert.ToSingle(FontSize), System.Drawing.FontStyle.Regular)).Width
		
		'get width of input text. Add period to string being measured, then subtract the buffer width above to get the actual string width
		Dim InputTextWidth As Double = System.Windows.Forms.TextRenderer.MeasureText(inputText & ".", New System.Drawing.Font(TblFont, Convert.ToSingle(FontSize), System.Drawing.FontStyle.Regular)).Width - buffer_width

		'Logger.Info(String.Join(vbCr, "Available Width: " & AvailableRevTableWidth, "Input Width: " & InputTextWidth))	'for testing

		If InputTextWidth <= AvailableRevTableWidth Then
			Return False	'single line all is good
		Else	'computed that the input will wrap onto two lines
			Select Case MessageBox.Show("The new description you are adding will go onto two lines. Do you want to retry?", "Text Wrap Detected", MessageBoxButtons.AbortRetryIgnore)
				Case DialogResult.Ignore 
					Return False	'user decided they wanted a single line
				Case DialogResult.Retry
					Return True	'user wants to try again
				Case Else	
					Return Nothing	'dialogresult.abort and anything else will abort the iLogic
			End Select
		End If

	End Function

 

And then this function is called inside a while loop from the main sub like this:

 

Dim moreDescText As String = Nothing

Dim Wrap_Bool As Nullable(Of Boolean) = True	'nullable boolean so we can handle case where user wants to completely abort the process. Starts as true so the while loop will run
While Wrap_Bool
	Wrap_Bool = CheckForTextWrap(moreDescText, oDoc.ActiveSheet.RevisionTables.Item(1))
	If Wrap_Bool Is Nothing Then Return	'abort cancels the operation
End While

 

 

Posting this in case anyone else needs something similar, but also the function code could probably be adapted so that it would resize your revision table without the need for a temporary general note if you so desire 🙂