question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

How can I modify a source attribute in a designspace file? I'm so close!

See original GitHub issue

Iā€™m not sure if this is the right place to ask a usage question, but the forum mentioned in the contribution guidelines is either down or doesnā€™t exist (https://github.com/fonttools/fonttools/issues/1629). Iā€™m also not able to find anything through Google. However, please let me know if I should move elsewhere with this question.


How I might set source filename attributes in a designspace file?

Context:

I have a script that takes in a designspace file and preps sources for interpolation into a prototype variable font by simply copying the UFOs into a timestamped folder and chucking out all incompatible glyphs. This is a ā€œstupidā€ way to prep fonts for building, but itā€™s pretty useful to allow me to check a variable font in browsers, etc, well before it the project has been totally finished.

However, this script currently only works if the designspace only points to UFOs in its own, same directory. Iā€™d like to be able to go through and update the filename attribute of sources to correctly point to the new timestamped folder, if they have been copied in from other directories. But, once I have set source attributes to edited values, Iā€™m having trouble making the attributes ā€œstickā€ while I write a new designspace file.

Hereā€™s my current copy and edit function (from here):

def copyDesignSpace(designspacePath):

    # duplicate designspace into new folder
    inputDStail = os.path.split(designspacePath)[1]
    outputDSpath = newFolderPath + "/" + inputDStail

    shutil.copyfile(designspacePath, outputDSpath)

    # update source & instance paths in designspace as needed
    outputDS = DesignSpaceDocument.fromfile(outputDSpath)

    for source in outputDS.sources:
        print(source.filename)  # prints the original value

        fontFilename = os.path.split(source.path)[1]
        setattr(source, 'filename', fontFilename)

        print(source.filename)  # this does change to the value I want

    # this doesn't overwrite the designspace file...
    outputDS.write(outputDSpath.replace(
        ".designspace", ".prepped.designspace"))


copyDesignSpace(designspacePath)

I think Iā€™m close, but just missing something. If I find it, Iā€™ll update this thread. If someone else is able to point out what Iā€™m missing, I would really appreciate the nudge in the right direction!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
arrowtypecommented, Jul 22, 2021

This just came in handy. Thanks for asking this question, past me! And thanks again to Just for his help in answering it. šŸ¤˜

1reaction
justvanrossumcommented, Jun 4, 2019

You can replace

setattr(source, 'path', newFontPath)

by

source.path = newFontPath

Read more comments on GitHub >

github_iconTop Results From Across the Web

designspaceLib: Read, write, and edit designspace files
The filename attribute in the SourceDescriptor and InstanceDescriptor classes stores the preferred relative path.
Read more >
Update varLib to current designspace spec Ā· Issue #916 - GitHub
File "/home/sascha/src/fontmake/Lib/fontmake/font_project.py", line 200, ... And even then, I'm not hardcoding any of that in code.
Read more >
How to Edit Text in Cricut Design Space - YouTube
Use the text editing panel to create the perfect text for your Cricut Design Space project. ... Your browser can't play this video....
Read more >
Design Space - Edit Bar - Cricut - Help
The Edit bar in Design Space gives you access to features such as Linetype, Fill, Size, ... Cut attributes - available when the...
Read more >
What Do Weld, Attach, & Group mean on Cricut
Attaching allows you to keep all of the ā€“ attached ā€“ layers together. This means that when you send your project to cut,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found