Cator
Senior Member
Hoping to help someone build custom apps in Alibre Script, I’m sharing the process that led me to create this script for generating QR Codes.
When you want to create a project that does not use the libraries present in IronPython of Alibre Script, the procedure to follow is this:
1. **Download the `qrcode-6.1.tar.gz` library compatible with Python 2.7:**
Qrcode 6.1
2. **Extract the content and copy the folder to:**
`C:\Program Files\Alibre Design 28.0.1.28098\Program\Addons\AlibreScript\PythonLib\site-packages`
3. **Start AlibreScript and in an empty script, test the import:**
**and press RUN**
We will receive an error ☹. To make an imported library work, it is necessary to specify the path each time.
4. **So, at the beginning of each script, we will use:**
At this point, you will still receive an error. `qrcode` has a dependency, a missing library: `six`.
5. **Let's repeat the same procedure for the `six` library:**
six-1.16.tar.gz
6. **Extract the content and copy the folder to:**
`C:\Program Files\Alibre Design 28.0.1.28098\Program\Addons\AlibreScript\PythonLib\site-packages`
7. **Then we will import both libraries and can use them simply:**
With this code, you should be able to use the `qrcode` library in Alibre Script without any issues.
I hope everyone and especially @NateLiquidGravity and @stepalibre, that you can check it out, I'd love to know what you think.
Regard,
Francesco
When you want to create a project that does not use the libraries present in IronPython of Alibre Script, the procedure to follow is this:
1. **Download the `qrcode-6.1.tar.gz` library compatible with Python 2.7:**
Qrcode 6.1
2. **Extract the content and copy the folder to:**
`C:\Program Files\Alibre Design 28.0.1.28098\Program\Addons\AlibreScript\PythonLib\site-packages`
3. **Start AlibreScript and in an empty script, test the import:**
Python:
import qrcode
**and press RUN**
We will receive an error ☹. To make an imported library work, it is necessary to specify the path each time.
4. **So, at the beginning of each script, we will use:**
Python:
import sys
sys.path.append("C:\\Program Files\\Alibre Design 28.0.1.28098\\Program\\Addons\\AlibreScript\\PythonLib\\site-packages\\qrcode-6.1")
import qrcode
At this point, you will still receive an error. `qrcode` has a dependency, a missing library: `six`.
5. **Let's repeat the same procedure for the `six` library:**
six-1.16.tar.gz
6. **Extract the content and copy the folder to:**
`C:\Program Files\Alibre Design 28.0.1.28098\Program\Addons\AlibreScript\PythonLib\site-packages`
7. **Then we will import both libraries and can use them simply:**
Python:
import sys
sys.path.append("C:\\Program Files\\Alibre Design 28.0.1.28098\\Program\\Addons\\AlibreScript\\PythonLib\\site-packages\\qrcode-6.1")
sys.path.append("C:\\Program Files\\Alibre Design 28.0.1.28098\\Program\\Addons\\AlibreScript\\PythonLib\\site-packages\\six-1.16.0")
import os
import qrcode
import qrcode.image.svg
With this code, you should be able to use the `qrcode` library in Alibre Script without any issues.
Python:
import sys
# Add the paths for the qrcode and six libraries to the system path
sys.path.append("C:\Program Files\Alibre Design 28.0.1.28098\Program\Addons\AlibreScript\PythonLib\site-packages\qrcode-6.1")
sys.path.append("C:\Program Files\Alibre Design 28.0.1.28098\Program\Addons\AlibreScript\PythonLib\site-packages\six-1.16.0")
import os
import qrcode
import qrcode.image.svg
# Create a Windows dialog for user interaction
Win = Windows()
ScriptName = 'Export QRCode'
Options = []
# Add an option for the user to input their part number
Options.append(['Design Data', WindowsInputTypes.String, 'Insert your part number'])
# Add an option for the user to choose the file save location
Options.append(['File', WindowsInputTypes.SaveFile, os.path.expanduser("~"), 'File', 'SVG|*.svg', '.svg'])
# Add a label for the user
Options.append(['Label', WindowsInputTypes.Label, 'Export the QR Code in SVG on your Desktop'])
Values = Win.OptionsDialog(ScriptName, Options, 200)
if Values is None:
sys.exit()
# Data for the QR code
data = Values[0]
# Create the QR Code with an SVG renderer
factory = qrcode.image.svg.SvgPathImage
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
image_factory=factory,
)
qr.add_data(data)
qr.make(fit=True)
# Generate the QR image
img = qr.make_image()
file_path = Values[1]
# Save the image to an SVG file on the desktop
with open(file_path, "w") as f:
img.save(f)
print("The QR code has been saved to: {}".format(file_path))
I hope everyone and especially @NateLiquidGravity and @stepalibre, that you can check it out, I'd love to know what you think.
Regard,
Francesco
Last edited: