My VB.NET add-in

My VB.NET add-in

Jef_E
Collaborator Collaborator
837 Views
4 Replies
Message 1 of 5

My VB.NET add-in

Jef_E
Collaborator
Collaborator

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
0 Likes
838 Views
4 Replies
Replies (4)
Message 2 of 5

MechMachineMan
Advisor
Advisor
From what I've read it looks like you could always make a macro that references and calls the .dll for the form rule, and have that in the ribbon.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 3 of 5

MechMachineMan
Advisor
Advisor
Also, As you have it there, you have your file path hardcoded in.

If you plan on making this a portable application, I would say you have some work to do.

This is bad practice according to what I've read around. Instead, you could hard code a reference file to local data/app data and use an xml or read a text file, and from that set your file location to replace and desired drive.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes
Message 4 of 5

Jef_E
Collaborator
Collaborator

@MechMachineMan wrote:
Also, As you have it there, you have your file path hardcoded in.

If you plan on making this a portable application, I would say you have some work to do.

This is bad practice according to what I've read around. Instead, you could hard code a reference file to local data/app data and use an xml or read a text file, and from that set your file location to replace and desired drive.

It's not intended to be an portable application, but you are correct that a document with reference to the save location would be better, should the location change. (I doubt this will ever happen in this situation but doesn't mean I should implement a bad practice 😉 )

 

Where would you store it? In the install directory? Or is it better to use C:\documents\ ? as this is also often done.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 5 of 5

MechMachineMan
Advisor
Advisor
A quick Google of "where to store application configuration files" or
something similiar to that I believe comes up with a few suggestions.

--------------------------------------
Did you find this reply helpful ? If so please use the 'Accept as Solution' or 'Like' button below.

Justin K
Inventor 2018.2.3, Build 227 | Excel 2013+ VBA
ERP/CAD Communication | Custom Scripting
Machine Design | Process Optimization


iLogic/Inventor API: Autodesk Online Help | API Shortcut In Google Chrome | iLogic API Documentation
Vb.Net/VBA Programming: MSDN | Stackoverflow | Excel Object Model
Inventor API/VBA/Vb.Net Learning Resources: Forum Thread

Sample Solutions:Debugging in iLogic ( and Batch PDF Export Sample ) | API HasSaveCopyAs Issues |
BOM Export & Column Reorder | Reorient Skewed Part | Add Internal Profile Dogbones |
Run iLogic From VBA | Batch File Renaming| Continuous Pick/Rename Objects

Local Help: %PUBLIC%\Documents\Autodesk\Inventor 2018\Local Help

Ideas: Dockable/Customizable Property Browser | Section Line API/Thread Feature in Assembly/PartsList API Static Cells | Fourth BOM Type
0 Likes