How to export a project in pfd format via the API?

Category:
Interfaces
Answer

A project can be exported via the API by using a ComPfdexport command. This is demonstrated in the following C++ code snippet. Please note that pfd export is only possible if no project is currently active (identical to manual execution via GUI).

using api::Value;
using api::v1::Api;
using api::v1::DataObject;
using api::v1::Application;


int ExportProject(Api* apiInstance, DataObject* project, const char* filename)
{
if (!apiInstance|| !project || !filename) {
return 1;
}

//create an export command object
DataObject* comExport = app->GetCurrentUser()->CreateObject("ComPfdexport","");
if (!comExport) {
return 1;
}

//configure the command object
int error(0);
app->DefineTransferAttributes("ComPfdexport", "g_objects,g_file", &error);
if (error > 0) {
return 1;
}

Value objects(Value::VECTOR);
objects.VecInsertDataObject(project);

Value args(Value::VECTOR);
args.VecInsertValue(&objects);
args.VecInsertString(filename);

comExport->SetAttributes(&args, &error);
if (error == 0) {
//execute the export command
comExport->Execute("Execute", NULL, &error);
}

comExport->DeleteObject(); //clean up
apiInstance->ReleaseObject(comExport);

return error;
}
Tags
Back