Closed peterennis closed 2 years ago
I'm unable to reproduce this problem with Inkscape 1.1.1 (3bf5ae0, 2021-09-20) on Ubuntu 21.04. However, based on your PDF attachment, I have a guess as to the source of the error you're seeing. I suspect that
The error still occurs without your steps 1 and 2. That is, your new code alone leads to the error.
You upgraded Simple Inkscape Scripting since writing the code that's now failing (or at least since reading the API documentation).
Version 2.0.0 of Simple Inkscape Scripting introduced a number of breaking API changes. Among these, polyline
now accepts a Python list of coordinates rather than individually specified coordinate arguments. The code peeking through in your screenshot's Python code box appears to use the pre-v2.0.0 API. Try wrapping the coordinate arguments to polyline
in square brackets (e.g., polyline((60, 75), (100, 20), (140, 75))
→ polyline([(60, 75), (100, 20), (140, 75)])
).
Does that make the error go away?
Your fix made the error go away.
Result in file:
It does not remove the previous contents.
I am new to python scripting and want to see how it works by copy-paste a lot of small examples such as you provide and iterate from there.
Congratulations and thanks for creating a very useful tool!
Your fix made the error go away.
Great!
It does not remove the previous contents.
- Is there a command to add at the top of the script to start from scratch?
- Can a "Clear" button be added to the window?
I believe the following code can be added to the top of a script to delete all existing content on the page:
for elt in svg_root.xpath('//*'):
if isinstance(elt, inkex.ShapeElement) and not isinstance(elt, inkex.Layer):
elt.getparent().remove(elt)
I created a Clear script as a py file, loaded it and ran apply. The interface shows --and/or-- so I expected the program to run the file "and" follow up with the textbox contents.
However, the screen is cleared but the script in the box does not run.
The script file is here: https://github.com/peterennis/SimpInkScr/commit/9f4d26ceb357cb389c1f7b1f7395051a33c4c706 even if Apply is clicked multiple times.
I continued and started loading your examples to see how they behave.
Maybe some problem with absolute vs. relative path, Clear sample not in examples folder, or Zoom drawing causing redraw to trigger ???
It appears my understanding of --and/or-- is correct but the sequence/setup of my testing is tickling a bug.
I created a Clear script as a py file, loaded it and ran apply. The interface shows --and/or-- so I expected the program to run the file "and" follow up with the textbox contents.
Yes, that's correct.
However, the screen is cleared but the script in the box does not run.
I was indeed able to reproduce this. My hypothesis is that Inkscape is creating a group in which to add the output of a "generate" extension (like Simple Inkscape Scripting) right before running the extension. The sample code then deletes this new group so the generated shapes have no place to go. The following modification of the clear-all code avoids deleting empty groups. Let me know if it works when you try it.
for elt in svg_root.xpath('//*'):
if not isinstance(elt, inkex.ShapeElement):
continue
if isinstance(elt, inkex.Layer):
continue
if isinstance(elt, inkex.Group) and len(elt) == 0:
continue
elt.getparent().remove(elt)
- Loaded the script animation.py, click apply and no text box code was visible.
- Zoom to show all the drawing.
- Load binary_tree.py, click apply, and now the text box content is drawn.
I can't reproduce this behavior at all. However, animation.py
is a bit odd in that it alters the page's width and height so it's believable that some difference between your setup and mine could affect this script's operation. My questions for you are as follows:
animation.py
as the first script?animation.py
to include the line svg_root.set('viewBox', '0 0 1024 768')
right after svg_root.set('height', 768)
?
- Do you observe the same behavior if you use a script other than
animation.py
as the first script?
Looks like it is fixed.
Code here: https://github.com/peterennis/SimpInkScr/commit/1c39c50c4be4ec5557169e6d00e1ae47464960d6
I will add another comment for the second question after more testing.
2. Do you observe the same behavior if you edit
animation.py
to include the linesvg_root.set('viewBox', '0 0 1024 768')
right aftersvg_root.set('height', 768)
?
![Screenshot 2021-12-31 132420](https://user-images.githubusercontent.com /140737/147839254-eab36ac9-65ae-465d-8f90-8d6f9647b16f.png)
If this is as expected, you can close this issue.
I have questions about the animation and will open a new issue.
Happy New Year 🎉
If this is as expected, you can close this issue.
Thanks for testing that. Before I close the issue, though, you had reported that the initial problem was that you "Loaded the script animation.py, click apply and no text box code was visible.". Just to confirm: if animation.py
contains the viewBox
line, then the text-box code is visible, while before it wasn't, right?
Happy New Year to you, too.
No.
- Load animation.py with sketch man in text box, Apply
No viewbox added. Code is still visible in textbox.
3. Add viewbox code to animation.py, Apply
Commit here: https://github.com/peterennis/SimpInkScr/commit/f69df22974fe1df3b20bd6ac06cc285fc1c7e2e6 Code is still visible in textbox.
The screenshots in the last message show this.
It may be some interplay with Clear.py and not repeatable in the scenario above.
I will keep a lookout going forward.
It may be some interplay with Clear.py and not repeatable in the scenario above.
Okay. So should I close the issue or leave it open?
Okay. So should I close the issue or leave it open?
I am closing it.
Thanks
captured in file:
simp_ink_err.pdf
Steps:
Error.
Needs a button to clear the existing script ???