Converting lisp functionality to VB. Turning on and off layers from an outside executable.

Converting lisp functionality to VB. Turning on and off layers from an outside executable.

C_Haines_ENG
Collaborator Collaborator
313 Views
3 Replies
Message 1 of 4

Converting lisp functionality to VB. Turning on and off layers from an outside executable.

C_Haines_ENG
Collaborator
Collaborator

I am looking to convert our old system using AutoCAD and .lisp scripts to Inventor and VB. 

 

The entire process would be this: 

  1. .bat file runs executable
  2. Executable opens Inventor, scans text file for specific codes, and turns off the respective layer in the inventor drawing mentioned in the text file
  3. Adds drawing features or sketch symbols to drawing
  4. Prints drawing
  5. Closes inventor without saving. 

I really don't know if this is possible in Inventor, but if anyone could help it would be massively appreciated. 

        

 

 

0 Likes
314 Views
3 Replies
Replies (3)
Message 2 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

I think all of this is possible to realize. But what kind of help do you require? Someone here to write the entire code for free? Think no one will have the time to do this.

Some hints:

- Get Microsoft Visual Studio Community Edition

- Create a new project creating a Windows executable

- Search Forum how:

    - to connect to a running Inventor instance or create a new one.

    - open drawing file

    - read in text file

    - traverse layer list and make it invisible

    - insert sketched symbols and possibly create it first oder get it from another file

    - handle drawing print manager

    - ...

 

And you have to add a lot of prechecking and error handling.


R. Krieg
RKW Solutions
www.rkw-solutions.com
Message 3 of 4

C_Haines_ENG
Collaborator
Collaborator

The biggest things I'm looking for are how to open inventor, and then actually interact with it from an outside program. I do not have alot of experience with VB, and there are no forms available discussing how to turn on and off layers using an external VB program.

0 Likes
Message 4 of 4

Ralf_Krieg
Advisor
Advisor

Hello

 

I did not found a complete HowTo to create a VB.Net standalone exe in Visual Studio. Some hints to start:

After creating a new project with a .Net Framework console app, add a reference to the Autodesk.Interop.dll. If Inventor is installed on your PC, you can find this file in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Autodesk.Inventor.Interop.

You can start/connect to an Inventor instance with (this is a minimalistic example)

Sub Main()
    Dim myInventor As Inventor.Application = StartInventor()

    If myInventor Is Nothing Then
        MsgBox("Starting Inventor not possible.")
        Exit Sub
    End If
End Sub

Private Function StartInventor() As Inventor.Application
        Dim m_inventorApp As Inventor.Application
        Try
            m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ' If not active, create a new instance of Inventor
            Dim inventorAppType As Type = System.Type.GetTypeFromProgID("Inventor.Application")
            m_inventorApp = System.Activator.CreateInstance(inventorAppType)
        End Try
        Return m_inventorApp
    End Function

 

From here, you can open a drawing document with

Dim oDrawDoc as DrawingDocument = myInventor.Documents.Open("FullPathToYourDrawingDocument", True)

Now you can act with your document, placing symbols and adding features.

 

You can read in your layer textfile line by line with a streamreader. I assume there is one line per layer name and every layer named in that file has to be set invisible.

Private Sub SetLayerInvisible(ByVal myDrawDoc As Inventor.DrawingDocument, ByVal myLayerTextFilePath As String)

        Dim objReader As New System.IO.StreamReader(myLayerTextFilePath)
        Dim sLine As String
        Dim counter As Integer = 0
        Dim oLayer As Inventor.Layer
        Do
            sLine = objReader.ReadLine()
            If Not sLine Is Nothing Then
                'sLine is the layername
                '
                For Each oLayer In myDrawDoc.StylesManager.Layers
                    If oLayer.Name = sLine Then
                        oLayer.Visible = False
                    End If
                Next
            End If
        Loop Until sLine Is Nothing
        objReader.Close()
    End Sub

 

To call this sub from your main sub

Sub Main()
        Dim args() As String = Environment.GetCommandLineArgs
        Dim sFullFileName As String = args(1)
        Dim sLayerTextfilePath As String = args(2)

        Dim myInventor As Inventor.Application = StartInventor()

        If myInventor Is Nothing Then
            MsgBox("Starting Inventor not possible.")
            Exit Sub
        End If

        Dim oDrawDoc As Inventor.DrawingDocument = myInventor.Documents.Open(sFullFileName, True)

        SetLayerInvisible(oDrawDoc, sLayerTextfilePath)

    End Sub

 

You'll have to add a lot of checking and error handling.


R. Krieg
RKW Solutions
www.rkw-solutions.com
0 Likes