Inventor Pack and Go using iLogic

Inventor Pack and Go using iLogic

Anonymous
Not applicable
4,833 Views
18 Replies
Message 1 of 19

Inventor Pack and Go using iLogic

Anonymous
Not applicable

 

Hi all,

The Pack And Go API sample works fine when run from Visual Studio, but when used in iLogic (with a reference to the Pack and Go DLL at the start of the iLogic rule, it gives the following error:

 

Error HRESULT E_FAIL has been returned from a call to a COM component.

Details: System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
at PackAndGoLib.PackAndGoClass.set_ProjectFile(String Result)

 

This is strange, as it is simply refusing to set the active project file for the Pack and Go. I've read xiaodong-liang's helpful blog below - could this be a case of x86 and x64 interop problems? I'm sure this must be simple to solve - I don't really want to have to write my own Pack and Go routine in iLogic.

 

http://adndevblog.typepad.com/manufacturing/2013/05/use-packandgo-of-2014-api.html

 

Any thoughts?

 

SyntaxEditor Code Snippet

 AddReference "C:\Program Files\Autodesk\Inventor 2017\Bin\Autodesk.PackAndGo.Interop.dll" 
 
 Dim oPacknGoComp As New PackAndGoLib.PackAndGoComponent

        Dim oDoc As Document = ThisApplication.ActiveEditDocument

        'ensure the first argument of CreatePackAndGo is correct assembly,
        'and the path of the second argument exists
        ' otherwise, the method will crash
        Dim oPacknGo As PackAndGoLib.PackAndGo
        oPacknGo = oPacknGoComp.CreatePackAndGo(ThisApplication.ActiveEditDocument.FullFileName, "C:\Temp\")

        ' set the project file for the export to be the currently active project file
        ' ERRORS ON THIS LINE......
        oPacknGo.ProjectFile = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName

        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()

 

0 Likes
4,834 Views
18 Replies
Replies (18)
Message 2 of 19

gerry_treacy
Contributor
Contributor

Hi Luke,

 

did you ever find the answer to this? I have the same problem and cannot find any solution. I commented out the line setting the project file and it works except it does not include parts in the P&G output, presumably because of the missing project file.

 

thanks

Gerry

0 Likes
Message 3 of 19

Curtis_W
Consultant
Consultant

Hi g.treacy,

 

If the project file is not set, it uses the current active project.

 

I added a Try / Catch, so that it caught the error and just used the current active project, and then it ran without error.

 

Try
  oPacknGo.ProjectFile = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName
Catch
End Try

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 4 of 19

gerry_treacy
Contributor
Contributor

Thanks for the reply Curtis, I had trapped the error and figured out that it would run and create a pack & go without specifying a project file. However, the package did not include the parts (when I create a manual package with the same setttings it includes the parts). I assume the search function is not finding the files and I guessed this is due to not specifying the project file, but maybe there is some other reason - any ideas or suggestions?

 

I am new to iLogic and just getting to grips with the basics. Is there any way to debug / step through the code? 

 

thanks for your help,

Gerry

0 Likes
Message 5 of 19

Curtis_W
Consultant
Consultant

Hi g.treacy,

 

I looked at this again, and see the same results (I overlooked that it missing the referenced files the first time).

 

Unfortunately, I can't find any further information on the Pack and Go in the API, so I'm not sure how to resolve it.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 6 of 19

gerry_treacy
Contributor
Contributor

I created a dll for this but it failed with the same error. The only way I could get it to work was to create a windows forms application and call it from Ilogic.  I can now create the Pack and Go and it includes the referenced files.

 

If anyone ever figures out why it fails in iLogic I would love to know what the problem is.

0 Likes
Message 7 of 19

AlexFielder
Advisor
Advisor

@Anonymous if I may add my thoughts to this thread, I just opened the C:\Program Files\Autodesk\Inventor 2017\Bin\Autodesk.PackAndGo.Interop.dll with a program called ilSpy and it shows the following information:

 

' C:\Program Files\Autodesk\Inventor 2017\Bin\Autodesk.PackAndGo.Interop.dll
' Autodesk.PackAndGo.Interop, Version=18.0.0.0, Culture=neutral, PublicKeyToken=d84147f8b4276564

' Global type: <Module>
' Architecture: AnyCPU (64-bit preferred)
' Runtime: .NET 4.0

I'm not sure whether that has any bearing on iLogic's ability to call the .dll or not- it may be failing because the type is a Module?

 

Out of curiosity I opened one of my own external, callable from within iLogic .dlls using the same tool and I see the following:

 

' C:\Program Files\Autodesk\Inventor 2016\Bin\iLogicAdd\iLogicExternalDebug.dll
' iLogicExternalDebug, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

' Global type: <Module>
' Architecture: AnyCPU (64-bit preferred)
' Runtime: .NET 4.0

Which of course proves my speculation about the .dll being a Module incorrect.

 

I haven't ever attempted to load a .dll from within iLogic that wasn't located inside the iLogicAdd directory of the Inventor install directory, so maybe that is why the pack&go .dll is failing?

 

Rubber Duck discovery:

 

According to this page the following is true:

 

You can change this location using the iLogic Configuration command. You can also add references to DLLs in the main Autodesk Inventor Bin folder (for example, C:\Program Files\Autodesk\Inventor [Version]\Bin).

The AddReference statement does not support a full path specification. You can only specify a filename.

So that's why it isn't working.

 

If you were to change the path from:

 

C:\Program Files\Autodesk\Inventor 2017\Bin\Autodesk.PackAndGo.Interop.dll

to:

Autodesk.PackAndGo.Interop.dll

It should then work, yes?

0 Likes
Message 8 of 19

gerry_treacy
Contributor
Contributor

Thanks for the info Alex.

 

Just to clarify, I can call my dll from iLogic and it runs fine except an error occurs when it tries to set the Project File - the same error occurs in iLogic. In both cases if I omit the line to set the Project File it uses the default one (which is ok) but the Pack and Go that it generates only includes the assembly file, not the referenced parts.

 

In my windows form I can set the Project File, it does not throw any error, and the Pack and Go includes the referenced files.

0 Likes
Message 9 of 19

AlexFielder
Advisor
Advisor

You are welcome @gerry_treacy!

 

I would revisit @Curtis_W's suggestion to trap the Project File change in a try, catch:

 

Try
  oPacknGo.ProjectFile = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName
Catch
End Try

Of course, you have to remember that you can't have any files open if you attempt to change the active project inside Inventor manually; I would assume the same is true for when you are using both iLogic and the API.

 

Also, I noticed your earlier question about debugging iLogic.

 

Simply put, the answer is no. (Not without adding umpteen messageboxes all over the place.) You can of course have iLogic update the Inventor Statusbar with something like this:

 

Sub updatestatusbar(ByVal message As String)
	ThisApplication.statusbartext = message
End Sub

Sub updatestatusbar(ByVal percent As Double, ByVal message As String)
	ThisApplication.statusbartext = message + " (" & percent.tostring("P1") + ")"
End Sub

'called in code with something like:

updatestatusbar(percent,"Exporting: " & System.IO.Path.GetFileNameWithoutExtension(dwgdoc.fulldocumentname) & ".dwg")

'or:

updatestatusbar("This is the message you want to appear on the statusbar")

Your only other alternative (if you still wish to debug iLogic) is to have an iTrigger event that runs a rule similar to this:

 

'this reference file is built with Visual Studio and inside the .vbproj file it "builds"
'to the iLogicAdd directory for whatever Inventor version you are running
AddReference "IlogicExternalDebug.dll"
    Imports iLogicExternalDebug
Imports Inventor
Sub Main()
    Dim xtClass As New iLogicExternalDebug.ExtClass()
    xtClass.ThisApplication = ThisApplication
    xtClass.DocToUpdate = ThisDoc
    Call xtClass.Update()
End Sub

The annoying thing with the above approach is that unlike when you build an add-in and publish it to the %appdata%\Autodesk\ApplicationPlugins\$(TargetName)\ folder (whereupon any supported Inventor version would happily load your addin from) you would need to have a post-build event that copies all the relevant files to the iLogicAdd folder for every Inventor install.

 

 

 

 

0 Likes
Message 10 of 19

gerry_treacy
Contributor
Contributor

Thanks again, still getting up to speed with iLogic and all advice welcome. I did use the try/catch and I will try out your debugging tips.

 

What you said about setting the Project File makes sense to me now - the assembly is open so if it cannot be changed manually then it probably cannot be changed in code either. Seems obvious now, should have realised that.

 

I still don't understand why it does not include the referenced files though. The code works in my windows form but not in iLogic and i don't understand why it would be different.

0 Likes
Message 11 of 19

gerry_treacy
Contributor
Contributor

I have another question related to this code and I hope you can help me. The section 'referenced files' searches and adds the parts to the package but this does not include drawings. I believe the command to add referencing drawing files is:

 

oPacknGo.SearchForReferencingFiles(SearchedFiles:= , ReferencingFiles:= , SearchProjectLocations:=True, FolderPath:="", IncludeSubfolders:=True)

 

However I cannot find any help on this and I'm having trouble figuring it out. Any guidance or examples would be very much appreciated.

0 Likes
Message 12 of 19

Jef_E
Collaborator
Collaborator

@gerry_treacy wrote:

I have another question related to this code and I hope you can help me. The section 'referenced files' searches and adds the parts to the package but this does not include drawings. I believe the command to add referencing drawing files is:

 

oPacknGo.SearchForReferencingFiles(SearchedFiles:= , ReferencingFiles:= , SearchProjectLocations:=True, FolderPath:="", IncludeSubfolders:=True)

 

However I cannot find any help on this and I'm having trouble figuring it out. Any guidance or examples would be very much appreciated.


Hi,

 

Did you find any help on this matter? I need it too!



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

Inventor 2014 SP2
0 Likes
Message 13 of 19

gerry_treacy
Contributor
Contributor

No, I never found anything further on how to get the ReferencingFile

 

However I got a working solution by using the drawing instead of the assembly file for ReferencedFile - then all files including drawings were included in the Pack & Go. Give this a try.

0 Likes
Message 14 of 19

AlexFielder
Advisor
Advisor

Hiya @gerry_treacy @Jef_E (I just saw your new post here!),

 

I just had a look in the usual places (With this Google Search) and came up empty. 😞

 

However, I did retrieve the following after using Sandcastle on the Autodesk.PackAndGo.Interop.dll - 

 

2017-01-26 16_44_38-A Sandcastle Documented Class Library.png

 

Which seems to confirm your earlier assumption about the syntax it requires.

 

As you can see from the above though, the file doesn't appear to contain any notation/xml comments to explain this command further.

 

Regards and Thanks,

 

Alex.

 

EDIT: Linked to github home of Sandcastle instead of codeplex

0 Likes
Message 15 of 19

Jef_E
Collaborator
Collaborator

Hi @AlexFielder,

 

What does this mean? I don't quite understand what you are trying to say here. It doesn't work?

 

It would be cool if @ekinsb or some other autodesk wizard could share some insight.



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

Inventor 2014 SP2
0 Likes
Message 16 of 19

AlexFielder
Advisor
Advisor

Hi @Jef_E,

 

My last reply was related to @gerry_treacy's earlier question about documentation for the SearchForReferencingFiles() command.

 

As it is present within the API it should work; there just isn't any documentation available on it.

 

Regards,

 

Alex.

0 Likes
Message 17 of 19


@gerry_treacy wrote:

I have another question related to this code and I hope you can help me. The section 'referenced files' searches and adds the parts to the package but this does not include drawings. I believe the command to add referencing drawing files is:

 

oPacknGo.SearchForReferencingFiles(SearchedFiles:= , ReferencingFiles:= , SearchProjectLocations:=True, FolderPath:="", IncludeSubfolders:=True)

 

However I cannot find any help on this and I'm having trouble figuring it out. Any guidance or examples would be very much appreciated.


This works for me:

                string[] referencedFiles = new string[] { };
                packAndGo.SearchForReferencedFiles(out referencedFiles, out _);

                string[] referencingFiles = new string[] { };
                packAndGo.SearchForReferencingFiles(referencedFiles, out referencingFiles, true);

                int combinedSize = referencedFiles.Length + referencingFiles.Length;

                string[] combinedFiles = new string[combinedSize];
                System.Array.Copy(referencedFiles, combinedFiles, referencedFiles.Length);
                System.Array.Copy(referencingFiles, 0, combinedFiles, 
                    referencedFiles.Length, referencingFiles.Length);

                packAndGo.AddFilesToPackage(combinedFiles);
0 Likes
Message 18 of 19

prussellZXB3F
Enthusiast
Enthusiast

Old post but in case someone stumbles this way it is possible to step through ilogic code with visual studio. Just put a "break" statement in your ilogic and with any vb project open in visual studio go "Debug > Attach to process" and run your ilogic. Bit of a faff but worth the effort sometimes.

Message 19 of 19

scatterlogical
Explorer
Explorer

Oh I never thought to do this! Works great, gonna make debugging ilogic so much easier. Thanks! Now if only there was a way to edit ilogic code in VS that would be brilliant.

0 Likes