Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when saving file with gear #146

Open
viktak opened this issue Jan 27, 2024 · 16 comments
Open

Error when saving file with gear #146

viktak opened this issue Jan 27, 2024 · 16 comments

Comments

@viktak
Copy link

viktak commented Jan 27, 2024

I just installed this WB for the latest FreeCAD (0.21.2) as I need to add a timing gear to my project. The gear appear fine, I can change its properties, all is good, but when I save the project, I get the following error in the 'Report view':

17:53:56  PropertyPythonObject::toString(): failed for <class 'freecad.gears.timinggear.TimingGear'>
17:53:56  Traceback (most recent call last):
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable
17:53:56  PropertyPythonObject::toString(): failed for <class 'freecad.gears.basegear.ViewProviderGear'>
17:53:56  Traceback (most recent call last):
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type ViewProvider is not JSON serializable

While trying to figure out what causes this I noticed that any gear type causes the same problem.

Is it possible that the current version of the WB is not compatible with the latest version of FreeCAD? Or something is wrong in my environment? All other WBs work fine on my computer. My environment is a 64 bit Windows 11.

Thank you in advance for any pointers!

@looooo
Copy link
Owner

looooo commented Jan 27, 2024

The addon-manager is not using the latest version. Try installing freecad.gears manually.

@viktak
Copy link
Author

viktak commented Jan 28, 2024

Thanks for the quick reply!
I removed it from the addon-manager, then I installed it manually, but it doesn't even show up in the workbenches dropdown list. I tried to install it using both pip and pip3, but no luck, still FreeCAD doesn't see it...

@looooo
Copy link
Owner

looooo commented Jan 28, 2024

It depends on how you installed freecad.

@viktak
Copy link
Author

viktak commented Jan 28, 2024

Simply downloaded the Windows installer and installed it...

@looooo
Copy link
Owner

looooo commented Jan 28, 2024

Ok then you need to install freecad.gears with the same python that is also shipped with freecad. Or you simple copy to the right place ..../lib/sitepackages

@viktak
Copy link
Author

viktak commented Jan 28, 2024

In FreeCAD's About box I can see python 3.8.10. So when I tried to install it with pip 3, it should have worked, right?

This is the output of the install:

PS D:\> pip3 install https://github.com/looooo/FCGear/archive/master.tar.gz
Collecting https://github.com/looooo/FCGear/archive/master.tar.gz
  Using cached https://github.com/looooo/FCGear/archive/master.tar.gz
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Requirement already satisfied: numpy in c:\users\viktor\appdata\local\programs\python\python310\lib\site-packages (from freecad.gears==1.2.0) (1.24.3)
Requirement already satisfied: scipy in c:\users\viktor\appdata\local\programs\python\python310\lib\site-packages (from freecad.gears==1.2.0) (1.12.0)
Requirement already satisfied: sympy in c:\users\viktor\appdata\local\programs\python\python310\lib\site-packages (from freecad.gears==1.2.0) (1.12)
Requirement already satisfied: mpmath>=0.19 in c:\users\viktor\appdata\local\programs\python\python310\lib\site-packages (from sympy->freecad.gears==1.2.0) (1.3.0)
Building wheels for collected packages: freecad.gears
  Building wheel for freecad.gears (pyproject.toml) ... done
  Created wheel for freecad.gears: filename=freecad.gears-1.2.0-py3-none-any.whl size=208747 sha256=c0921881412553a0a303f70e13d5007e6d17317185567f0ad3d007b0cb1373fb
  Stored in directory: C:\Users\Viktor\AppData\Local\Temp\pip-ephem-wheel-cache-a3gx_ffc\wheels\b4\4b\5c\f2259e212822d70e6570319d345308f5ffd03d697867b4967d
Successfully built freecad.gears
Installing collected packages: freecad.gears
Successfully installed freecad.gears-1.2.0

I can even find it in the site-packages folder:
image

It still wouldn't show up within FreeCAD. Is there anything else to do in FreeCAD to make it work? (I have restarted it)

@looooo
Copy link
Owner

looooo commented Jan 28, 2024

it seems like you installed it to python 3.10. If freecad uses python 3.8.10 it will not see the installed freecad.gears.

Maybe you can raise an issue for FreeCAD and show that the add-on-manager is not using the latest version of freecad.gears.

@viktak
Copy link
Author

viktak commented Jan 28, 2024

I see, thanks for explaining this to me!

@arampak
Copy link

arampak commented Feb 3, 2024

To follow up on this. When saving the file with a generated gear, I had an error when the workbench was installed using the built-in addon manager. Here is the error message in the console:

13:03:28  PropertyPythonObject::toString(): failed for <class 'freecad.gears.basegear.ViewProviderGear'>
13:03:28  Traceback (most recent call last):
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type ViewProviderDocumentObject is not JSON serializable

