QrCode with GhPython?

Hello; i installpyqrcode and when i test it in GhPython i got this error

Runtime error (LookupException): unknown encoding: shiftjis

Is there a solution or alternative tool?


I test this one, looks it work but i don’t know where is the result and how to save it

import qrcode
import qrcode.image.svg

if method == 'basic':
# Simple factory, just a set of rects.
factory = qrcode.image.svg.SvgImage
elif method == 'fragment':
# Fragment factory (also just a set of rects)
factory = qrcode.image.svg.SvgFragmentImage
else:
# Combined path factory, fixes white space that may occur when zooming
factory = qrcode.image.svg.SvgPathImage

img = qrcode.make('Some data here', image_factory=factory)

Hello,

Did you download the pymaging library to create the images? It says it is pure python and 2.7 compatible so it might work in GH.

import os
print os.getcwd()

should tell you where python is working - maybe it is there …?

Also it includes a template for making your own factory - it looks as though it would be quite easy to implement a Rhino template to draw squares in Rhino representing your QR code !

1 Like

Thanks you, this code create xml file with all points needed

1 Like

I use Pancake to export the output as svg file than import it, i don’t know how to do that with python;
and the result , small qrcode city :smiley:

3 Likes

Hmm… first steps towards a Rhino QR code factory …

import qrcode
import qrcode.image.rhino_image

factory = qrcode.image.rhino_image.RhinoImage
img = qrcode.make('Some data here', image_factory=factory)

2 Likes

Very nice , thank you

The code is here

https://raw.githubusercontent.com/dancergraham/python-qrcode/Rhino/python-qrcode/qrcode/image/rhino_image.py

1 Like

Thank you very much; i make a little change

import Rhino.Geometry as rg
import scriptcontext as sc
import qrcode.image.base

class RhinoImage(qrcode.image.base.BaseImage):
"""
Rhino QRCode image output class.
"""
kind = "Rhino"
allowed_kinds = ("Rhino",)

def __init__(self, *args, **kwargs):
    super(RhinoImage, self).__init__(*args, **kwargs)

def drawrect(self, row, col):
    """
    Draw point location of the QR code.
    """
    point = rg.Point3d(col, -row, 0)
    self._img.append(point)

def new_image(self, **kwargs):
    """
    Build the image class. Subclasses should return the class created.
    """
    return []

def get_image(self, **kwargs):
    """
    Return the image class for further processing.
    """
    return self._img

QrCode.gh (6.5 KB)

1 Like

Hi @anon39580149 .
I would like to use the qrcode module in GHPython and RhinoPython, but when I try to import qrcode, I get an import error. how can I use qrcode in GHpython?

Thanks.

Read the topic carefuly, the solution already posted by @Dancergraham

Sorry, I had to read it properly again. However, I couldn’t figure out why the first line of the import shows invalid syntax.
Where is the qrcode module installed? I’m sorry that this is a fundamental question.
Thanks for your help!

Follow these steps to set python27 as interepter and to add it in rhino folders than you can install qrcode module.

Hello,

You should put the qrcode module in your scripts folder. For Rhino 7 on Windows this should be %HOMEPATH%\AppData\Roaming\McNeel\Rhinoceros\7.0\scripts

You should have a folder called qrcode in there containing files like this:
image
and this file : rhino_image.py (1.5 KB) in the image directory

1 Like

Hmm, I’m probably missing something essential but I have those folders and files seamingly in the right location
image
image
image

But cannot get it to work either…

Any idea what I might be missing here?

Hello,

Did you download version 7 from Pypi ? It looks like they have gone Python 3 only - you may need to download and unpack the tar package from here qrcode · PyPI

1 Like

That did something but it now seems like I’m missing a module named “six”. Any idea what that could be? Thanks a lot for the help.

If I remember correctly, Six should be a Python module that attempts to render scripts written in Python 2.7 and 3.x+ better compatible. The entire module should be contained within a single Python file. As long as you copy it to a directory that Rhino loads by default or even to your own project/module, you should be able to import from it. You can get it on GitHub.

1 Like

yes as in 2 times 3 equals 6 :smiley:

1 Like

I’m currently using 3.9. :slight_smile:

I have incompatible libraries - I am stuck on 3.8 for the new day job, but at least I have f-strings and type annotations. Looking forward to structural pattern matching in 3.10 if I ever get there !!!