Pack and Go API

Pack and Go API

Anonymous
Not applicable
5,832 Views
35 Replies
Message 1 of 36

Pack and Go API

Anonymous
Not applicable

Looking for a bit of guidance with the Pack and Go API.

 

I have ran the example API provided in Inventor 2017 within VB.NET as follows (This is running on a simple form on button press):

 

 

Private Sub Button2_Click(sender As System.Object, e As EventArgs) Handles Button2.Click
Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent

Dim oPacknGo As PackAndGoLib.PackAndGo
oPacknGo = oPacknGoComp.CreatePackAndGo("C:\PacknGo\Source\Castor Parts.iam", "C:\PacknGo\Castor Parts")

' Set the design project. This defaults to the current active project.
oPacknGo.ProjectFile = "C:\PacknGo\Source\Castor Parts.ipj"

Dim sRefFiles = New String() {}
Dim sMissFiles = New Object

' Set the options
oPacknGo.SkipLibraries = True
oPacknGo.SkipStyles = True
oPacknGo.SkipTemplates = True
oPacknGo.CollectWorkgroups = False
oPacknGo.KeepFolderHierarchy = True
oPacknGo.IncludeLinkedFiles = True

' Get the referenced files
oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)

' Add the referenced files for package
oPacknGo.AddFilesToPackage(sRefFiles)

' Start the pack and go to create the package
oPacknGo.CreatePackage()

End Sub

 

This is causing an Error message "An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred {"Error HRESULT E_FAIL has been returned from a call to a COM component."}"

 

 

All file paths are correct and output directory is created, I have double checked this as well as running the following:

 

Dim ProjFile As DesignProjectManager
            ProjFile = g_inventorApplication.DesignProjectManager
            'Convert Project name to string
            Dim ProjName As String
            ProjName = ProjFile.ActiveDesignProject.FullFileName
            Debug.Print("Active project: " & ProjName)

Which returns the debug print string correctly and then tried using:

 

oPacknGo.ProjectFile = ProjName

So I know the Project File is correct but no matter what I try it seems to continually fall over.

 

I can run the code successfully if I comment out the Project file line, however this only creates a Pack and Go of the singular Part/Assembly that is open and no linked files (which defeats the point of Pack and Go)

 

Any resolution/advise would be greatly appreciated.

0 Likes
Accepted solutions (1)
5,833 Views
35 Replies
Replies (35)
Message 2 of 36

SašoPrijatelj
Advocate
Advocate

Hi,

 

I did some tests with your example. I think that it is actually not necessary to define the project because it it defaults to currently selected project anyway.

 

The real problem I found is that .SearchForReferencedFiles for some reason finds only top assembly file. I was testing with VBA and I could not find a way to solve it but reading this blog post I found the following:

 

"This interop is 32bits on 32bits OS, 64bits on 64bits. So please make sure your application is correctly configured. When I used it the first time on my 64bits, it failed. It took me some time to figure out the failure is due to the application uses X86 configuration in default. After I changed to Any CPU, it works. "

 

Did you already see this and set the target in Visual Studio to Any CPU?

 

 

 

-----------------------------------------------------------------------
AutoDXF - automatic flat pattern creation and batch export to DXF for Inventor

Please use "Accept as Solution" & give "Kudos" if this response helped you.
0 Likes
Message 3 of 36

Anonymous
Not applicable

Thanks for the reply.

 

Yes it's currently set to compile targeting any CPU.

0 Likes
Message 4 of 36

psaarloos
Collaborator
Collaborator

Hi Paul,

 

I did a quick test and on my machine it's working without a problem. I had to create the destination folder upfront. Some things to verify/try:

 

1) Is your application an add-in or a standalone application?

2) Are the Inventor documents all migrated to the 2017 release? If not, try if it makes a difference

3) Set the 'Embed Interop Types' property of the Autodesk interop references to false

 

Hope you can get it to work. If not, I can take a look at it if your project.

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 5 of 36

Anonymous
Not applicable

Hi,

 

1) This is an Add-in

2) All data is Migrated

3) autodesk.inventor.interop embed was set to False, however Autodesk.PackAndGo.Interop was set to True.

 

I have changed this to false however it still is only creating the top level assembly and not it's children within the Pack and Go Workspace folder.

 

Did you manage to get this working with all the children present from VB.net? If so would you be able to provide an example/source so I could try to cross compare?

 

 

 

0 Likes
Message 6 of 36

psaarloos
Collaborator
Collaborator
Accepted solution

Hi Paul,

 

