Message 1 of 5
My VB.NET add-in
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to understand more about Inventor add-in's and how to make them available in Inventor
I made a VB.NET application that has a windows-form on it with one button 'Save' what it does is simply saves a drawing and copy/paste it to a desired diretory. so others can view the .dwg with having inventor. (using Acad or a Viewer)
But i don't want this application as a windows form app. I would like to have custom button in my ribbon that runs this program. How do you do this?
My code
Imports System.Type Imports System.Activator Imports System.Runtime.InteropServices Imports Inventor Public Class EMIA_001 Public oInvApp As Inventor.Application Public oInvStarted As Boolean = False Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. Try oInvApp = Marshal.GetActiveObject("Inventor.Application") Catch ex As Exception Try Dim invAppType As Type = GetTypeFromProgID("Inventor.Application") oInvApp = CreateInstance(invAppType) oInvApp.Visible = True oInvStarted = True Catch ex2 As Exception ' Uitzetten van inventor functies zichtbaarheid ' Call functie End Try End Try End Sub Private Sub Save_Click(sender As Object, e As EventArgs) Handles Save.Click ' Reference the active document Dim oDoc As Inventor.Document oDoc = oInvApp.ActiveDocument ' Check document type ' Only drawing files are to be saved with this code. If Not oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then MsgBox("Bad document type selected") Exit Sub End If ' Save the drawing oDoc.Save2(True) ' Get the document saved location Dim oSavePath As String oSavePath = oDoc.FullDocumentName Debug.Print("Save path = " & oSavePath) ' Convert the document save path to a network location Dim oCopyPath As String oCopyPath = oSavePath.Replace("C:\VaultWorkspace\cadcampc\", "N:\") Debug.Print("Copy path = " & oCopyPath) ' Check if the path exist ' HACK: improvement could be done? Dim oCharCount As Integer oCharCount = 0 Dim oCheckFolder As String = "" For x = 1 To oCopyPath.Length If GetChar(oCopyPath, x) = "\" Then oCharCount = oCharCount + 1 End If If oCharCount = 3 Then oCheckFolder = oCopyPath.Substring(0, x) Debug.Print("Checkfolder = " & oCheckFolder) Exit For End If Next If Not System.IO.Directory.Exists(oCheckFolder) Then MsgBox("This directory does not exist." & vbLf & "Please check the directory of this file.", MsgBoxStyle.Information, ".dwg copy error.") Exit Sub End If ' Copy and paste the saved .dwg to the network location My.Computer.FileSystem.CopyFile(oSavePath, oCopyPath, Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs, Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing) ' Set the copied file to read-only. ' tested file opened with AutoCad and AutoCad-LT read-only and overwrite file ' viewer passed this test (test on desktop 29/01/2016) ' autocad passed this test (test on desktop 1/02/2016) System.IO.File.SetAttributes(oCopyPath, IO.FileAttributes.ReadOnly) End Sub End Class
Please kudo if this post was helpfull
Please accept as solution if your problem was solved
Inventor 2014 SP2