Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

vb.net Message box with scrollbars

1 REPLY 1
SOLVED
Reply
Message 1 of 2
snappyjazz
1727 Views, 1 Reply

vb.net Message box with scrollbars

Hello. Newbie here. Using Inventor Pro 2019 with Visual Studio 2017. My script reads the content center child node levels and puts them in a LONG string; which is printed to a message box. Unfortunately because of the length of the string and no scroll bars, I can't see the bottom of the list. So I would like to pass the string to a secondary form that has a text box with scroll bars. I do not have enough experience with .net to get code snippets from the internet to work.  Do you know how to do this?

 

Module code:

Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor

Module Module1

    Sub Main()

        Dim invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Dim invDoc As Inventor.Document = invApp.ActiveDocument

        'this gets all of the child nodes in the content center and puts them in a string list
        For Each Node1 As ContentTreeViewNode In TopNode.ChildNodes
            StrCCList &= Node1.DisplayName & vbNewLine

            For Each Node2 As ContentTreeViewNode In TopNode.ChildNodes.Item(Node1.DisplayName).ChildNodes
                StrCCList &= "   " & "   " & Node2.DisplayName & vbNewLine

                For Each Node3 As ContentTreeViewNode In TopNode.ChildNodes.Item(Node1.DisplayName).ChildNodes.Item(Node2.DisplayName).ChildNodes
                    StrCCList &= "   " & "   " & "   " & "   " & Node3.DisplayName & vbNewLine

                    For Each Node4 As ContentTreeViewNode In TopNode.ChildNodes.Item(Node1.DisplayName).ChildNodes.Item(Node2.DisplayName).ChildNodes.Item(Node3.DisplayName).ChildNodes
                        StrCCList &= "   " & "   " & "   " & "   " & "   " & "   " & Node4.DisplayName & vbNewLine
                    Next
                Next
            Next
        Next

        'reads the string list of the content center nodes
        'MsgBox(StrCCList)

        Dim FamResults As New FamResults(StrCCList)
        'FamResults.Activate()
        'FamResults.Show()
        'FamResults.TextBox1.Text = StrCCList
    End Sub
End Module

Secondary form code:

Public Class FamResults

    Public Sub New(ByVal PropSetString)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.



    End Sub


    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged



        'Dim TextOutput As String = sender
        'Dim TextOutput As String = "Family Results popup dialog"
        'MsgBox(TextOutput)
        'TextBox1.Text = TextOutput

    End Sub

    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click

        Me.Close()

    End Sub
End Class
1 REPLY 1
Message 2 of 2
snappyjazz
in reply to: snappyjazz

I figured it out. In the section of code below is where I went wrong.

 

        Dim FamResults As New FamResults(StrCCList)
        FamResults.Activate()
        FamResults.Show()
        FamResults.TextBox1.Text = StrCCList
  • First of all, I/you don't need the ".Activate()".

 

  • Secondly, ".Show" is a modeless call to show a form. In this case, the main script is running simultaneously to the code in the form(FamResults). The result is the main script finishes and closes the program before the form has a chance to appear.
  • The fix is to use ".ShowDialog()" which opens the form as modal. Which will pause the main script while the form is open. Upon closing the form then the main script will finish/close.
  • Third of all "FamResults.TextBox1.Text = StrCCList" needs to be moved above the ".ShowDialog()"

The result is that the script gets all of the levels of the content center and puts them in a string (a long string). This string is then put in the text box of a form with scroll bars, so you can scroll down and see the whole hierarchy.

 

Final Code:

Imports System
Imports System.Type
Imports System.Activator
Imports System.Runtime.InteropServices
Imports Inventor

Module Module1



    Sub Main()

        Dim invApp As Inventor.Application = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Dim invDoc As Inventor.Document = invApp.ActiveDocument
        Dim ConCen As ContentCenter = invApp.ContentCenter
        Dim TopNode As ContentTreeViewNode = invApp.ContentCenter.TreeViewTopNode
        Dim StrCCList As String = "   " & "   " & "   " & "   " & "   " & "Content Center Breakdown" & vbNewLine


        'this gets all of the child nodes in the content center and puts them in a string list
        For Each Node1 As ContentTreeViewNode In TopNode.ChildNodes
            StrCCList &= Node1.DisplayName & vbNewLine
            For Each Node2 As ContentTreeViewNode In TopNode.ChildNodes.Item(Node1.DisplayName).ChildNodes
                StrCCList &= "   " & "   " & Node2.DisplayName & vbNewLine
                For Each Node3 As ContentTreeViewNode In TopNode.ChildNodes.Item(Node1.DisplayName).ChildNodes.Item(Node2.DisplayName).ChildNodes
                    StrCCList &= "   " & "   " & "   " & "   " & Node3.DisplayName & vbNewLine
                    For Each Node4 As ContentTreeViewNode In TopNode.ChildNodes.Item(Node1.DisplayName).ChildNodes.Item(Node2.DisplayName).ChildNodes.Item(Node3.DisplayName).ChildNodes
                        StrCCList &= "   " & "   " & "   " & "   " & "   " & "   " & Node4.DisplayName & vbNewLine
                    Next
                Next

            Next

        Next


        'reads the string list of the content center nodes
        Dim FamRes As New FamResults(StrCCList)
        FamRes.TextBox1.Text = StrCCList
        FamRes.ShowDialog()

    End Sub

End Module
Public Class FamResults

    Public Sub New(ByVal PropSetString)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.


    End Sub


    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged


    End Sub

    Private Sub ExitButton_Click(sender As Object, e As EventArgs) Handles ExitButton.Click

        Me.Close()

    End Sub

End Class

PS. You have to have an .ipt open for this to get the Content Center. I don't have the skill yet to check if an .ipt is open.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report