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

Link Place Date

New Here ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Hi,

 

On selecting a link in Links panel, we can see "Place Date" for the link. I want to get this date via scripting in jsx. There is "date" property in Link but it doesn't seem to be the place date. Can we get the place date?

 

Thanks,

Narayan

TOPICS
Scripting

Views

515

Translate

Translate

Report

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 Expert ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Right, the date property is the link’s modification date. You could probably have a startup script listen for the place event and insert the current date into the link’s label, then use the link’s label property to retrieve the date later.

Votes

Translate

Translate

Report

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 Expert ,
Feb 05, 2021 Feb 05, 2021

Copy link to clipboard

Copied

Something like this saved to the startup scripts folder:

 

 

var myEventListener = app.eventListeners.add("afterPlace", placeDate );

function placeDate(evt){
    var d = new Date(); 
    evt.parent.images[0].itemLink.label = d.toString()
}

 

 

Then later select the placed image and this gets the place date 

 

 

var doc = app.documents.item(0);
var s = doc.selection[0];

$.writeln("Link was placed on: " + s.itemLink.label)
//Link was placed on: Fri Feb 05 2021 13:24:19 GMT-0500

 

 

Votes

Translate

Translate

Report

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
New Here ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

Hi Rob,

Thanks for the reply. This will work with newly placed items. But won't be able to get place date for existing document with placed items.

Is there any method in the sdk to get place date of link?

Regards,

Narayan

Votes

Translate

Translate

Report

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 Expert ,
Feb 16, 2021 Feb 16, 2021

Copy link to clipboard

Copied

You could add a return value to @SychevKA â€™s excellent function and loop through the links. This returns the link name and place date:

 

 

var lnks = app.documents[0].links;
for (var i = 0; i < lnks.length; i++) {
    lnks[i].parent.select();
    var pd = GetPlaceDate()
    var n = lnks[i].name;
    $.writeln("Link name:" + n + "\nPlace Date: " + pd + "\n")
}


/**
* Gets the selection’s place date 
* @return the date as a string
*/

function GetPlaceDate(){
    var ds;
	try{app.menuActions.itemByName('$ID/#LinksUICopyLinkInfoMenu').invoke()}
	catch(e){
		app.menuActions.itemByName('$ID/Links').invoke()
		app.menuActions.itemByName('$ID/#LinksUICopyLinkInfoMenu').invoke()
	}
	app.menuActions.itemByName('$ID/Links').invoke()
	var tmp_tf = app.activeDocument.pages[0].textFrames.add()
	tmp_tf.parentStory.texts[0].select()
	app.paste()
	var tmp_content = tmp_tf.parentStory.contents
	tmp_tf.remove()
	app.menuActions.itemByName('$ID/Selection Tool').invoke()
	for(var i = 0; i < tmp_content.split('\r').length; i++){
		if(tmp_content.split('\r')[i].split('\t')[0] == 'Place Date'){
            ds = tmp_content.split('\r')[i].split('\t')[1]
		}
	}
    return ds
}

 

Votes

Translate

Translate

Report

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
Participant ,
Feb 17, 2021 Feb 17, 2021

Copy link to clipboard

Copied

LATEST

No, that's bad idea.

app.menuActions.().invoke() - simulates user actions manually and takes too long. For example, my retail catalog contains more than 1000 links, above script worked about 30 minutes.

I think you can save time. First save document as .idml, then rename to .zip and unpack. There is "Spreads" folder containing all the link data you need. Parse .xml files as text. If links names contain only numbers and Latin letters, then you will not have problems with the encoding.

Votes

Translate

Translate

Report

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
Participant ,
Feb 06, 2021 Feb 06, 2021

Copy link to clipboard

Copied

hi, i think you can do it, see below code

function GetPlaceDate(){
	try{app.menuActions.itemByName('$ID/#LinksUICopyLinkInfoMenu').invoke()}
	catch(e){
		app.menuActions.itemByName('$ID/Links').invoke()
		app.menuActions.itemByName('$ID/#LinksUICopyLinkInfoMenu').invoke()
	}
	app.menuActions.itemByName('$ID/Links').invoke()
	var tmp_tf = app.activeDocument.pages[0].textFrames.add()
	tmp_tf.parentStory.texts[0].select()
	app.paste()
	var tmp_content = tmp_tf.parentStory.contents
	tmp_tf.remove()
	app.menuActions.itemByName('$ID/Selection Tool').invoke()
	for(var i = 0; i < tmp_content.split('\r').length; i++){
		if(tmp_content.split('\r')[i].split('\t')[0] == 'Place Date'){
			alert(tmp_content.split('\r')[i].split('\t')[1])
		}
	}
}

app.doScript('GetPlaceDate()', ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'GetPlaceDate')

 

Votes

Translate

Translate

Report

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
New Here ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

Hi,

Thanks for the reply. The workaround looks good. But to copy link info, the link has to be selected in Links panel. So let's say there are 10 links then I have to select each one by one and copy/paste link info.

I was thinking how/where link info is stored and if there is any method in the sdk to get place date of link?

Regards,

Narayan

Votes

Translate

Translate

Report

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 Expert ,
Feb 15, 2021 Feb 15, 2021

Copy link to clipboard

Copied

You could write a helper function to select the link and then call the above script, ie: 

 

var ags = app.documents[0].allGraphics;
for (var i = 0; i < ags.length; i++) {
try { 
ags[i].select();
GetPlaceDate();
} catch(e){}
}

 

Could also write a helper function log the result to a .txt or similar. 

Votes

Translate

Translate

Report

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