I am attempting to implement an Illustrator (CC 2017 and above) plug-in which replicates the behavior of AppleScript's:
tell application "Adobe Illustrator" set file path of placed item 1 of document 1 to "/path/to/an/image" end tell
Initially I tried using SetPlacedFileSpecification() from the AIPlacedSuite. However, it appears that it is not possible to switch from an EPS file to a raster file as it returns AIErr 376 which thanks to (Paul_A_George) in a response to a previous question "Problem Programmatically Placing Images with Placed or Raster Suites" is badEPSFileErr. The ability to switch between linked EPS and raster files is an absolute requirement.
After searching this forum I found 3 other issues that seem relevant, Creating PlacedArt inside PluginArt result art, How to relink a raster to a file by using SDK?? and Placed image update which pointed me to the ExecPlaceRequest() also in AIPlacedSuite. I am now doing the following that appears to work:
AIPlaceRequestData lReplaceRequest; lReplaceRequest.m_lPlaceMode = kForceReplace; lReplaceRequest.m_hOldArt = lArtHandle; lReplaceRequest.m_pFilePath = &lNewFilePath; lReplaceRequest.m_filemethod = 1; // link lReplaceRequest.m_disableTemplate = true; // necessary? lReplaceRequest.m_doShowParamDialog = false; lReplaceRequest.m_PlaceTransformType = kAIPlaceTransformTypeNone; AIErr lErr = sAIPlaced->ExecPlaceRequest(lReplaceRequest);
What I am looking for is validation that this is correct and what the AppleScript calls.
Thanks in advance,
A follow up to the above query is whether it is necessary to call:
AIBoolean lUpdated = false; ThrowIfAIErr_(sAIArt->UpdateArtworkLink(lArtHandle, true, &lUpdated));
after the ExecPlaceRequest() to make sure that the link is completely updated.