View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0002749 | FreeCAD | Bug | public | 2016-10-25 16:33 | 2016-10-26 19:12 |
Reporter | Berner | Assigned To | wmayer | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | no change required | ||
Platform | Linux | OS | Ubuntu | OS Version | OS: Ubuntu 16.04 |
Product Version | 0.17 | ||||
Fixed in Version | 0.17 | ||||
Summary | 0002749: Language problem with german special characters ü | ||||
Description | When i create a Box with locale in Linux set to: LANG=de_DE.UTF-8 LANGUAGE=de_DE LC_CTYPE="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_PAPER="de_DE.UTF-8" LC_NAME="de_DE.UTF-8" LC_ADDRESS="de_DE.UTF-8" LC_TELEPHONE="de_DE.UTF-8" LC_MEASUREMENT="de_DE.UTF-8" LC_IDENTIFICATION="de_DE.UTF-8" LC_ALL= The Box will created with the Label "Würfel". When i call the following Macro the Macro crashed: # Macro Begin: /home/data/WINSTICK/CAD/ListObj.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++ # -*- coding: utf-8 -*- import FreeCAD,Draft,Part # List all objects of the document App.Console.PrintMessage("ListObj-Macro\n") doc = FreeCAD.ActiveDocument objs = FreeCAD.ActiveDocument.Objects #App.Console.PrintMessage(str(objs) + "\n") #App.Console.PrintMessage(str(len(FreeCAD.ActiveDocument.Objects)) + " Objects" + "\n") for obj in objs: a = obj.Name # list the Name of the object (not modifiable) b = obj.Label # list the Label of the object (modifiable) try: c = obj.LabelText # list the LabeText of the text (modifiable) App.Console.PrintMessage(str(a) +" "+ str(b) +" "+ str(c) + "\n") # Displays the Name the Label and the text except: App.Console.PrintMessage(str(a) +" "+ str(b) + "\n") # Displays the Name and the Label of the object #doc.removeObject("Box") # Clears the designated object # Macro End: /home/data/WINSTICK/CAD/ListObj.FCMacro +++++++++++++++++++++++++++++++++++++++++++++++++ Errormessage of the Macro: App.Console.PrintMessage(str(a) +" "+ str(b) + "\n") # Displays the Name and the Label of the object <type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range(128) When i rename the Label to Wuerfel, the Macro is running correct. The problem depends on the characters ü, ö, etc. OS: Ubuntu 16.04.1 LTS Word size of OS: 64-bit Word size of FreeCAD: 64-bit Version: 0.17.8764 (Git) Build type: None Branch: master Hash: efff1b7773ec20d32efba878c3900076918232d4 Python version: 2.7.12 Qt version: 4.8.7 Coin version: 4.0.0a OCC version: 6.8.0.oce-0.17 | ||||
Steps To Reproduce | See description above. | ||||
Tags | No tags attached. | ||||
FreeCAD Information | |||||
|
This is NOT a FreeCAD bug but standard Python (2.x) behaviour. Just run the following code in a Python session:
results into the error:UnicodeEncodeError: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range(128) This happens because when concatenating a string and a unicode string Python tries to create a string from the unicode string "b" but the code point for "ü" is outside the ASCII range. When you want to avoid the problem you must encode "b" e.g. as utf-8 |
|
Thank you, your solution solves the problem. I got my sample from the Freecad Macro recipes. Do you have an idea i can code a macro to run in any locales ? |
|
> Do you have an idea i can code a macro to run in any locales ? When using unicode strings everywhere then it should work with any locales. If you need a plain string for certain functions it's best to use encode("utf-8"). If you have a utf-8 encoded string and want to create a unicode string from it then use decide("utf-8") |
Date Modified | Username | Field | Change |
---|---|---|---|
2016-10-25 16:33 | Berner | New Issue | |
2016-10-26 12:05 | wmayer | Note Added: 0007427 | |
2016-10-26 12:06 | wmayer | Status | new => feedback |
2016-10-26 12:46 | Berner | Note Added: 0007428 | |
2016-10-26 12:46 | Berner | Status | feedback => new |
2016-10-26 19:12 | wmayer | Note Added: 0007429 | |
2016-10-26 19:12 | wmayer | Status | new => closed |
2016-10-26 19:12 | wmayer | Assigned To | => wmayer |
2016-10-26 19:12 | wmayer | Resolution | open => no change required |
2016-10-26 19:12 | wmayer | Fixed in Version | => 0.17 |