Textbox Prompt Emtry Formatted Text

Textbox Prompt Emtry Formatted Text

Anonymous
Not applicable
3,000 Views
8 Replies
Message 1 of 9

Textbox Prompt Emtry Formatted Text

Anonymous
Not applicable

I would like to change the style (strikethrough) of a prompted entry text box.

 

I tried using the following code but it doesn't work:

 

strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='False'><Prompt")
strFormattedText = Replace(strFormattedText, "</Prompt>", "</Prompt></StyleOverride>")
dctPromptedEntries.Item("SQUARE").FormattedText = strFormattedText

 

 

I tried getting the formatted text of the textbox however only the prompt property is being returned.

 

What is the correct way in setting the style of a prompted entry textbox?

0 Likes
Accepted solutions (1)
3,001 Views
8 Replies
Replies (8)
Message 2 of 9

Rob67ert
Collaborator
Collaborator

Hi,

I have been playing with it to.

This is my solution:

SyntaxEditor Code Snippet

    TempPartNo = "<StyleOverride Font='ISOCP_IV25' FontSize='0.5' Bold='False' Strikethrough='True'>" & TempPartNo & "</StyleOverride>"
    oSK.TextBoxes.Item(1).FormattedText = TempPartNo

 Hope it will help you.

Robert

If you find this reply helpful ? It would be nice if you use the Accept as Solution or Kudos button below.
0 Likes
Message 3 of 9

MechMachineMan
Advisor
Advisor

1) With how your code starts, we don't know what collection you are actually pulling this info from to be able to help you with any little nuances it may be. I'm ASSUMING that dctPromptedEntries is a collection of TextBoxes which may or may not include prompted entry text.

 

2) You are missing a closing ">"

 

3) Have you tried checking what the outputs of each line are to ensure that nothing is going wrong?

 

ie;

 

strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
MsgBox("Line1: " & strFormattedText)

strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='False'><Prompt")

MsgBox("Line2: " & strFormattedText)

strFormattedText = Replace(strFormattedText, "</Prompt>", "</Prompt></StyleOverride>")

MsgBox("Line3: " & strFormattedText)
dctPromptedEntries.Item("SQUARE").FormattedText = strFormattedText

MsgBox("Line4: " & dctPromptedEntries.Item("SQUARE").FormattedText)

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 9

Anonymous
Not applicable

Hi,

 

Sorry for the late reply. I just came back with this issue.

 

1. Yes, you're correct. dctPromptedEntries is a collection of prompted entry textbox.

2. I'm not sure of what line you are referring for missing ">".

3. I already tried that code to check the returned string but nothing's wrong.

 

I tried getting the formatted text of the textbox and set it again to textbox but still it fails. See code below.

 

strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
dctPromptedEntries.Item("SQUARE").FormattedText = strFormattedText

 

I tried a suggestion from other post to turn off the textbox border and remove the constraints but still same error.

0 Likes
Message 5 of 9

wayne.brill
Collaborator
Collaborator

Hi,

 

I would need to research this. Please upload an Inventor Drawing with the TextBox you are trying to change. Also if you could provide a complete (but small) code example that shows the problem that would be helpful.

 

Thanks,

Wayne

 

 



Wayne Brill
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 6 of 9

Anonymous
Not applicable

Hi wayne,

 

See code below and attached file for the Inventor drawing.

 

 

oTitleBlockED = m_InventorApp.ActiveDocument.ActiveSheet.TitleBlock

dctPromptedEntries = GetPrompEntries()

If UCase(strTubePattern) = "TRIANGULAR" Then
	setTextBoxValues(dctPromptedEntries.Item("TRIANGULAR"), "TRIANGULAR")
	strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
	strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='False'><Prompt")
	strFormattedText = Replace(strFormattedText, "</Prompt>", "</Prompt></StyleOverride>")
	dctPromptedEntries.Item("TRIANGULAR").FormattedText = strFormattedText
ElseIf UCase(strTubePattern) = "SQUARE" Then
	setTextBoxValues(dctPromptedEntries.Item("SQUARE"), "SQUARE")
	strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
	strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='False'><Prompt")
	strFormattedText = Replace(strFormattedText, "</Prompt>", "</Prompt></StyleOverride>")
	dctPromptedEntries.Item("SQUARE").FormattedText = strFormattedText
End If


Private Function GetPrompEntries() As Dictionary(Of String, TextBox)
	Dim otextboxes As TextBoxes
	Dim oTextBox As TextBox

	Dim dctPromptEntries As New Dictionary(Of String, TextBox)

	Dim oActiveDocument As DrawingDocument
	oActiveDocument = m_InventorApp.ActiveDocument

	Dim oTitleBlock As TitleBlock
	oTitleBlock = oActiveDocument.ActiveSheet.TitleBlock

	Dim strValue As String

	If Not oTitleBlock Is Nothing Then

		otextboxes = oTitleBlock.Definition.Sketch.TextBoxes

		For Each oTextBox In otextboxes
			strValue = Trim(oTextBox.Text)

			If InStr(UCase(oTextBox.FormattedText), "</PROMPT>") <> 0 Then
				If Not dctPromptEntries.ContainsKey(strValue) Then
					dctPromptEntries.Add(strValue, oTextBox)
				End If
			ElseIf UCase(strValue) = "ELLIP" Or UCase(strValue) = "FLAT" Or UCase(strValue) = "DISH" _
				Or UCase(strValue) = "CONIC" Or UCase(strValue) = "HEMISPH" Then
				If Not dctPromptEntries.ContainsKey(strValue) Then
					dctPromptEntries.Add(strValue, oTextBox)
				End If
			End If
		Next
	End If

	Return dctPromptEntries
