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

Approaching boost -> custom python class <-> serialize #13

Open
schoeller opened this issue Mar 16, 2025 · 1 comment
Open

Approaching boost -> custom python class <-> serialize #13

schoeller opened this issue Mar 16, 2025 · 1 comment

Comments

@schoeller
Copy link

Dear all,

thanks for your opensource.

I am an occasional scripter and am trying to serialize a custom object from PyRx. I am banging my head doing as follows:

import traceback
from pyrx_imp import Ap, Db
from serialize import register_class
from serialize import dump, dumps

def textstyletablerecord_to_builtin(u): # take custom object and return python-builtin types
     return (u.getName())

def textstyletablerecord_from_builtin(c): # take python-builtin types and return custom object 
     tstr = Db.TextStyleTableRecord()
     tstr.setName(c[0])
     return tstr

register_class(Db.TextStyleTableRecord, textstyletablerecord_to_builtin, textstyletablerecord_from_builtin) # registering serialization class TextStyleTableRecord

@Ap.Command()
def jsontest():
    db = Db.curDb()
    tstr = Db.TextStyleTableRecord() # init the custom object
    print(tstr.className()) # output: AcDbTextStyleTableRecord

    tstr.setName("test") # setting name att
    dumps(tstr, fmt='yaml')

BTW className() prints AcDbTextStyleTableRecord. Also the modules PyRx established an intermediate interface





Then dumps throws as follows:

Exception has occurred: RuntimeError
Pickling of "PyDb.TextStyleTableRecord" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)

The custom object is generated in this (awesome) third party project using boost on different SDKs. I have seen a hint in the docs, but I am not sure whether this leads to anywhere or whether I should take a different path. Maybe I have just been stupid with class names.

Hints appreciated, I try to follow, but brain capacity is limited.

Regards

Seb

@schoeller
Copy link
Author

schoeller commented Mar 16, 2025

When trying a custom object like Ge.Point3d everythings works. It seems to have something to do with the boost pickle interface. For Ge.Point3d it is defined as boost::python::pickle_suite, but for Db.TextStyleTableRecord it is not. Is it possible to compensate this somehow within serialize?

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

1 participant