SVG output script

Thanks for replying i got the exact shape option mention above. But the color differ. I want the viewport shading to be match. https://imgur.com/gallery/hPwSQyK Any other option or suggestion to get the viewport shading.

Hi Liero.

For me (person who loves Illustrator) it’s awesome scrip! Thank you.
I’m new in Blender. Yesterday I installed first time 2,79, today I discovered 2,8 version of Blender. I’m wondering is possible to fit script to 2.8 version?

I second that request… I use this tool a lot in my job so porting it over to 2.8 would make my life so much easier.

sure guys, here’s a basic update to make it work in 2.80, expect no other changes

https://www.dropbox.com/s/keur0yo5w4ipohw/export_svg_280.py?dl=1

send me a message if there’s something that worked before and seems broken now, but remember it’s only useful for simple shapes not a complete exporter

4 Likes

Thank you so much… you’ve saved me a ton of work.

This thread spans WAAAAAAAAAy too long.
Where is the 2.79B version ?

Hi Liero.
First of all, thank you very much for the great script. I am wonder how I found it just now, despite the fact that I have been working in Blender for years.

I use Blender 2.8 now and accordingly use the latest version of the script for it.

The first thing I noticed is a problem when setting the edge width to 0 pixels, it didn’t work (1 pixel thickness is displayed instead). To work correctly, it is enough to find these lines:

                        if wm.edge_wid:
                            w = ' stroke-width="'+str(wm.edge_wid)+'px" stroke-linejoin="'\
                                +wm.edge_join+'" stroke-linecap="round"'

…and add after them:

                        else:
                            w = ' stroke-width="0" stroke-linejoin="'\
                                +wm.edge_join+'" stroke-linecap="round"'

(By the way, as far as I know, there is no need to add “px” to the numeric value.)

The second problem is more serious, and I have not solved it yet.
When I choose the color of materials as base color for the selected shapes, I get an error when trying to export SVG:

I would be very grateful for the help in solving this problem.

Hi zhart, thanks for pointing this out, been away from Blender for a few months but just added a quick fix to be able to use material’s Viewport Display color… see you should also set Color Variation to 0 or a very low value from script. To export with 0px strokes try setting Edges to ‘Nothing’ in the dropdown. The links are in the first post…

Liero, thank you.

There is no errors now, thanks. But now faces with custom material displayed with primary color. In version for Blender 2.7 they were displayed as expected.
Update: Seems it works, but with some delay. I do not understand yet what it depends on.

It works, thanks!

I think you now need to use the Viewport Display color of materials, it’s pretty intuitive in Eevee, under Cycles or Workbench you may need to do some adjustments though…

I used it, still some problem:

Update:
It works, but with some nuances.
Everything works fine in object mode, but doesn’t work in edit mode.
Even ‘Selected faces’ option works normally only after switching to object mode.
I assume that this is normal behavior, you just need to keep in mind that you can press the export button only in object mode, otherwise the latest changes (from edit mode) will not be applied.

And there is another error, when «Join Objects» checked:

And one more thing: sometimes (usually when there is only part of selected object is visible in viewport) I got error “No selected objects” after pushing on “Export SVG” button.

Hi,

I’ trying to call the exporter fromn another (headless) script. I can drop the headless requirement…
but I would like to be able to use the settings I previously set in the panel

calling bpy.ops.export.svg() I get:

File "/Users/kaos/Library/Application Support/Blender/2.79/scripts/addons/export_svg.py", line 27, in execute
region3d = context.space_data.region_3d
AttributeError: 'NoneType' object has no attribute 'region_3d'

so I figured I have to give the correct context. I’ve been doing trial and error with no luck… what would be correct? Best I did was

context = bpy.context
for area in context.screen.areas:
    if area.type == 'VIEW_3D':
        print(area)
        ctx = {
            "window": context.window,
            "area": area, 
            "region": None
        }
bpy.ops.export.svg(ctx)

resulting in:

  File "/Users/kaos/Library/Application Support/Blender/2.79/scripts/addons/export_svg.py", line 28, in execute
    centro = (region.width/2, region.height/2)
AttributeError: 'NoneType' object has no attribute 'width'

The script works great when I call it manually
But I don’t know how to handle this…

Thanks (for the wonderful script)

hi, if you place the export line inside the loop and add the width and height it kind of worked, something like this…

import bpy
context = bpy.context

for area in context.screen.areas:

    if area.type == 'VIEW_3D':
        ctx = {
            "window": context.window,
            "area": area, 
            "width": area.width,
            "height": area.height
            }

        bpy.ops.export.svg(ctx)
        break

but I guess you’ll run into some other problems, and I’m not sure I can help, good luck anyway

AutoBlueprint is a good addons. will it be ported to blender 2.80 ?

When I’ll have more time (next month maybe :wink: ) I’ll update it.
I will certainly update it at some point. I already started porting all my addons to 2.80 by priority order, autoBlueprint being the last…

Now that we have a stable release candidate for 2.8 can someone update the script? I get this error now since the devs have updated the dependency graph:

 Traceback (most recent call last):
  File "C:\Users\...\Roaming\Blender Foundation\Blender\2.80\scripts\addons\export_svg_280.py", line 283, in execute
    objeto_2_bm(context, o, mes, linea)
  File "C:\Users\...\Roaming\Blender Foundation\Blender\2.80\scripts\addons\export_svg_280.py", line 129, in objeto_2_bm
    tmp = obj.to_mesh(context.depsgraph, apply_modifiers=True) ###
AttributeError: 'Context' object has no attribute 'depsgraph'

location: <unknown location>:-1

There is a 2.80 cheat sheet for updating
https://blenderartists.org/t/2-80-cheat-sheet-for-updating-add-ons/1148974

just did some fixes, it seems to work now on latest blender
thanks mkbreuer for the link, had to use bpy.data.meshes.new_from_object() here