Copy link to clipboard
Copied
Hi All,
I have a scenario where I want to save .ai document as .svg silently(without save as dialog) in the background. I'm using following code to do this. But it is giving save as dialog.
sAIActionManager->AIActionSetStringUS(paramValue, kAIExportDocumentNameKey,ai::UnicodeString("test.svg"));
sAIActionManager->AIActionSetString(paramValue, kAIExportDocumentExtensionKey,kAISVGFileFormatExtension);
sAIActionManager->PlayActionEvent(kAIExportDocumentAction,kDialogOff,paramValue);
Is there anything I'm doing wrong?
If anyone knows how to do this kindly post code snippet or technique on how to do it.
Thank you for your help
the path you want to save your file is not correctly formatted, I guess. That is why dialogbox is shown.
Try to fix this first!
Copy link to clipboard
Copied
I have this snippet do exact thing you want. Though it uses extend-script and not c++.
This does not give you save as dialogue.
// Exports current document to dest as an SVG file with specified
// options, dest contains the full path including the file name
function exportFileToSVG (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsSVG();
var type = ExportType.SVG;
var fileSpec = new File(dest);
exportOptions.embedRasterImages = true;
exportOptions.embedAllFonts = false;
exportOptions.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
app.activeDocument.exportFile( fileSpec, type, exportOptions );
}
}
I hope this helps.
Copy link to clipboard
Copied
This few methods should help! Using Value parameter block (VPB) - a container for action parameters.
@see AIActionManagerSuite
void ActionHelper::VPB::SetSaveDocumentAsName(const ai::FilePath& name)
{
SDK_ASSERT(sAIActionManager);
ASErr result = sAIActionManager->AIActionSetStringUS(this->fActionParamValueRef, kAISaveDocumentAsNameKey, name.GetFullPath());
aisdk::check_ai_error(result);
}
void ActionHelper::VPB::SetSaveDocumentAsGetParams(ASBoolean getParams)
{
ASErr result = sAIActionManager->AIActionSetBoolean(this->fActionParamValueRef, kAISaveDocumentAsGetParamsKey, getParams);
aisdk::check_ai_error(result);
}
ASErr ActionHelper::SaveDocumentAs(const ai::UnicodeString& name, DocumentActionHelper::VPB& vpb)
{
ASErr result = kNoErr;
try {
ai::FilePath path(name);
vpb.SetSaveDocumentAsName(path);
// Enable dialogs parameter.
vpb.SetSaveDocumentAsGetParams(false);
ActionDialogStatus dialogStatus = name.empty() ? kDialogOn : kDialogOff;
result = this->SaveDocumentAs(dialogStatus, vpb);
aisdk::check_ai_error(result);
}
catch (ai::Error& ex) {
result = ex;
}
return result;
}
ASErr ActionHelper::SaveDocumentAs(ActionDialogStatus dialogStatus, AIActionParamValueRef parameters)
{
ASErr result = kNoErr;
try
{
SDK_ASSERT(sAIActionManager);
result = sAIActionManager->PlayActionEvent(kAISaveDocumentAsAction, dialogStatus, parameters);
aisdk::check_ai_error(result);
}
catch (ai::Error& ex)
{
result = ex;
}
return result;
}
Copy link to clipboard
Copied
the path you want to save your file is not correctly formatted, I guess. That is why dialogbox is shown.
Try to fix this first!
Copy link to clipboard
Copied
So here is code snippet to do this. I had to do export file instead of save as.
AIActionParamValueRef paramValueRef = NULL;
sAIActionManager->AINewActionParamValue(¶mValueRef);
ai::UnicodeString name = ai::UnicodeString("C:\\Users\\mypc\\Desktop\\test\\testfile.svg");
ai::FilePath path(name);
sAIActionManager->AIActionSetStringUS(paramValueRef, kAIExportDocumentNameKey,path.GetFullPath());
sAIActionManager->AIActionSetString(paramValueRef, kAIExportDocumentFormatKey, kAISVGFileFormat);
sAIActionManager->AIActionSetString(paramValueRef, kAIExportDocumentExtensionKey, kAISVGFileFormatExtension);
sAIActionManager->AIActionSetBoolean(paramValueRef, kAIExportDocumentSaveMultipleArtboardsKey, false);
sAIActionManager->PlayActionEvent(kAIExportDocumentAction, kDialogOff, paramValueRef);
Find more inspiration, events, and resources on the new Adobe Community
Explore Now