Extension to offset a path
-
- Posts: 4
- Joined: Fri Oct 28, 2016 11:27 pm
Extension to offset a path
I want to simplify some tasks I have to do. I've been looking through some extensions but haven't been able to find anything on offsetting a path. I realize its a very simple operation to offset a path but I'm wanting to do it several times and with different widths so an extension would help out a lot. Can someone help point me in the right direction how to accomplish this? Thanks in advance.
Re: Extension to offset a path
Welcome to the forum!
You can find several offset options under the Path menu. Do they help or are you after something else?
Path Offset Commands
http://tavmjong.free.fr/INKSCAPE/MANUAL ... hs-Offsets
You can find several offset options under the Path menu. Do they help or are you after something else?
Path Offset Commands
http://tavmjong.free.fr/INKSCAPE/MANUAL ... hs-Offsets
just hand over the chocolate and nobody gets hurt
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
Inkscape Manual on Floss
Inkscape FAQ
very comprehensive Inkscape guide
Inkscape 0.48 Illustrator's Cookbook - 109 recipes to learn and explore Inkscape - with SVG examples to download
-
- Posts: 4
- Joined: Fri Oct 28, 2016 11:27 pm
Re: Extension to offset a path
Thanks for the response. I should have been more precise; I'm trying to make my own extension to automate offsetting a lot of paths. Its hard to find documentation on the extensions so far I've found what I believe is an offset statement in the gcodetools extension.
inkex.etree.SubElement( area_group, inkex.addNS('path','svg'),
{
inkex.addNS('type','sodipodi'): 'inkscape:offset',
inkex.addNS('radius','inkscape'): str(radius),
inkex.addNS('original','inkscape'): d,
'style': styles["biarc_style_i"]['area']
})
This very well may be what I need but I'm having issues passing in the 'd' argument. The gcodetools extension is very elaborate and thorough so its hard for me to decipher everything going on with it. I'll post what I have when I get a chance and maybe someone can help me with my extension.
inkex.etree.SubElement( area_group, inkex.addNS('path','svg'),
{
inkex.addNS('type','sodipodi'): 'inkscape:offset',
inkex.addNS('radius','inkscape'): str(radius),
inkex.addNS('original','inkscape'): d,
'style': styles["biarc_style_i"]['area']
})
This very well may be what I need but I'm having issues passing in the 'd' argument. The gcodetools extension is very elaborate and thorough so its hard for me to decipher everything going on with it. I'll post what I have when I get a chance and maybe someone can help me with my extension.
Re: Extension to offset a path
Yes, the extension produces outsets all with the same value, for filling areas. Is that what you mean?
(What will you do with the different, irregular outsets?)
(What will you do with the different, irregular outsets?)
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Re: Extension to offset a path
d must be the original path data, I believe. What is the problem with inserting it?
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
-
- Posts: 4
- Joined: Fri Oct 28, 2016 11:27 pm
Re: Extension to offset a path
I'm still learning python so it may just be a programming error. Here is what I have
I only have one path in the svg that I'm testing and I dont know an easier way to obtain it other than doing this recursive search which I lifted from another extension. The error message shows that d is 'NoneType' so I'm not actually getting the original path.
Again thanks for the help with this.
Code: Select all
def recursivelyTraverseSvg( self, aNodeList):
for node in aNodeList:
if node.tag == inkex.addNS( 'g', 'svg' ) or node.tag == 'g':
self.recursivelyTraverseSvg( node )
if node.tag == inkex.addNS( 'path', 'svg' ):
return node.get('d')
def effect( self ):
aNodeList = self.document.getroot()
d = self.recursivelyTraverseSvg(aNodeList)
inkex.errormsg('Size of d element:%d' % len(d))
parent = self.current_layer
s = {'stroke':'#000000', 'stroke-width':'1', 'fill':'none', 'stroke-opacity':'1'}
attr = {'style':simplestyle.formatStyle(s),
inkex.addNS('type','sodipodi'): 'inkscape:offset',
inkex.addNS('radius','inkscape'): '5',
inkex.addNS('original','inkscape'): d
}
inkex.etree.SubElement( parent, inkex.addNS('path','svg'), attr)
I only have one path in the svg that I'm testing and I dont know an easier way to obtain it other than doing this recursive search which I lifted from another extension. The error message shows that d is 'NoneType' so I'm not actually getting the original path.
Again thanks for the help with this.
Re: Extension to offset a path
Q1: Extensions have an option to retrieve the currently selected path(s), did you see that? It's self.selected for the inkex.Effect class.
Or is it your intention to apply an offset to *each* path in the document?
Q2: I don't know right now without testing why you get 'None' (well, the indentation looks weird, but I guess that's a copy-paste problem), but couldn't you do some debugging in the recursivelyTraverseSvg method already, to see what's going on? Use inkex.debug("your error message: %s" % your_formatting_data), this won't stop the program from running, but will only pop up messages on the screen.
Maybe it's just a missing import or so. For a good start for retrieving path data, I'd suggest taking a look at the 'Whirl' extension (whirl.py in /usr/share/inkscape/extensions if you're on Linux), which takes a path and modifies its data.
Or is it your intention to apply an offset to *each* path in the document?
Q2: I don't know right now without testing why you get 'None' (well, the indentation looks weird, but I guess that's a copy-paste problem), but couldn't you do some debugging in the recursivelyTraverseSvg method already, to see what's going on? Use inkex.debug("your error message: %s" % your_formatting_data), this won't stop the program from running, but will only pop up messages on the screen.
Maybe it's just a missing import or so. For a good start for retrieving path data, I'd suggest taking a look at the 'Whirl' extension (whirl.py in /usr/share/inkscape/extensions if you're on Linux), which takes a path and modifies its data.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Inkscape FAQ - Learning Resources - Website with tutorials (German and English)
Re: Extension to offset a path
Hello
Are you sure that it is the correct way to retrieve the "d" element?
As Moini says, try this (If I'm not wrong):
Code: Select all
return node.get('d')
Are you sure that it is the correct way to retrieve the "d" element?
As Moini says, try this (If I'm not wrong):
Code: Select all
inkex.debug( node.get('d') )
or
print( node.get('d') )
If you have problems:
1.- Post a sample (or samples) of your file please.
2.- Please check here:
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/index.html
3.- If you manage to solve your problem, please post here your solution.
1.- Post a sample (or samples) of your file please.
2.- Please check here:
http://tavmjong.free.fr/INKSCAPE/MANUAL/html/index.html
3.- If you manage to solve your problem, please post here your solution.
-
- Posts: 4
- Joined: Fri Oct 28, 2016 11:27 pm
Re: Extension to offset a path
Thanks for the help guys the whirl extension gave me what I needed. I would like to be able to run the extension without having to select the path but this is progress for sure. One hurdle down many more to go. Here is the working code:
Code: Select all
def effect( self ):
for id, node in self.selected.iteritems():
if node.tag == inkex.addNS('path','svg'):
d = node.get('d')
inkex.errormsg('Size of d element:%d' % len(d))
parent = self.current_layer
s = {'stroke':'#000000', 'stroke-width':'1', 'fill':'none', 'stroke-opacity':'1'}
attr = {'style':simplestyle.formatStyle(s),
inkex.addNS('type','sodipodi'): 'inkscape:offset',
inkex.addNS('radius','inkscape'): '5',
inkex.addNS('original','inkscape'): d
}
inkex.etree.SubElement( parent, inkex.addNS('path','svg'), attr)