Comments (7)
hello @abey79 I found this issue while trying to find a way to run basic vpype commands from Inkspace.
It shouldn't be too hard, but if possible, I wish I wouldn't start from scratch. Have you given the idea a try?
from vpype.
@haschdl no I haven't.
I did recently add an API function wrapper to vpype's core that would come in handy: https://vpype.readthedocs.io/en/stable/api/vpype_cli.html#vpype_cli.execute
The way I think things should be going is as follows:
import vpype as vp
from vpype_cli import execute
doc = vp.Document()
doc.add(....) # populate document with Inkscape vectors
doc = vp.execute("linesort linemerge linesimplify", doc) # pipeline should come from UI
for layer_id in doc:
for line in doc[layer_id]:
... # put line back into inkscape
The main complexity is that vpype accepts only polylines, so all curved elements will have to be sampled (ideally with a selectable accuracy). In vpype, this is actually done in svgelements, a project to which I contributed parallelised discretisation functions (these are in the various shapes' npoint()
methods, eg QuadraticBezier.npoint().
If you want to give this a shot, I'll happily make myself available if you have questions or need help. If you haven't already, I suggest joining the drawingbots.net's discord server.
from vpype.
It might be relevant to mention that I only use a limited set of vpype’s features, namely the optimization and layouting features. I do not use the drawing features. Most of the time, I generate my SVG in Processing, and sometimes do clean-ups in Illustrator, in Inkscape or using vpype. Axidraw plot optimization has let me down many times, so I want to incorporate vpype to my workflow.
With that said, l just put together some spaghetti code in which I experimented with a Inkscape extension calling vpype client - I wasn’t aware of the API! it’s basically and xml describing the extension, and an accompanying bash script to call vpype.
Calling the cli worked after a few attempts. It was a simple use case calling linesort, and it worked!
The extension framework for Inkscape works so that it passes a path to a temp file to the extension.
With this in mind, do you still think the API via Python should the way to go? It sounds more robust and testable! Could the API simply handle the input as a file, in similar way as the client? I didn’t get why I would need to create a vp.Document
Inkscape runs your script (optionally with an interpreter, more info here: Extension Interpreters), passing it any number of parameters in long GNU style. The final argument is the name of the temporary SVG file your script should read. After processing, the script should return the modified SVG file to Inkscape on STDOUT.
from vpype.
It might be relevant to mention that I only use a limited set of vpype’s features, namely the optimization and layouting features. I do not use the drawing features
Do you plan to have a detailed GUI or just a text field where the user would type commands? A mix of both would make it easy to run the usual optimisation commands (your use case sounds rather typical) and a text field would enable more specific scenarios.
The extension framework for Inkscape works so that it passes a path to a temp file to the extension. With this in mind, do you still think the API via Python should the way to go? It sounds more robust and testable! Could the API simply handle the input as a file, in similar way as the client? I didn’t get why I would need to create a vp.Document.
I didn't know that Inkscape API worked that way. It sounds rather inefficient to me be it certainly makes our life easier. For the execute()
API, you have two choices that are nearly 100% equivalent:
# option A
doc = vp.read_multilayer_svg(temp_file_path, quantization=0.1)
doc = vp.execute("linemerge ...", doc)
# option B
doc = vp.execute(f"read {temp_file_path} linemerge ...")
Full docs for both approaches:
https://vpype.readthedocs.io/en/stable/api/vpype.html#vpype.read_multilayer_svg
https://vpype.readthedocs.io/en/stable/reference.html#read
from vpype.
from vpype.
I will share something here once I’m have a working example!
Nice. I can't recommend enough joining the discord server I mentioned. I know there are plenty of people would will be interested in this.
from vpype.
Hey there,
i did my best coding last days to implement vpype into InkScape. It's not complete but a lot of things are already working. Happy to get your feedback and maybe some more code :-)
code: https://gitea.fablabchemnitz.de/MarioVoigt/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/vpypetools
docs: https://stadtfabrikanten.org/display/IFM/vpypetools and sub-pages
regards, Mario
from vpype.
Related Issues (20)
- `read` entirely discards file containing NaN
- Is there a way to use vpype to count the number of lines/paths in an svg file? HOT 1
- Pyside 6.5.0 breaking changes (Linux) HOT 1
- Enhancement suggestion -- allow getting document width/height in non-pixel units HOT 2
- Change the layer ID interpretation to match EMSL standard HOT 1
- `--fit-to-margins` adds boarder around margin HOT 1
- Curved Line Spacing Problem HOT 4
- Allow for `layout` arg to maintain size of svg element
- Output error messages when using `execute` from vpype API HOT 4
- Cursive font glyphs are split in multiple strokes HOT 2
- Examples in `lreverse`'help are wrong
- Add support for various stroke font format
- Remove mentions of `--page-size` in `layout` help
- Extra layer when running two read/writes within one pipeline HOT 1
- Color overwritten using dipping pattern recipe
- Request: linemerge option to only merge when turn angle is small HOT 1
- Is there a way to tostring() a Document? HOT 1
- Simplification fails in my installation (vpype read -s <svg_file>) HOT 1
- VirusTotal
- Site-packages pollution from README
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vpype.