1

I have a Problem with my Userform. It should automatically Switch to another TextBox when an selection in the catpart made. I get the Automation Error: It is illegal to call out while inside message filter. Run-time error '-2147418107 (80010005)

img

Sub Auswahl_Click()
    Dim sel As Object, Objekt As Object, ObjektTyp(0)
    Dim b, Auswahl, i As Integer
    ObjektTyp(0) = "Body"
    Set sel = CATIA.ActiveDocument.Selection
    For i = 1 To 6
        sel.Clear
        UserFormNow.Controls("Textbox" & i).SetFocus
        Auswahl = sel.SelectElement2(ObjektTyp, "Wähle ein Body aus...", False)
        Set b = CATIA.ActiveDocument.Selection.Item(i)
        If Auswahl = "Normal" Then
            Set Objekt = sel.Item(i)
            UserFormNow.ActiveControl = Objekt.Value.Name
            sel.Clear
        End If
        i = i + 1
    Next
    sel.Clear
End Sub

' EXCEL DATEI ÖFFNEN____________________________________
Sub Durchsuchen1_Click()
    Dim FPath As String
    FPath = CATIA.FileSelectionBox("Select the Excel file you wish to put the value in", "*.xlsx", CatFileSelectionModeOpen)
    If FPath = "" Then

        Else
            DurchsuchenFeld.AddItem FPath
            ListBox1.Clear
            ListBox1.AddItem "Bitte wählen Sie das Panel"
            TextBox1.SetFocus
    End If
End Sub
' FORMULAR SCHLIEßEN____________________________________
Sub ButtonEnd_Click()
    ButtonEnd = True
    Unload UserFormNow
End Sub
ashleedawg
  • 20,365
  • 9
  • 72
  • 105

1 Answers1

0

First you have to know that when you use an UI and still want to interact with CATIA, you have to choices:

  1. Launch the UI in NoModal: mode UserFormNow.Show 0
  2. Hide the UI each time you want to interact with CATIA: Me.Hide or UserFormNow.Hide

Then, I strongly recommend you to avoid looking for items with names:

UserFormNow.Controls("Textbox" & i).SetFocus

If you want to group controls and loop through them, use a Frame and then use a For Each loop.

For Each currentTextBox In MyFrame.Controls
    MsgBox currentTextBox.Text
Next

Regarding your code, many simplifications can be done:

Private Sub Auswahl_Click()

    Dim sel As Object

    Dim currentTextBox As TextBox
    Dim Filter As Variant

    ReDim Filter(0)
    Filter(0) = "Body"

    Set sel = CATIA.ActiveDocument.Selection

    'Loop through each textbox
    For Each currentTextBox In MyFrame.Controls

        sel.Clear

        'Ask for the selection and test the result at the same time
        If sel.SelectElement2(Filter, "Wahle ein Body aus...", False) = "Normal" Then

            'Get the name without saving the object
            currentTextBox.Text = sel.Item2(1).Value.Name

        Else
            'allow the user to exit all the process if press Escape
            Exit Sub
        End If

    Next

    sel.Clear

End Sub
P.Manthe
  • 960
  • 1
  • 5
  • 12