Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Save .ai file as .svg without save as prompt

Community Beginner ,
May 13, 2016 May 13, 2016

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

TOPICS
SDK
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , May 13, 2016 May 13, 2016

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!

Translate
Adobe
Participant ,
May 13, 2016 May 13, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 13, 2016 May 13, 2016

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
May 13, 2016 May 13, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 15, 2016 May 15, 2016
LATEST

So here is code snippet to do this. I had to do export file instead of save as.

  AIActionParamValueRef paramValueRef = NULL;

  sAIActionManager->AINewActionParamValue(&paramValueRef);

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines