I have a problem where when I run my extension from the GUI i get the error:
Traceback (most recent call last): File "my_first_extension.py", line 3, in <module> class MyFirstExtension(inkex.EffectExtension): AttributeError: 'module' object has no attribute 'EffectExtension'
But when I run Python3 in the terminal inkex has EffectExtension
Python 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import inkex >>> inkex.EffectExtension <class 'inkex.extensions.EffectExtension'> >>>
Here are my my_first_extension.inx and my_first_extension.py
class MyFirstExtension(inkex.EffectExtension): def effect(self):
# Get current selection element list current_selected = self.svg.selected # Make sure at least one object is selected otherwise return if len(current_selected) > 0: for elem in current_selected: elem.style['fill'] = 'red' else: return
Hello,
I have a problem where when I run my extension from the GUI i get the error:
Traceback (most recent call last):
File "my_first_extension.py", line 3, in <module>
class MyFirstExtension(inkex.EffectExtension):
AttributeError: 'module' object has no attribute 'EffectExtension'
But when I run Python3 in the terminal inkex has EffectExtension
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inkex
>>> inkex.EffectExtension
<class 'inkex.extensions.EffectExtension'>
>>>
Here are my my_first_extension.inx and my_first_extension.py
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>My First Extension</_name>
<id>org.inkscape.effect.my_first_extension</id>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="TEST"/>
</effects-menu>
</effect>
<script>
<command reldir="extensions" interpreter="python">my_first_extension.py</command>
</script>
</inkscape-extension>
import inkex
class MyFirstExtension(inkex.EffectExtension):
def effect(self):
for elem in self.svg.get_selected():
elem.style[fill] = 'red'
o = MyFirstExtension()
o.run()
Any help would be appreciated
Can you replace
o = MyFirstExtension()
o.run()
with
if __name__ == '__main__':
MyFirstExtension().run()
https://gitlab.com/inkscape/extensions/-/wikis/home
switching to
if __name__ == '__main__':
MyFirstExtension().run()
did not help it. But i am going to try to run the examples from gitlab and see what happens.
In Ubuntu 20.10 with Inkscape 1.1:
This will work:
.inx
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>My First Extension</name>
<id>org.inkscape.effect.my_first_extension</id>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="TEST"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">my_first_extension.py</command>
</script>
</inkscape-extension>
.py
import inkex
class MyFirstExtension(inkex.EffectExtension):
def effect(self):
# Get current selection element list
current_selected = self.svg.selected
# Make sure at least one object is selected otherwise return
if len(current_selected) > 0:
for elem in current_selected:
elem.style['fill'] = 'red'
else:
return
o = MyFirstExtension()
o.run()