More convenience for create links extension

This commit is contained in:
Mario Voigt 2021-04-13 23:24:50 +02:00
parent a07d72dcbf
commit 965f5dbb0a
2 changed files with 35 additions and 18 deletions

View File

@ -9,6 +9,11 @@
<option value="closed_paths">closed paths</option>
<option value="both">both</option>
</param>
<param name="creationtype" type="optiongroup" appearance="combo" gui-text="Creation">
<option value="use_existing">Existing dash style from element</option>
<option value="custom_dasharray">Custom dash pattern</option>
<option value="entered_values">Render by unit and link settings</option>
</param>
<param name="unit" type="optiongroup" appearance="combo" gui-text="Units">
<option value="mm">mm</option>
<option value="cm">cm</option>
@ -18,14 +23,16 @@
<option value="pc">pc</option>
<option value="percent">%</option>
</param>
<label appearance="header">Creation: Link Settings</label>
<param name="link_count" type="int" min="1" max="9999" gui-text="Link count">1</param>
<param name="length_link" type="float" min="0.000" max="9999.000" precision="3" gui-text="Link length (the length of the gap)">1.000</param>
<param name="link_multiplicator" type="int" min="0" max="9999" gui-text="Link multiplicator (experimental)" gui-description="If set, we create a set of multiple gaps of same size next to the main gap">0</param>
<param name="link_offset" type="float" min="-9999.000.000" max="9999.000" precision="3" gui-text="Link offset (+/-) (experimental)" gui-description="Does not properly work the intended way if link count is more than 1.">0.000</param>
<param name="length_filter" type="bool" gui-text="Enable path length filtering">false</param>
<param name="length_filter_value" type="float" min="0.000" max="9999.000" precision="3" gui-text="Paths with length more than">0.000</param>
<param name="custom_dasharray" type="bool" gui-text="Enable custom dash pattern">false</param>
<param name="link_offset" type="float" min="-9999.000.000" max="9999.000" precision="3" gui-text="Link offset (+/-)">0.000</param>
<label appearance="header">Creation: Custom Dash Pattern Settings</label>
<param name="custom_dasharray_value" type="string" gui-text="Dash pattern" gui-description="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.">10 5</param>
<label appearance="header">Other Settings</label>
<param name="length_filter" type="bool" gui-text="Enable path length filtering (uses always document's unit)">false</param>
<param name="length_filter_value" type="float" min="0.000" max="9999.000" precision="3" gui-text="Paths with length more than">0.000</param>
<param name="keep_selected" type="bool" gui-text="Keep selected elements">false</param>
<param name="breakapart" type="bool" gui-text="Break apart output paths" gui-description="Performs CTRL + SHIFT + K to break the new output path into it's parts">false</param>
<param name="show_info" type="bool" gui-text="Print some length and pattern information" gui-description="Warning: might freeze InkScape forever if you have a lot of nodes because we create too much print output. Use for debugging only!">false</param>

View File

