I have an extension I am writing to create a line, copy it and rotate the copy. I need to swap the beginning node with the end node of the copy before rotating. How can I accomplish this?
I am brand new to this, so this might not be the best way to do this... and yes, I actually want to swap the beginning and ending nodes. Same as doing a horizontal or vertical flip.
I have an extension I am writing to create a line, copy it and rotate the copy. I need to swap the beginning node with the end node of the copy before rotating. How can I accomplish this?
Thank you,
Can you give more information.
When you say 'line' do you mean a path with just two points - or any type of path ?
Swapping the beginning and end nodes - do you mean to really swap the nodes, or change the centre of rotation ?
Can give an example of before and after what you want to achieve ?
I am brand new to this, so this might not be the best way to do this... and yes, I actually want to swap the beginning and ending nodes. Same as doing a horizontal or vertical flip.
layer = self.svg.get_current_layer()
elem1 = layer.add(inkex.PathElement())
elem1.update(
**{
"style": style,
"inkscape:label": name,
"d": "M "
+ str(x1)
+ ","
+ str(y1 - y2)
+ " L "
+ str(x1)
+ ","
+ str(y1)
+ " z"
} )
Swapping the start and end nodes will not flip the object.
It will just reverse the path direction. Like travelling to B to A instead of A to B.
You would need to flip the x or flip the y values of the start and end points as needed.
You could write a little function to do that, and return flipped x or flip y.
This approach would only work however for a path made from two points ( a straight line )
Normally in SVG documents, flipping is achieved by applying a transform instead of dealing with the points.
Also the 'z' you have at the end of the statement - that is to close the path, not needed for a straight line.
I made an example here with a menu - my coding style is not very pythonic, but it works lol.
https://gitlab.com/inklinea/flip-path
In the example - I just made a function to flip the points in a list, then generate a new path for each change.
If you want to manipulate existing paths - then that is different to just building the 'd' attribute and updating.
https://inkscape.gitlab.io/extensions/documentation/source/inkex.paths.html
Thank you so much. That helped a lot.