spakin / SimpInkScr

Simple Inkscape Scripting
https://inkscape.org/~pakin/%E2%98%85simple-inkscape-scripting
GNU General Public License v3.0
330 stars 32 forks source link

apply_path_operation not consistent? #112

Closed charely6 closed 11 months ago

charely6 commented 11 months ago

So I'm trying to make a weird shape with a curved cut out using the apply_path_operation 'difference' and it was originally working but after I rewrote the code so I could use the actual shapes in their final location to resize the canvas and then turn them into paths it now won't order it correctly. I have attached the script I have made (renamed to .txt so it will take it.) if you comment out line 75 you can kind of see what my goal was visually but no matter the order I put the outlins in the apply_path_operations command it always just makes the little half circle like things instead.

InkscapeBox.txt image

charely6 commented 11 months ago

image I realized I could add a screenshot of what it was suppose to look like. the goal was the opposite of the ear things the in the previous image.

spakin commented 11 months ago

If I comment out line 75 but then manually perform a PathDifference in Inkscape, I see the image illustrated in your initial post. Hence, I believe Simple Inkscape Scripting is behaving correctly. I just need to understand better what you're trying to achieve in order to offer advice on how to achieve it.

In the screenshot of what the shape is supposed to look like, could you color-code what the separate shapes are supposed to be, even by manually editing the screenshot? That is, without line 75, I might color outLine red and slots blue: original If I select both the red and blue shapes and select PathExclusion, for example, I wind up with the red shape merged into the blue shape: exclusion If you can draw something similar for your desired final shapes, I'll try to offer a suggestion on how to produce that with Simple Inkscape Scripting.

charely6 commented 11 months ago

280936664-4f9716ef-10e8-4cee-af42-ba1381496034~2.png

so basically this is what I wanted (sorry it looks rough I'm on mobile) I'm trying to generate svgs for cricut cutting boxes. my earlier attempt looked right but after I exported the svg the dimensions were screwed up.

spakin commented 11 months ago

Thanks; that helps.

When it comes to path operations, Simple Inkscape Scripting works like Inkscape itself in that it doesn't matter in what order you select the paths; what matters is which object is on top. That explains why "no matter the order I put the outlins in the apply_path_operations command it always just makes the little half circle like things instead": you're doing the equivalent of selecting the paths in different orders without changing their stacking.

Solution: Lift the slots to the top before differencing the paths:

slots[0].z_order('top')
outLineWithSlot1 = apply_path_operation('difference', outLine +slots )
charely6 commented 11 months ago

ah... okay that makes sense, I'll have try that. is there something similar in the scripting with shapes that I missed? or is there a way to duplicate the path after I've done all the opperations on it

spakin commented 11 months ago

ah... okay that makes sense, I'll have try that. is there something similar in the scripting with shapes that I missed?

I don't understand what you're asking here.

or is there a way to duplicate the path after I've done all the opperations on it

Yes. See https://github.com/spakin/SimpInkScr/wiki/Copying-objects

charely6 commented 11 months ago

so I wanted to be able to combine like I did using the path operations but keeping it as shapes. and I tried copying it as a path object and it didn't work. I didn't want to copy it as a shape and then do the path operations twice (seeing as they have to spawn a new instance of inkscape to happen)

On Wed, Nov 8, 2023 at 9:05 PM Scott Pakin @.***> wrote:

ah... okay that makes sense, I'll have try that. is there something similar in the scripting with shapes that I missed?

I don't understand what you're asking here.

or is there a way to duplicate the path after I've done all the opperations on it

Yes. See https://github.com/spakin/SimpInkScr/wiki/Copying-objects

— Reply to this email directly, view it on GitHub https://github.com/spakin/SimpInkScr/issues/112#issuecomment-1803091925, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADRRINOI6O5XCTCYJ6B4OOLYDRCA3AVCNFSM6AAAAAA65EPP5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMBTGA4TCOJSGU . You are receiving this because you authored the thread.Message ID: @.***>

-- Sincerely Cody Christensen

spakin commented 11 months ago

There's no equivalent of path operations for shapes. A script needs to call .to_path() on each shape to convert it to a path, like your script already does.