Sample code to create SVG file, using Processing 4.1.1 with Python mode

Hello,
I would like to create an SVG file in Processing 4.1.1 Python mode
but I am getting an error on this line: add_library (‘svg’)
Error:
java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader ‘bootstrap’)
at jycessing.LibraryImporter.addJarToClassLoader(LibraryImporter.java:315)
at jycessing.LibraryImporter.recursivelyAddJarsToClasspath(LibraryImporter.java:164)
at jycessing.LibraryImporter.addLibrary(LibraryImporter.java:140)
at jycessing.LibraryImporter$1.call(LibraryImporter.java:82)
at org.python.core.PyObject.call(PyObject.java:480)
at org.python.core.PyObject.call(PyObject.java:484)
at org.python.pycode._pyx11.f$0(test_svg_240205.pyde:1)
at org.python.pycode._pyx11.call_function(test_svg_240205.pyde)
at org.python.core.PyTableCode.call(PyTableCode.java:171)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1614)
at org.python.core.Py.exec(Py.java:1658)
at org.python.pycode._pyx10.f$0…

There is an existing post in the forum saying to go back to Processing 3.5.4 as SVG works with this older version of Processing but unfortunately I have an error when I tried to revert back to this 3.5.4 older version. I get an error 'An error occurred during startup.

So it seems I’ve to stay with Processing 4.1.1.
Appreciate if anyone has a sample code to create SVG file that works in Processing Python mode 4.1.1
Much thanks.

1 Like

Hi @proc8888 !

I have been unable to make Python mode work with Processing 4.X :frowning:
I can still run most Python mode sketches on Processing 3.5.4. Here are my SVG export code examples

Maybe you could try some py5? My sample code for py5

1 Like

Thank you for update and sample code for py5

1 Like

Recently I’ve moved my “processing-3.5.4” app folder from a Win 8.1 laptop to another 1 w/ Win 10 and it works the same.

However, b/c you also have Processing 4, you’re gonna need to have separate sketchbook folders for both P3 & P4.

Here’s a way to do it on Windows:

  • 1st, close all running Processing instances, so they won’t overwrite the “preferences.txt” file we’re gonna edit later.

  • Go to folder %USERPROFILE%\Documents and create a subfolder named code or another name of your liking.

  • inside subfolder code, create 2 subfolders; 1 for “Processing 3” and another for “Processing 4”.

  • BtW, in my laptop I’ve got 4 subfolders named: P1, P2, P3, P4. B/c I’ve got all Processing versions!

  • Annotate the path of those folders b/c we’ll need them in this next 2nd step.

  • It’s very important to have separate sketchbooks for each of those major versions due to library incompatibility among them.

  • Now go to folder %APPDATA%\Processing and open the “preferences.txt” file there using some text editor, like Notepad.

  • Go to the bottom of “preferences.txt” and try to find these 3 entries:

    1. sketchbook.path=
    2. sketchbook.path.four=
    3. sketchbook.path.three=
  • Those 3 entries represent the paths of our sketchbook folders for Processing versions 2, 4 and 3 respectively.

  • Use the paths you’ve annotated earlier on those config entries and save the file.

If you’ve followed those instructions right, each Processing major version will use its own sketchbook, so libraries installed for 1 major version won’t crash the other.

P.S.: You can move the contents of the sketchbook folder your “Processing 4” was using to its newest folder.

However, only your own sketches, not the subfolders libraries, modes nor tools; b/c it can happen they already contain mixed versions of both Processing 3 & 4 inside them!

3 Likes

Hello @GoToLoop Thank you for shedding further further light on this. I’ll ‘map’ your suggestions to MAC version, which I’m using. Very useful info., appreciated.

1 Like

Just asked Bing AI for those Windows paths when they’re ‘mapped’ to Mac:

  1. %USERPROFILE%\Documents\~/Documents/
  2. %APPDATA%\Processing\~/Library/Processing/

Not sure if any of them is correct though.

P.S.: When you need to change from Processing 4 to Processing 3 and vice-versa, remember to close the current 1 before opening the other!

2 Likes