End Function

	
Public Sub setTextBoxValues(ByVal oTextbox As TextBox, strValue As String)
        oTitleBlockED.SetPromptResultText(oTextbox, strValue)
End Sub

 

 

Hope you can help us on this.

0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi wayne,

 

See attached file for the Inventor drawing.

 

Thank you.

0 Likes
Message 8 of 9

wayne.brill
Collaborator
Collaborator
Accepted solution

Hi,

 

I find that the Edit method of the TitleBlockDefinition needs to be called and the TextBox needs to come from the DrawingSketch that is being edited.

 

Here is an update to your code. This is from a .NET forms application. The logic for getting the correct TextBox may need to be improved but the code does show that changing the FormattedText property of a TextBox in a TitleBlockDefinition can work.

 

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'WB added
        Dim m_InventorApp As Inventor.Application = Nothing '= AddinGlobal.InventorApp '<- this gives me the Application 
        Try
            m_InventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ex As Exception
        End Try

        Dim oTitleBlockED As TitleBlock
        oTitleBlockED = m_InventorApp.ActiveDocument.ActiveSheet.TitleBlock

        Dim dctPromptedEntries As Dictionary(Of String, TextBox)
        dctPromptedEntries = GetPrompEntries(m_InventorApp)

        ' Dim strTubePattern As String = "Triangular"
        Dim strTubePattern As String = "Square"
        Dim strFormattedText As String

        If UCase(strTubePattern) = "TRIANGULAR" Then
            setTextBoxValues(dctPromptedEntries.Item("TRIANGULAR"), "TRIANGULAR", oTitleBlockED)
            strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
            strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='False'><Prompt")
            strFormattedText = Replace(strFormattedText, "</Prompt>", "</Prompt></StyleOverride>")
            dctPromptedEntries.Item("TRIANGULAR").FormattedText = strFormattedText

        ElseIf UCase(strTubePattern) = "SQUARE" Then
            setTextBoxValues(dctPromptedEntries.Item("SQUARE"), "SQUARE", oTitleBlockED)
            strFormattedText = dctPromptedEntries.Item("SQUARE").FormattedText
            ' strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='False'><Prompt")
            'WB added - wanted to see the strike through in the text (worked ok)
            strFormattedText = Replace(strFormattedText, "<Prompt", "<StyleOverride Strikethrough='True'><Prompt")
            strFormattedText = Replace(strFormattedText, "</Prompt>", "</Prompt></StyleOverride>")
            'WB added 
            Dim oTitleBlockDef As TitleBlockDefinition
            oTitleBlockDef = m_InventorApp.ActiveDocument.TitleBlockDefinitions("Heat Exchanger")
            Dim oSketch As DrawingSketch = Nothing
            'Edit the TitleBlockDefinition, passing in a DrawingSketch that will be instantiated
            Call oTitleBlockDef.Edit(oSketch)

            Dim oTextBox As TextBox
            'WB commented
            ' oTextBox = dctPromptedEntries.Item("SQUARE")
            'WB added for each 
            'Go through the TextBoxes in in the Sketch being edited
            For Each oTextBox In oSketch.TextBoxes
                'Debug.Print(oTextBox.Text)
                If oTextBox.Text.Contains("SQUARE") Then
                    'This works without error for me (TextBox is from DrawingSketch being edited)
                    oTextBox.FormattedText = strFormattedText
                    Exit For
                End If
                'WB commented
                'dctPromptedEntries.Item("SQUARE").FormattedText = strFormattedText
            Next oTextBox

            oTitleBlockDef.ExitEdit(True)

        End If
    End Sub

    Private Function GetPrompEntries(m_InventorApp As Inventor.Application) As Dictionary(Of String, TextBox)
        Dim otextboxes As TextBoxes
        Dim oTextBox As TextBox

        Dim dctPromptEntries As New Dictionary(Of String, TextBox)

        Dim oActiveDocument As DrawingDocument
        oActiveDocument = m_InventorApp.ActiveDocument

        Dim oTitleBlock As TitleBlock
        oTitleBlock = oActiveDocument.ActiveSheet.TitleBlock

        Dim strValue As String

        If Not oTitleBlock Is Nothing Then

            otextboxes = oTitleBlock.Definition.Sketch.TextBoxes

            For Each oTextBox In otextboxes
                strValue = Trim(oTextBox.Text)

                If InStr(UCase(oTextBox.FormattedText), "</PROMPT>") <> 0 Then
                    If Not dctPromptEntries.ContainsKey(strValue) Then
                        dctPromptEntries.Add(strValue, oTextBox)
                    End If
                ElseIf UCase(strValue) = "ELLIP" Or UCase(strValue) = "FLAT" Or UCase(strValue) = "DISH" _
                    Or UCase(strValue) = "CONIC" Or UCase(strValue) = "HEMISPH" Then
                    If Not dctPromptEntries.ContainsKey(strValue) Then
                        dctPromptEntries.Add(strValue, oTextBox)
                    End If
                End If
            Next
        End If

        Return dctPromptEntries
    End Function


    Public Sub setTextBoxValues(ByVal oTextbox As TextBox, strValue As String, oTitleBlockED As TitleBlock)
        oTitleBlockED.SetPromptResultText(oTextbox, strValue)
    End Sub

 

Thanks,

Wayne



Wayne Brill
Developer Technical Services
Autodesk Developer Network

Message 9 of 9

Anonymous
Not applicable

Hi wayne,

 

Thank you very much for reply. It works fine now.

 

 

0 Likes