Yes, my assembly has two sub assemblies and all children are in the pack and go. The difference is that I tested it in a standalone application instead of an add-in. This could make a difference. My guess is that the PackAndGo functionality of the API is using Inventor Apprentice, which can't be used from within Inventor itself. Try making a Windows Application in Visual Studio and paste the code below in the form code (Change the pack and go paths).

 

Does it work on your end with a standalone application?

 

Imports Inventor

Public Class Form1

    Private inventorApplication As Inventor.Application

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Dim inventorRunning As Boolean = GetInventorApplication()
        'If Not inventorRunning Then
        If inventorRunning = False Then
            MsgBox("Inventor isn't running" & vbCr & "Launch Inventor and restart this application" & vbCr & vbCr, MsgBoxStyle.Critical, "Cadac Group")
        End If

    End Sub

    Private Function GetInventorApplication() As Boolean

        Try
            inventorApplication = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
        Catch ex As Exception
            Return False
        End Try

        Return True

    End Function

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent

        Dim oPacknGo As PackAndGoLib.PackAndGo
        oPacknGo = oPacknGoComp.CreatePackAndGo("C:\Workspace\NXTdimVault\Documents\Projects\P00002\WG1E0001199.iam", "C:\PacknGo\Test2")

        ' Set the design project. This defaults to the current active project.
        oPacknGo.ProjectFile = inventorApplication.DesignProjectManager.ActiveDesignProject.FullFileName

        Dim sRefFiles = New String() {}
        Dim sMissFiles = New Object

        ' Set the options
        oPacknGo.SkipLibraries = False
        oPacknGo.SkipStyles = True
        oPacknGo.SkipTemplates = True
        oPacknGo.CollectWorkgroups = False
        oPacknGo.KeepFolderHierarchy = True
        oPacknGo.IncludeLinkedFiles = True

        ' Get the referenced files
        oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)

        ' Add the referenced files for package
        oPacknGo.AddFilesToPackage(sRefFiles)

        ' Start the pack and go to create the package
        oPacknGo.CreatePackage()
    End Sub

End Class
Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 7 of 36

Anonymous
Not applicable

Hi Pim,

 

Thanks for your continued support with this.

 

 

The following suggestion works - Thank you!

 

The reason I developed this as an addin is that the command is triggered by a button in the ribbon (As well as other tools) and I don't really want to separate them out into two different solutions, would there be a way of still continuing to do this?

0 Likes
Message 8 of 36

psaarloos
Collaborator
Collaborator

Hi Paul,

 

It's pretty easy to kick off the action through a button in your add-in, although it's a bit more complicated to monitor the process.

 

1) Build a Console application (pretty much the same as a Windows Application, but without any forms. Use arguments to tell the console application the source path and destination paths (and other options if you want). Normally if a console application runs as it should the ExitCode is set to 0. Within your console application you can use Environment.Exit(1) for example within a Try..Catch block. Within your add-in you look at the ExitCode after the process has finished. If it's not 0, you know something has gone wrong.

 

2) Launch the process with a button in your add-in.

 

Sample:

 

1) Console application

Module MyConsoleApplication

Sub Main(ByVal args As String())

    'MsgBox("test breakpoint on console app")

   If args.Length > 0 Then

      Select Case args(0)
 
         Case "PackAndGo"

                    Try
                        PackAndGo(args(1),args(2))
                    Catch ex As Exception
                        Environment.Exit(1)
                    End Try

            End Select

        End If

        Environment.Exit(0)

    End Sub

End Module

To debug the console application you can use the 'Command Line Arguments' section on the Debug properties pane within the Project Properties. Put something like "PackAndGo" "C:\Temp\Assembly1.iam" "C:\PackAndGo" in there and use breakpoints to see if the arguments are passed in correctly.

 

 

2) Launching the console applcation (code in your button execute event)

 

Dim myProcess As New Process
Dim processName As String = "YourConsoleApplication.exe"
Dim actionName As String = "PackAndGo"
Dim sourcePath As String = "C:\Temp\Assembly.iam"
Dim destinationFolder As String = "C:\PackAndGo"
Dim errorMessageArray As New ArrayList

myProcess.StartInfo.UseShellExecute = False
myProcess.StartInfo.RedirectStandardError = False
myProcess.StartInfo.RedirectStandardOutput = False
myProcess.StartInfo.FileName = Path.Combine(executingAssemblyPath, processName)
myProcess.StartInfo.Arguments = """" + actionName + """ """ + sourceFolder + """ """ + destinationFolder + """"
myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
myProcess.StartInfo.CreateNoWindow = True
myProcess.Start()
 myProcess.WaitForExit()

