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