I have just tried installing the gear workbench in FreeCAD on MacOS using pip. For that, I have cd'd into /Applications/FreeCAD.app/Contents/Resources/bin/ and run:
./python -m pip install https://github.com/looooo/FCGear/archive/master.tar.gz

Everything was installed without problem, however, the same error remains.

./python --version prints: "Python 3.10.13"

The file is actually saved, and the generated gear is there after re-opening, but probably with some information loss.

@looooo
Copy link
Owner

looooo commented Feb 11, 2024

@chennes do you know why some people have problems install the latest version of this workbench with the addonmanager?

@chennes
Copy link
Contributor

chennes commented Feb 11, 2024

I just installed it with the Addon Manager and it worked fine (though I don't know how to test that the WB itself is working, I just hit install, restarted, then launched it).

@viktak
Copy link
Author

viktak commented Feb 12, 2024

@chennes See the OP: just create a timing gear and save it. Then you'll see (or not :) ) the issue.

@turbubestia
Copy link

Same problem here.

OS: Windows 11 build 22631
Word size of FreeCAD: 64-bit
Version: 0.21.2.33771 (Git)
Build type: Release
Branch: releases/FreeCAD-0-21
Hash: b9bfa5c5507506e4515816414cd27f4851d00489
Python 3.8.10, Qt 5.15.2, Coin 4.0.1, Vtk 8.2.0, OCC 7.6.3
Locale: Spanish/Chile (es_CL)
Installed mods: 
  * Assembly3 0.12.2
  * freecad.gears 1.2.0

The next exception is triggered when saving the project. Also, it is triggered for every gear, not just once.

20:32:26  PropertyPythonObject::toString(): failed for <class 'freecad.gears.basegear.ViewProviderGear'>
20:32:26  Traceback (most recent call last):
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Program Files\FreeCAD 0.21\bin\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type ViewProvider is not JSON serializable

@av2k
Copy link

av2k commented Mar 24, 2024

Can confirm with Python 3.11:

PropertyPythonObject::toString(): failed for <class 'freecad.gears.features.ViewProviderGear'>
Traceback (most recent call last):
  File "__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "encoder.py", line 200, in encode
    chunks = self.iterencode(o, _one_shot=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "encoder.py", line 258, in iterencode
    return _iterencode(o, 0)
           ^^^^^^^^^^^^^^^^^
  File "encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type ViewProvider is not JSON serializable

@stepheneb
Copy link

Another report FreeCAD 0.21.2.33771 using Python 3.10.13 on macOS 14.4.1

Steps:

  1. open freecad
  2. make new document
  3. open gear workbench
  4. make worm gear
  5. save document

FreeCAD About

OS: macOS 14.4.1
Word size of FreeCAD: 64-bit
Version: 0.21.2.33771 (Git)
Build type: Release
Branch: (HEAD detached at 0.21.2)
Hash: b9bfa5c5507506e4515816414cd27f4851d00489
Python 3.10.13, Qt 5.15.8, Coin 4.0.0, Vtk 9.2.6, OCC 7.6.3
Locale: C/Default (C)
Installed mods: 
  * ThreadProfile 1.89.0
  * freecad.gears 1.2.0
  * A2plus 0.4.64a
  * sheetmetal 0.4.14
  * Beltrami 1.0.8-alpha
  * Curves 0.6.36
  * Assembly4 0.50.12
  * Assembly3 0.12.2

Error: <class 'TypeError'>: Object of type ViewProviderDocumentObject is not JSON serializable

Listedd errors

Traceback (most recent call last):
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type ViewProviderDocumentObject is not JSON serializable

PropertyPythonObject::toString(): failed for <class 'freecad.gears.basegear.ViewProviderGear'>

Traceback (most recent call last):
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/Applications/FreeCAD.app/Contents/Resources/lib/python3.10/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
<class 'TypeError'>: Object of type FeaturePython is not JSON serializable

PropertyPythonObject::toString(): failed for <class 'freecad.gears.wormgear.WormGear'>

Python installed on system

% python3 --version 
Python 3.12.3
% which python3
/opt/homebrew/bin/python3
image

@stepheneb
Copy link

stepheneb commented May 15, 2024

Same errors saving (as described in [#146#issuecomment-2111358476]) when installing latest manually (#146 (comment))

  1. Use addon-manager to uninstall freecad.gears
  2. Install freecad.gears manually
% cd ~/Library/Application\ Support/FreeCAD/Mod
% git clone [email protected]:looooo/freecad.gears.git 
% cd freecad.gears 
% git log -1

commit 9715c068e4fb98f9e60cba8eea97980a73e60fae (HEAD -> master, origin/master, origin/HEAD)
Author: catalintucureanu <[email protected]>
Date:   Thu May 9 22:17:18 2024 +0300

    Update timinggear_t.py
    
    fix for issue #164

V1.2.0 was added to package.xml in 6197bfd

Here are all the commits since then and doing a quick scan I didn't see any that might fix this issue: 6197bfd...master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants