Many things can not be scripted with Adobe DOM you will need to learn about Adobe Plug-in Scriptlistener. When you see code like I posted that is not readable its Scriptlistener code that has been modified to some variables. The code is generated by the plug-in its like and action recorder for scripts.
I extracted what was generated for the import of an ai file that I open in Photoshop. I replaced the hard coded file path with a var file and the hard coded document name with Name. and turned it into a function. I did not write that code Photoshop's Plug-in Scriptlistener did... I added the code above // ===================
and are replace two hard coded set with var file and Name in the generated code below the //===================== Width and Height need work..... extract the code from mt fist post and save it as OpenAI.jsx . Drop that file onto Photshop you should be able to open an AI file you select.
function importAI(file) {
//alert(file);
// Isolate File Name
var Name = decodeURI(file).replace(/\.[^\.]+$/, ''); // strip the extension off
var imagePath = "";
while (Name.indexOf("/") != -1 ) { // Strip Path
imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);
Name = Name.substr(Name.indexOf("/") + 1 ,);
}
//alert(Name);
// =======================================================
var idOpn = charIDToTypeID( "Opn " );
var desc1 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc2 = new ActionDescriptor();
var idNm = charIDToTypeID( "Nm " );
desc2.putString( idNm, Name );
var idCrop = charIDToTypeID( "Crop" );
var idcropTo = stringIDToTypeID( "cropTo" );
var idboundingBox = stringIDToTypeID( "boundingBox" );
desc2.putEnumerated( idCrop, idcropTo, idboundingBox );
var idRslt = charIDToTypeID( "Rslt" );
var idRsl = charIDToTypeID( "#Rsl" );
desc2.putUnitDouble( idRslt, idRsl, 300.000000 );
var idMd = charIDToTypeID( "Md " );
var idClrS = charIDToTypeID( "ClrS" );
var idECMY = charIDToTypeID( "ECMY" );
desc2.putEnumerated( idMd, idClrS, idECMY );
var idDpth = charIDToTypeID( "Dpth" );
desc2.putInteger( idDpth, 8 );
var idAntA = charIDToTypeID( "AntA" );
desc2.putBoolean( idAntA, false );
var idWdth = charIDToTypeID( "Wdth" );
var idPxl = charIDToTypeID( "#Pxl" );
//desc2.putUnitDouble( idWdth, idPxl, 1943.000000 );
desc2.putUnitDouble( idWdth, idPxl, 5000.000000 );
var idHght = charIDToTypeID( "Hght" );
var idPxl = charIDToTypeID( "#Pxl" );
//desc2.putUnitDouble( idHght, idPxl, 276.000000 );
desc2.putUnitDouble( idHght, idPxl, 5000.000000 );
var idCnsP = charIDToTypeID( "CnsP" );
desc2.putBoolean( idCnsP, true );
var idsuppressWarnings = stringIDToTypeID( "suppressWarnings" );
desc2.putBoolean( idsuppressWarnings, false );
var idfsel = charIDToTypeID( "fsel" );
var idpdfSelection = stringIDToTypeID( "pdfSelection" );
var idpage = stringIDToTypeID( "page" );
desc2.putEnumerated( idfsel, idpdfSelection, idpage );
var idPgNm = charIDToTypeID( "PgNm" );
desc2.putInteger( idPgNm, 1 );
var idPDFG = charIDToTypeID( "PDFG" );
desc1.putObject( idAs, idPDFG, desc2 );
var idnull = charIDToTypeID( "null" );
desc1.putPath( idnull, new File( file ) );
executeAction( idOpn, desc1, DialogModes.NO );
}