Python scripting - Introduction

Python libraries

Previous  Chapter  Next

 

   

Available Python libraries

 

A Python library is a collection of related modules. It contains packages of code that can be reused multiple times in different applications. This makes Python programming easier and more convenient for the programmer. Because we don't need to write the same code again and again for different applications.

 

All available Python libraries can be found in the FASTSUITE installation folder: ..\E2InstallationPath\Lib\site-packages.

 

cenpylib

 

 

[Example 1]   

# Import library

from cenpylib import *

 

# Usage: specify the operator's class

def ModifyActiveProgram(operator: CENPyOlpProgramModifyOperator):

  # Result: IntelliSense will provide you with all available functions

  logging = operator.GetLoggerOperator()

  program = operator.GetActiveProgram()

  logging.LogInfo("Program name: "+str(program.GetName()))

  ...

 

[Example 2]  

from cenpylib import *

def ModifyActiveProgram(Operator: CENPyOlpProgramModifyOperator):

  logging = Operator.GetLoggerOperator()

  # Use file utility to access the paths of CENIT and E2 logos

  fileUtility = FileUtility()

  logging.LogInfo(f"CENIT logo black path: {fileUtility.CENIT_LOGO_BLACK}")

  logging.LogInfo(f"CENIT logo green path: {fileUtility.CENIT_LOGO_GREEN}")

  logging.LogInfo(f"FASTSUITE E2 icon path: {fileUtility.FASTSUITE_E2_ICON}")

  logging.LogInfo(f"FASTSUITE E2 logo path: {fileUtility.FASTSUITE_E2_LOGO}")

 

 

[Example 3]  

from cenpylib import *

def ModifyActiveProgram(Operator: CENPyOlpProgramModifyOperator):

  logging = Operator.GetLoggerOperator()

  # Use file utility to access the paths of CENIT and E2 logos

  # ======== create a PDF Report =============

  pdf = ReportUtility()

  pdf.createAutoExecutePDFReport(Operator, "")

 

 

tkinter

 

The tkinter package (“Tk interface”) is the standard Python interface to the Tcl/Tk GUI toolkit. The detailed information can be found here:

 

[Example]   

# Import library

from tkinter import *

from tkinter import ttk

 

   # Usage

  root = Tk()

  frm = ttk.Frame(root, padding=50)

  frm.grid()

  ttk.Label(frm, text="Hello World!").grid(column=0, row=0)

  ttk.Button(frm, text="Quit", command=root.destroy).grid(column=1, row=0)

  root.mainloop()

 

Some examples can be found in the FASTSUITE E2 installation folder:

PageParagraph_8 ..\E2Plugin\Technologies\ArcWeldingTechnology\Standard\AuxiliaryCommands\OlpProgram\Connect touch and process points.py

 

ConnectTouchAndProcessPoints

 

PageParagraph_8 ..\E2Plugin\Technologies\LaserCuttingTechnology\Standard\AuxiliaryCommands\OlpProgram\Import inspection data.py

 

ImportInspectionData

 

 

fpdf2

 

fpdf is a library for simple and fast PDF document generation in Python. It is a fork and the successor of PyFPDF. With the plugin manager comes the possibility to create dictionaries for different languages translation. The dictionary supports the definition of attribute and event names, created in Python. The detailed information can be found here:

 

Dependencies of fpdf2 package:

PageParagraph_8 Pillow  - is a Python Imaging Library adds image processing capabilities to your Python interpreter

PageParagraph_8  defusedxml - contains several Python-only workarounds and fixes for denial of service and other vulnerabilities in Python’s XML libraries.

PageParagraph_8 svg.path - is a collection of objects that implement the different path commands in SVG, and a parser for SVG path definitions.

 

[Example]   

# Import library

from fpdf import FPDF

 

   # Usage

  pdf = FPDF()

  pdf.add_page()

  pdf.set_font('helvetica', size=12)

  pdf.cell(txt="hello world")

  pdf.output("hello_world.pdf")

 


Previous
Previous page
Chapter
Chapter page
Next
Next page