@ -43,15 +43,15 @@ class LinksCreator(inkex.EffectExtension):
super(LinksCreator, self).__init__()
self.arg_parser.add_argument("--main_tabs")
self.arg_parser.add_argument("--path_types", default="closed_paths", help="Apply for closed paths, open paths or both")
self.arg_parser.add_argument("--creationtype", default="entered_values", help="Creation")
self.arg_parser.add_argument("--unit", default="mm", help="Units")
self.arg_parser.add_argument("--link_count", type=int, default=1, help="Link count")
self.arg_parser.add_argument("--length_link", type=float, default=1.000, help="Link length")
self.arg_parser.add_argument("--link_multiplicator", type=int, default=1, help="If set, we create a set of multiple gaps of same size next to the main gap")
self.arg_parser.add_argument("--link_offset", type=float, default=0.000, help="Link offset (+/-). Does not properly work the intended way if link count is more than 1.")
self.arg_parser.add_argument("--link_offset", type=float, default=0.000, help="Link offset (+/-).")
self.arg_parser.add_argument("--custom_dasharray_value", default="", help="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.")
self.arg_parser.add_argument("--length_filter", type=inkex.Boolean, default=False, help="Enable path length filtering")
self.arg_parser.add_argument("--length_filter_value", type=float, default=0.000, help="Paths with length more than")
self.arg_parser.add_argument("--custom_dasharray", type=inkex.Boolean, default=False, help="Enable custom dash pattern")
self.arg_parser.add_argument("--custom_dasharray_value", default="", help="A list of separated lengths that specify the lengths of alternating dashes and gaps. Input only accepts numbers. It ignores percentages or other characters.")
self.arg_parser.add_argument("--keep_selected", type=inkex.Boolean, default=False, help="Keep selected elements")
self.arg_parser.add_argument("--breakapart", type=inkex.Boolean, default=False, help="Performs CTRL + SHIFT + K to break the new output path into it's parts")
self.arg_parser.add_argument("--show_info", type=inkex.Boolean, default=False, help="Print some length and pattern information")
@ -141,7 +141,7 @@ class LinksCreator(inkex.EffectExtension):
dashes.append(length_link) #stroke (=gap)
dashes.append(length_link) #gap
if self.options.custom_dasharray is True:
if self.options.creationtype == "custom_dasharray":
try:
floats = [float(dash) for dash in re.findall(r"[-+]?\d*\.\d+|\d+", self.options.custom_dasharray_value)]
if len(floats) > 0:
@ -152,18 +152,24 @@ class LinksCreator(inkex.EffectExtension):
inkex.errormsg("Error in custom dasharray string (might be empty or does not contain any numbers). Using regular input instead ...")
stroke_dasharray = ' '.join(format(dash, "1.3f") for dash in dashes)
stroke_dashoffset = self.svg.unittouu(str(self.options.link_offset) + self.options.unit)
if self.options.unit == "percent":
stroke_dashoffset = self.options.link_offset / 100.0
else:
stroke_dashoffset = self.svg.unittouu(str(self.options.link_offset) + self.options.unit)
if self.options.show_info is True:
inkex.utils.debug("node " + node.get('id'))
if self.options.unit == "percent":
inkex.utils.debug("total path length = {:1.3f} {}".format(stotal, self.svg.unit)) #show length, converted in selected unit
inkex.utils.debug("(calculated) offset: {:1.3f} %".format(stroke_dashoffset))
inkex.utils.debug("(calculated) gap length: {:1.3f} %".format(length_link))
else:
inkex.utils.debug("total path length = {:1.3f} {} ({:1.3f} {})".format(self.svg.uutounit(stotal, self.options.unit), self.options.unit, stotal, self.svg.unit)) #show length, converted in selected unit
inkex.utils.debug("(calculated) offset: {:1.3f} {}".format(self.svg.uutounit(stroke_dashoffset, self.options.unit), self.options.unit))
inkex.utils.debug("(calculated) gap length: {:1.3f} {}".format(length_link, self.options.unit))
inkex.utils.debug("total gaps = {}".format(self.options.link_count))
inkex.utils.debug("(calculated) gap length: {:1.3f} {}".format(length_link, self.options.unit))
inkex.utils.debug("(calculated) dash/gap pattern: {} ({})".format(stroke_dasharray, self.svg.unit))
inkex.utils.debug("(calculated) dash offset: {:1.3f} {}".format(self.svg.uutounit(stroke_dashoffset, self.options.unit), self.options.unit))
inkex.utils.debug("--------------------------------------------------------------------------------------------------")
# check if the node has a style attribute. If not we create a blank one with a black stroke and without fill
@ -242,14 +248,18 @@ class LinksCreator(inkex.EffectExtension):
#self.svg.selection.set(replacedNode.get('id')) #update selection to split paths segments (does not work, so commented out)
if len(self.svg.selected) > 0:
for node in self.svg.selection.filter(PathElement).values():
#at first we need to break down combined nodes to single path, otherwise dasharray cannot properly be applied
breakInputNodes = self.breakContours(node)
for breakInputNode in breakInputNodes:
createLinks(breakInputNode)
pathNodes = self.svg.selection.filter(PathElement).values()
if len(pathNodes) > 0:
for node in pathNodes:
#at first we need to break down combined nodes to single path, otherwise dasharray cannot properly be applied
breakInputNodes = self.breakContours(node)
for breakInputNode in breakInputNodes:
createLinks(breakInputNode)
else:
inkex.errormsg('Selection does not contain any paths to work with. Maybe you need to convert objects to paths before.')
return
else:
inkex.errormsg('Please select some objects first.')
inkex.errormsg('Please select some paths first.')
return
if __name__ == '__main__':