Copy link to clipboard
Copied
We want to save a Sketch which is not saved in the disk locally (Eg. Let say currently the sketch name is Untitled-1) through Adobe api. We are using the following adobe illustrator api to save the sketch internally.
error = sAIDocument->WriteDocument(fullFilePath, kAINativeFileFormat, false)
But after calling the api the untitled sketch would be stored into a particular location. After the save operation we want to close the untitled sketch automatically(Right now in Adobe, Untitled Sketch and saved sketch kept as opened). We call the following api to close the untitled sketch(currently kept as opened). But after calling the api, we got a popup that “Save changes to Adobe Illustrator document “Untitled-1” with the button Yes, No and Cancel. Actually we don’t want to display the popup. How can we achieve?
AIDocumentHandle handle = NULL;
sAIDocument->GetDocument(&handle);
sAIDocumentList->Close(handle);
Regards,
Avudai
Use sAIDocument
->SetDocumentModified(false); before closing the document
~Tarun
Copy link to clipboard
Copied
I'm assuming CS3/4 here:
// Get the current user interaction state
ASInteractionAllowed interactionAllowed = sASUserInteraction->GetInteractionAllowed();
// Set the user interaction state to never interact
sASUserInteraction->SetInteractionAllowed(kASInteractWithNone);
// Close our document
AIDocumentHandle handle = NULL;
sAIDocument->GetDocument(&handle);
sAIDocument->Close(handle);
// set the user interaction state back to what it was
sASUserInteraction->SetInteractionAllowed(interactionAllowed);
Acquire the User Interaction suite with kASUserInteractionSuite
and kASUserInteractionVersion
.
I've not actually used this suite myself so please report back if it works
Copy link to clipboard
Copied
Hi Wayne,
Thanks for your update.
I am using CS3. I tried your code. But now I am getting Adobe Illustrator Save As popup dialog. I don't want to display that dialog as well. What should I do. Help me in this regard.
Regards,
Avuds
Copy link to clipboard
Copied
I suppose you could use the Action Manager Suite to do a PlayActionEvent with the kSaveDocumentAsAction (in the native AI format) so that you are manually doing a "save as" without displaying the dialog. That way, when you close the file it won't ask you to save because you just did.
Copy link to clipboard
Copied
Use sAIDocument
->SetDocumentModified(false); before closing the document
~Tarun
Copy link to clipboard
Copied
I also thought that SetDocumentModified might help, but I'm not sure that it will work to supress the "save as" on a document that's never been saved before. It might work, I've just never used it in that exact instance.
Copy link to clipboard
Copied
Tarun,
I tried with ->SetDocumentModified(false). Working as aspected. Tons of thanks. Thanks for all making reply to this issue and closed this issue with your help. Thanks again.
Regards,
Avuds
Copy link to clipboard
Copied
Ahh, I should've thought of that.
Glad you sorted it Avuds
Copy link to clipboard
Copied
Hi,
I am having similar problem you had!, i want to save the current document convert it in to jpeg in single step
I tried to save the document and the code is running with out any error but the file is not being saved!
This is what i tried,
SPBasicSuite *aBasic = message->d.basic;
AIDocumentSuite *fSave;
aBasic->AcquireSuite (kAIDocumentSuite,kAIDocumentVersion, (
const void**)&fSave);
std::string abc = "D:\\Sreejesh\\test.ai";
ai::UnicodeString myString(abc);
ai::FilePath aiFile1(myString);
AIErr serror=fSave->WriteDocument(aiFile1,
"Adobe Illustrator", false);
can you give me any other method, or any samples which solve the problem.
Thanks in advance
Sreejesh K V
Copy link to clipboard
Copied
Hi Sreejesh
Use WriteDocumentWithOtions API to export the file as JPEG
//Setting Function specific variables
ActionDialogStatus dlgShow = kDialogOff;
sAIDocument->RedrawDocument();
std::string strOutputFileName = “C:\\tarun.jpeg”;
ai::UnicodeString myString(strOutputLocation);
sASUserInteractionSuite->SetInteractionAllowed(kASInteractWithNone);
sAIDocument->RedrawDocument();
sAIDocument->SetDocumentFileFormat(aiFileFormat);
ai::FilePath aiFile(myString);
const char *fileFormatName=”JPEG file format”;
err = sAIDocument->WriteDocumentWithOptions(aiFile, fileFormatName, kFileFormatExport | kFileFormatWriteAs | kFileFormatWrite , false);
Copy link to clipboard
Copied
Hi Tarun,
Thank you for your reply, let me try it out. I will update you the result
Copy link to clipboard
Copied
Hi tarun,
Thank you very much for your instant reply, I am getting an error in the line "sAIDocument->SetDocumentFileFormat(aiFileFormat);" , which is the type I have assign to the variable "aiFileFormat".
I want to do save and conversion in single step. Your code will work for the conversion to "JPEG". I need to save the same document in ai format also and your code is forcing the user to save in a particular folder, is it possible to allow the user to use the ai save option, That is I want to use the ai save menu with in my plug-in, so that the user can select the desired folder for saving the document. After completing the save operation the conversion to jpeg should takes place in background. The jpeg file should be saved into the same folder.
Thanks and best Regards
Sreejesh K V
Copy link to clipboard
Copied
I'm not sure what you are trying to do EXACTLY, but this might work for you:
error = sActionManager->PlayActionEvent(kAISaveDocumentAction,kDialogOff,NULL);
Copy link to clipboard
Copied
Hi ,
What I am trying to do is, to fetch the path of the current AI document in windows . To get the file path, the file should be saved in a location. I tried to save the document using the writedocument function. unfortunately the WriteDocument is not serving the purpose for me, So i thought I can have use the save option in the AI . So that I can make sure that the file will be saved. After saving the document properly i can fetch the path. and I have to send the path to my web application. I'll be grateful if you helps me with an example. Because I am already running out of time.
Thanks and Best Regards
Sreejesh K V
Copy link to clipboard
Copied
Here's something from one of my older plugins that might work for you... It's probably not the most perfect example though:
ASErr PlayNativeExport(SPBasicSuite *basic, char* newName) //newName has the full path including the file name
{
AIActionParamValueRef valueParameterBlock1 = NULL;
AIActionManagerSuite *sAIActionManager;
ASErr error = basic->AcquireSuite(kAIActionManagerSuite,kAIActionManagerSuiteVersion,(const void**)&sAIActionManager);
if(error == kNoErr)
{
ASErr result = sAIActionManager->AINewActionParamValue(&valueParameterBlock1);
if (valueParameterBlock1)
{
result = sAIActionManager->AIActionSetString(valueParameterBlock1,kAIExportDocumentNameKey,newName);
result = sAIActionManager->AIActionSetString(valueParameterBlock1,kAIExportDocumentFormatKey, kAINativeFileFormat);
result = sAIActionManager->AIActionSetString(valueParameterBlock1,kAIExportDocumentExtensionKey,kAINativeFileFormatExtension);
result = sAIActionManager->AIActionSetBoolean(valueParameterBlock1,kAINativeCompressionKey,false);
result = sAIActionManager->AIActionSetBoolean(valueParameterBlock1,kAINativePDFCompatibilityKey,false);
result = sAIActionManager->AIActionSetInteger(valueParameterBlock1,kAINativeVersionKey,14);
result = sAIActionManager->AIActionSetInteger(valueParameterBlock1,kAINativeScriptKey,1);
result = sAIActionManager->AIActionSetInteger(valueParameterBlock1,kAINativeIncludeImagesKey,0);
result = sAIActionManager->AIActionSetReal(valueParameterBlock1,kAINativeSubsetFontsRatioKey,100.0);
result = sAIActionManager->AIActionSetInteger(valueParameterBlock1,kAINativeEmbedProfileKey,0);
if(result == 0)
result = sAIActionManager->PlayActionEvent(kAIExportDocumentAction,kDialogOff,valueParameterBlock1);
if(result != 0)
error = result;
}
}
basic->ReleaseSuite(kAIActionManagerSuite,kAIActionManagerSuiteVersion);
return error;
}