Quantcast
Channel: Manufacturing DevBlog
Viewing all articles
Browse latest Browse all 518

PackAndGo from C++

$
0
0

By Adam Nagy

The Inventor API Reference provides VB.NET and C# sample codes, and there is also a blog post on it, but here is now a C++ sample too.

I simply used the SimpleApprenticeExe sample project and added the following to it:

#import "DTPackAndGo.tlb" no_namespace named_guids \
    raw_dispinterfaces raw_method_prefix(
"") \
    high_method_prefix(
"Method")

void PackAndGoSample()
{
  HRESULT Result = NOERROR;
    
  CComPtr<IPackAndGoComponent> packAndGoComp;
  Result = packAndGoComp.CoCreateInstance(CLSID_PackAndGoComponent);

  CComPtr<IPackAndGo> packAndGo =
    packAndGoComp->MethodCreatePackAndGo(
      L"C:\\Temp\\Source\\Assembly1.iam", L"C:\\Temp\\Destination");

  // Set the design project. This defaults to the
  // current active project.
  packAndGo->ProjectFile = L"C:\\Temp\\Source\\Test.ipj";

  // Set the options
  packAndGo->SkipLibraries = true;
  packAndGo->SkipStyles = true;
  packAndGo->SkipTemplates = true;
  packAndGo->CollectWorkgroups = false;
  packAndGo->KeepFolderHierarchy = true;
  packAndGo->IncludeLinkedFiles = true;

  SAFEARRAY * refFiles = NULL;
  VARIANT refMissFiles;

  // Get the referenced files
  packAndGo->MethodSearchForReferencedFiles(
    &refFiles, &refMissFiles);
    
  // Add the referenced files for package
  packAndGo->MethodAddFilesToPackage(&refFiles);

  // Start the pack and go to create the package
  // OverrideExistingFiles = TRUE
  packAndGo->MethodCreatePackage(VARIANT_TRUE);
}

As pointed out in the other blog post as well, a program that uses Pack and Go must be the same bitness as the Inventor they’re running with. If you’re using 64-bit Inventor then the program must also be 64-bit.

So I had to change the Project settings of the SimpleApprenticeExe sample on my Windows 7 x64 machine to x64: Download SimpleApprenticeExe_PackAndGo

I'm also attaching the sample Inventor 2015 project and document files that can be unpacked into the C:\Temp folder to test this program with: Download Source


Viewing all articles
Browse latest Browse all 518

Trending Articles