Skip to main content
Inspiring
March 21, 2023
Answered

[SCRIPT] Place an invalid file or create a link with LINK_MISSING state

  • March 21, 2023
  • 4 replies
  • 1072 views

I'd like to link some objects with the files that are not accessible at the moment of editing.

 

Is it possible to place an invalid file object into a container? If not, are there any ways to add a link to a document without using `place()`? I couldn't find any methods to create an empty `link` object by hand.

The following doesn't work:

place(file, withProperties = {error: ""})

inDesign allows for invalid links to exist, file objects can refer to non-existent files, but `place` always gives an error if the filepath doesn't resolve to a valid file.

 

Thanks.

This topic has been closed for replies.
Correct answer 28990177

Have you tried actually implementing my suggestion? After you place the placeholder then call reinitLink , the path info should change to your pending path info and be missing. 


Thanks a lot, brianp311, it works. I've been setting the URI string incorrectly when I tried it.

The desired state is reachable, after all, that's how it should be. Not without a hack, but still. Anyway, sorry for raising the fuss.

 

// Setting link's `filePath` to an arbitrary path using a dummy file to initialise the link

const doc = app.activeDocument;
const r = doc.pages[0].rectangles.add();
r.place("c:/dummy.png");
doc.links[0].reinitLink("file:c:/nofilehere.png");

 

4 replies

Peter Kahrel
Community Expert
Community Expert
March 22, 2023

How do you envisage creating a link to a graphic that doesn't exist? That InDesign maintains a link when a graphic after it has become unavailable is good, so that you can relink it.

 

Brian's suggestion (create a link to a placeholder graphic and relink when the graphic becaomes available) or mine (enter a string denoting the link and create the link when the graphic becomes available) seem perfectly sound workarounds.

28990177Author
Inspiring
March 22, 2023

> How do you envisage creating a link to a graphic that doesn't exist?

 

The same way we create anything: `Link` is just an object in memory, create it and fill the `filePath` with a desired string, leverage the existing functionality to deal with it as you wish.

brian_p_dts
Community Expert
Community Expert
March 22, 2023

Have you tried actually implementing my suggestion? After you place the placeholder then call reinitLink , the path info should change to your pending path info and be missing. 

28990177Author
Inspiring
March 22, 2023

Adding placeholders for later re-editing is a bit silly, as it's reimplementing the existing functionality of the program (tracking of the linked sources).

Relinking doesn't help, as far as I see, any update of the path leads to the program checking the file exists.

 

I consider this a bug:

1. There's a correct working state of the program and it can't be reached via scripting.

2.This prevents collaboration - a person working on a document might not have the access to the source files placed.

3. This behaviour of `place` amd `relink` is undocumented and goes against the behaviour of other parts of the API, such as `File`.

 

Robert at ID-Tasker
Legend
March 22, 2023

How inability to place something that doesn't exist is a bug ?? 

 

The only solution for you is to create temporary representation of the file, place it and then delete the original. 

 

But if you don't know what the file would be - size, type, etc... 

 

28990177Author
Inspiring
March 22, 2023

I've mentioned 3 reasons already. Another one: this is a hard panic which breaks the script, there's no way to manage the error on the script's side. Again, the main reason: ok, the function can raise an error, but the state is absolutely valid, it's representable by a program no problem, it's just unreachable through the API without hacks. All the `path` properties are readonly, there's no link creation routines.

 

I'm already outputting a dummy image the same as you suggested, but it's a dirty hack and write-accessing the FS from a script is something to be avoided, IMO.

brian_p_dts
Community Expert
Community Expert
March 21, 2023

I think we've discussed this before, and that link.reinitLink(File) would allow you to reinitialize a link even if it's missing. But I haven't checked. Edit: you'd have to probably place a valid link file (placeholder) then reinit the link. Not sure. 

Peter Kahrel
Community Expert
Community Expert
March 21, 2023

The only thing you can do is to add placeholders for the graphics and create the links later (with a script, probably). Make your placeholders easily recognisable, something like <<xyz.png>>.