Closed WilliamTylerBradley closed 10 months ago
I'm not a regular Visual Studio Code user, but I did just install it, and I was able to reproduce this problem.
I believe I have a solution, but I'll need your help testing it. First, remove the
from simpinkscr import *
line from your script. Second, configure your project's launch.json
file to run Simple Inkscape Scripting itself, passing it your script name and other arguments:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "/home/user/.config/inkscape/extensions/simple_inkscape_scripting/simpinkscr/simple_inkscape_scripting.py",
"args": ["--py-source=${file}", "--output=/home/user/my-output.svg", "/home/user/.config/inkscape/templates/default.svg", "75", "50", "chartreuse"],
"console": "integratedTerminal",
"justMyCode": true
}
]
}
Does that work when you try it? If so, I'll update the wiki page accordingly.
While I did get everything running, I wouldn't use this setup. I'm not getting the IntelliSense working on the Python file after taking out the from simpinkscr import *,
and that's the main goal for this issue. Using launch.json
is more work than using the terminal in Visual Studio Code. So, I think I'd use that instead. (I don't need IntelliSense working to use this extension, but it would be great to have.)
I'm not getting the IntelliSense working on the Python file after taking out the from simpinkscr import *, and that's the main goal for this issue.
My apologies. I was so focused on getting Visual Studio Code working with Simple Inkscape Scripting that I forgot that the whole point was to work with IntelliSense.
I believe I have a partial solution. Try importing simpinkscr
only if its symbols are not already loaded:
try:
rect
except NameError:
from simpinkscr import *
This should prevent the AttributeError: 'NoneType' object has no attribute 'append_obj'
error you were observing because Simple Inkscape Scripting's symbols no longer will be spread across multiple Python namespaces. However, IntelliSense seems to work in a degraded mode. By that, I mean that name completion works and Ctrl-Space correctly presents Simple Inskcape Scripting function prototypes, but Visual Studio Code no longer shows which parameter you're typing as you're typing it.
Is that an acceptable approach?
This works great for me. I think Ctrl-Space provides enough information.
As a side note, if you use:
try:
rect
except NameError:
import simpinkscr
simpinkscr.rect(...
the parameters show. I don't know why this why works, but the other doesn't.
I can add this into the documentation if you want.
Although I too see the parameters when I use that construct, the AttributeError
has returned as well. Do scripts using that approach work when you run them?
I can add this into the documentation if you want.
Thanks, but I just added some text: https://github.com/spakin/SimpInkScr/wiki/Running#visual-studio-code
Does that accurately cover the key parts of our discussion?
I do get an error, but I think that was listed in the previous version of the documentation. So it was expected.
The current documentation lists the approach that works for me. I think this issue can be closed if you are good with that. Thanks, I really appreciate it!
I'm getting an error message with the following code and running it through the command line in Visual Studio Code:
This is the same example from Command-line execution with
from simpinkscr import *
added at the front to get IntelliSense working.The error message is:
I can't replicate the error if I change
from simpinkscr import *
toimport simpinkscr
,import numpy
, orfrom numpy import *
. The basic example without adding in any packages also works fine. So, I think there's something catching in the code when everything is imported fromsimpinkscr
, but I'm not sure what exactly is happening.How can I get this code working? Or is there a better method to use Visual Studio Code?