I am just learning Processing to make files for the Axidraw. I have figured out my best workflow in terms of saving SVGs but just hit a snag. I am using simplified code for this example here using one line (but in the files I have problems with it is hundreds of lines), but basically if I tell the program to draw a line (or ellipse or whatever) that has coordinates outside of the designated canvas size (any negative x- or y-value), it still draws and exports all that is outside.
This is an example. If I save this SVG by pressing âeâ and open it in Inkscape, I get the bounding box with an intersecting line that starts at (-50,0). Is there an easy way to have Processing save only what is inside of the canvas?
However, in Inkscape (or I imagine if I opened in Illustrator) it looks like this (attaching the screenshot). Problem is Axidraw will plot the whole line unless of course I put it off the actual page but I like to keep stuff centered:
Processing did what you asked it to do; ie line has a negative value for x1. The only solution I can think of is to constrain the value of x1 to a positive value. That might require creating a Line class, then constrain line.x1 to min >0. https://processing.org/examples/constrain.html
I am super new to this. Classes are really hard for me to understand still.
I donât understand how to constrain it without shifting the entire line. If I constrain the x-value then the line start point would move to (0,0) and draw a totally different line.
Yes thanks! I have done the Processing one in Learning Processing book a few times. It is one of those chapters, I will be reading again and again. I also need to watch the videos a few timesâŚand you also mention arrays which happen to be the other thing I struggle with! Everything made sense basically until I got to these two things. I just need more time to digest.
But I guess, with my rudimentary understanding of objects and classes, I am still unsure how it would help me in this case. What would the specific code even be?
In my testing Inkscape will always show the entire length of the line regardless of what is visible in the .svg image. Constraining x1 to > 0 does change the pitch of the line (as you surmised) even if you learn how to use classes, at least in the demo that I tried. If you are committed to Inkscape then there may not be a solution to your problem.
I figured out the long version to solve my problem in Inkscape itselfâbasically cropping the lines in there using my bounding box that I print to the SVG.
However, cropping an SVG is not so easy ha. And I seem to only manage to do it right 1/2 times. Hopefully, this skill at least will get better.
(btw how do I delete a post on here since my duplicate one became unhidden? I really feel like an idiot that I canât figure it outâŚ)
I just tried this. I get the same thing unfortunately, only now I get the addition of a clip path bounding box however the lines still can and do start outside of the box and the pen plotter will still print them.
I found that if I select everything I want to âcropâ in Inkscape
then make sure to select âObject to Pathâ
then select everything not in rectangle and âcombineâ
then select rectangle and select âcut pathâ it will cut where the rectangle intersects and I can delete the outside lines
Your described Inkscape procedure is different from the one that I used, described in the above reference as âClip Using Shapesâ. The author imports the .svg image into the editor first, then selects a shape to overlie it (likely a rectangle) and after selecting both objects uses menu item Object/Clip/Set to trim what you donât want to print. It seemed to work pretty easily after explicitly following the guidelines.
Clipping doesnât work for pen plotting. For many outputs, it is a great way to crop, however, for the pen plotter the paths are still there and will still be plotted. Effectively clip tells Inkscape not to display outside of the shape, but it doesnât remove the paths. The pen plotter (or laser cutter or whatever) will plot all the paths.
In display mode, the clip works perfectly.
If you choose âoutlineâ mode under View/Display mode it looks like nothing happened after using clip.