If myProcess.ExitCode = 9 Then
   hasErrors = True
   errorMessageArray.Add("Some specific error has occurred")
ElseIf myProcess.ExitCode <> 0 Then
   hasErrors = True
   errorMessageArray.Add("An error occurred while trying to execute the pack and go operation")
End If

If hasErrors Then
   ' Show MessageBox
   ShowErrorMessages(errorMessageArray)
End If

 

Hope it works for you!

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
Message 9 of 36

Anonymous
Not applicable

Thanks again, I will give this a go tomorrow with any luck and let you know how I get on.

0 Likes
Message 10 of 36

Anonymous
Not applicable

Struggling to get this fully working, not sure if it's just a simple mistake or just showing my inexperience here.

 

Do you have any example source code I could cross compare with my own to see where I'm going wrong if possible?

 

Kind regards,

Paul.

0 Likes
Message 11 of 36

psaarloos
Collaborator
Collaborator

Hi Paul,

 

I just the snippets I posted here. You can attach your solution or send it to me directly so I can have a look. (psaarloos at cadac dot com)

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 12 of 36

Anonymous
Not applicable

Thanks for all your help with this, I have used the form technique so I can use this to show paths etc.

0 Likes
Message 13 of 36

psaarloos
Collaborator
Collaborator

Hi Paul,

 

Great to hear. Thanks for the feedback!

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 14 of 36

NachoShaw
Advisor
Advisor
Can't see how you are setting sRefFiles. I see it being created but what is populating it?

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 15 of 36

psaarloos
Collaborator
Collaborator

Hi Nacho,

 

It's this line that is populating the sRefFiles variable:

 

oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)

 

 

The SearchForReferencedFiles call has two so called 'out' parameters. Passing in two empty variables which get filled when the function itself is handled. Hope this makes sense 🙂

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 16 of 36

Anonymous
Not applicable

Hello Pim, I am using the program that you wrote in VisualBasic but I have an error.(picture 1)picture 1.png

Then I tried erasing  "New" in this line "Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent" but I had another problem (picture 2)

 

please, could you help me?picture 2.png

0 Likes
Message 17 of 36

psaarloos
Collaborator
Collaborator

Hi,

 

Could you post your solution so I can take a look at it? (or send it through WeTransfer to: psaarloos at cadac dot com)

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes
Message 18 of 36

Anonymous
Not applicable

Thanks for your response.

 

I just send the code through We transfer

Thanks

0 Likes
Message 19 of 36

NachoShaw
Advisor
Advisor

Hi

 

have you tried like this:

 

Dim oPacknGo as PackAndGo.Lib.PackAndGo = New PackAndGo.Lib.PackAndGo

or

 

 

 

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 20 of 36

psaarloos
Collaborator
Collaborator

Hi,

 

I changed your code behind button3 a little bit. Now it is working. The thing is that the PackAndGo functionality can't be used from within the Inventor process. I added a line to create a Apprentice Server object (light weight Inventor) to read the ActiveDesignProject. I also changed the line to create a new PackAndGoComponent object.

 

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

        Dim apprenticeServer As Inventor.ApprenticeServerComponent = New ApprenticeServerComponent()
        Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent

        Dim oPacknGo As PackAndGoLib.PackAndGo
        oPacknGo = oPacknGoComp.CreatePackAndGo("C:\Workspace\NXTdimVault\Documents\Projects\P008\AE0001025.iam", "C:\Temp\PG")

        ' Set the design project. This defaults to the current active project.
        oPacknGo.ProjectFile = apprenticeServer.DesignProjectManager.ActiveDesignProject.FullFileName

        Dim sRefFiles = New String() {}
        Dim sMissFiles = New Object

        ' Set the options
        oPacknGo.SkipLibraries = False
        oPacknGo.SkipStyles = True
        oPacknGo.SkipTemplates = True
        oPacknGo.CollectWorkgroups = False
        oPacknGo.KeepFolderHierarchy = True
        oPacknGo.IncludeLinkedFiles = True

        ' Get the referenced files
        oPacknGo.SearchForReferencedFiles(sRefFiles, sMissFiles)

        ' Add the referenced files for package
        oPacknGo.AddFilesToPackage(sRefFiles)

        ' Start the pack and go to create the package
        oPacknGo.CreatePackage()

    End Sub

 

Hope it works on your environment as well.

Regards,
Pim Saarloos
Product Manager
If my post answers your question, please click the "Accept as Solution" button. Kudos are much appreciated!
0 Likes