SVG properties - modifying after import

I’m using the Python mode in Processing, but I’m guessing this might be an issue in other processing modes as well:

I’ve imported some SVGs exported from Illustrator (as well as other hand coded SVGs) and I’m having problems changing the strokeWeight on the characters. Here is my test code:

import os

def setup():
    size (500,500)
    background(255)
    
    svgPath = os.path.expanduser('~/Documents/Processing/scratchpad/data/')
    fileName = 'svgTest.svg'
    filePath = os.path.join(svgPath,fileName)
    theShape = loadShape(filePath)
    stroke(255,255,255)
    strokeWeight(15)
    shape(theShape,10,10)

Here is my simple SVG that Processing opens and displays without problem. I have been using several other SVGs for testing as well to make sure the file itself is not introducing a complication.

<svg xmlns="http://www.w3.org/2000/svg">
	<line
		x1="40" y1="30"
		x2="240" y2="100"
		stroke="black" stroke-width="1" />
</svg>

My strokeWeight does nothing to change the appearance of the SVG shapes I’m bringing in. Wondering if anyone has similar (or opposite!) experiences?

Hi pxlmnkeee!
Try using the disableStyle() method to be able to change the settings for the shape. That should fix your issue. I’ve included it in your code as follows:

import os

def setup():
    size (500,500)
    background(255)
    
    svgPath = os.path.expanduser('~/Documents/Processing/scratchpad/data/')
    fileName = 'svgTest.svg'
    filePath = os.path.join(svgPath,fileName)
    theShape = loadShape(filePath)
    
    #Disable svg style
    theShape.disableStyle()
    
    stroke(0,0,0)
    strokeWeight(15)
    shape(theShape,10,10)
2 Likes

If you place your file “svgTest.svg” inside your sketch’s folder or its subfolder “data/”, PApplet::loadShape() method will find it w/o any those os shenanigan boilerplate! :crossed_fingers:

1 Like

YES! That was the nugget I was looking for. I had seen it mentioned in another unrelated post, but didn’t think style would apply since I wasn’t setting a style explicitly in the SVG itself.

Thanks for the tip!!

Thanks GoToLoop! I’m going to have hundreds of SVG files so I’ve built a folder structure in the data folder to keep things organized. I just left the os boilerplate code in there. I’m trying to get in the good habit of using os subroutines to work with file paths, and I’ve had problems accessing things directly in the data folder in Processing’s Python mode.

Thanks for looking out, always appreciated!

Some tips for loading assets in Python Mode: :snake:

1 Like

I’m sort of using a similar approach with os module. I have noticed that any time you make a change in the Processing IDE for Python mode, your sketch path switches to a temp folder. When you save after a code change, then your sketch path goes back to the one that has data folder. It’s usually an issue for my workflow, as I don’t like saving after every code change. Your existing code manages to skip the hassle of saving by setting a universal path for your data, which is great.

1 Like