4 Replies Latest reply on May 15, 2016 11:16 PM by patilpralhad

    Save .ai file as .svg without save as prompt

    patilpralhad Level 1

      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

        • 1. Re: Save .ai file as .svg without save as prompt
          dnyaneshlb Level 1

          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.

          1 person found this helpful
          • 2. Re: Save .ai file as .svg without save as prompt
            Toto RoToTO Level 3

            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;

             

            }

             

            1 person found this helpful
            • 3. Re: Save .ai file as .svg without save as prompt
              Toto RoToTO Level 3

              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!

              • 4. Re: Save .ai file as .svg without save as prompt
                patilpralhad Level 1

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