Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link.Relink throws "Cannot create the link resource from the given URI." #12

Closed
sanzoghenzo opened this issue Mar 10, 2021 · 6 comments
Closed

Comments

@sanzoghenzo
Copy link

Hi, thanks a ton for your work!

With the information on this site I was able to put up a python-centric DTP workflow, using invoke, pandoc, lxml and pillow.

Usually the final product is a bulletin with most of the pages in B/W, so I convert and place the b/w images (converted using pillow) in the InDesign file, but recently we need to also have the color version for digital distribution.

I'm trying to automate the switch from B/W to color images (I put them into two separate folders, "images" and "images_bw", so I only need to change the parent folder):

def relink_images(indd_file, source_dir, dest_dir):
    app = win32com.client.Dispatch('InDesign.Application.CC.2017')
    ui_level =  app.scriptPreferences.userInteractionLevel
    # UserInteractionLevels.neverInteract
    app.scriptPreferences.userInteractionLevel = 1699640946
    cur_doc = app.Open(indd_file)
    for link in cur_doc.Links:
        link_path = pathlib.Path(link.filePath)
        if link_path.parent.name == source_dir:
            new_path = link_path.parent.parent / dest_dir / link_path.name
            if new_path.exists():
                print(f"relinking {link_path.name} to {new_path}...")
                try:
                    link.Relink(str(new_path))
                except Exception as err:
                    print(f"Error relinking {new_path}:", err)
            else:
                print(f"No file named {link_path.name} exitst in {dest_dir}")
    cur_doc.save()
    app.scriptPreferences.userInteractionLevel = ui_level

The Link.Relink method raises an exception:

(-2147352567, 'Exception occurred.', (35869, 'C:\\Program Files\\Adobe\\Adobe InDesign CC 2017\\InDesign.exe', 'Cannot create the link resource from the given URI.', None, 0, 0), None)

I saw that other have the same problem with javascript, and solved using the new File() js object (even though the docs states that you can use a string).

Since we don't have access to the File object, what are our options here?

Thanks for the attention!

@Amaretto-Coke
Copy link

@sanzoghenzo Did you ever figure this out? I'm dealing with a similar problem.

@sanzoghenzo
Copy link
Author

Hi @Amaretto-Coke ,
Unfortunately I didn't find a solution for this, and I probably never will since I abandoned this project.
Good luck!

@Amaretto-Coke
Copy link

@sanzoghenzo Thanks for the reply. I'll continue troubleshooting, maybe there's a workaround. I'll post here if I find anything.

@Amaretto-Coke
Copy link

@sanzoghenzo Putting "file:" in front of the path seemed to do the trick for me.

@marklani
Copy link

@sanzoghenzo Putting "file:" in front of the path seemed to do the trick for me.

This seemed to work for me as well. i.e
file:C:\Path\Path\Path

@sanzoghenzo
Copy link
Author

Good to know! Closing this, but this info could be made into an example if someone is willing to do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants