PackAndGo from C++

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


Comments

3 responses to “PackAndGo from C++”

  1. Hi. Can i ask a question.
    I want to use PackAndGo on C++ Program.
    I could do it on C# program with adding reference [SolidWorks.Interpt.sldworks.dll] & [SolidWorks.Interpt.swconst.dll]
    But i dont know what i have to add library to use packandgo on C++ program.
    Can you teach me some information if you have an idea.
    Thank you.

  2. sorry ask again.
    I want to download and check your source, But i cant in office.
    So. I added reference sldworks.tlb where was SolidWorks 2015 installed folder.
    And make a CPackAndGo.h Class.
    I tried this.
    IModelDoc2 model = NULL;
    CString modelPath = pConv->m_OriginalFilePath;
    bRes = pswCtrl->OpenModel(modelPath, model);
    IModelDocExtension swDocExt = model.GetExtension();
    CPackAndGo swPackAndGo = swDocExt.GetPackAndGo();
    But IModelDocExtension had not GetPackAndGo method.
    may i refered wrong library?

  3. It’s only the “DTPackAndGo.tlb” library that you need to reference plus the apprentice library – see the above sample code.
    Have a look at the “SimpleApprenticeExe” sample that is part of the SDK that is installed along with Inventor.

Leave a Reply to GSCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading