Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.
Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).
Hey Y'all,
I'm running into an issue with a JSON encoding bit, I'm getting a type error of this
TypeError: unable to convert unicode to @net.maxon.interface.url-C
I am trying to read a JSON file into cinema and make it a path in the plugin, below is the current code I have
#---------------------------------------------------------------------------------------------------------------------------------------- # IMPORT OBJECTS #---------------------------------------------------------------------------------------------------------------------------------------- import os from os import listdir from os.path import isfile, join def import_objs(OBJ_LIST): global SETTINGS LIBPATH = SETTINGS["SETTING_ASSET_LIBRARY_FULLPATH"] FILES = [f for f in listdir(LIBPATH) if isfile(join(LIBPATH, f))] for OBJ in OBJ_LIST: OBJ_FILENAME = OBJ[0] + ".c4d" if OBJ_FILENAME in FILES: FILEPATH = os.path.join(LIBPATH,OBJ_FILENAME) c4d.documents.MergeDocument(doc, FILEPATH, c4d.SCENEFILTER_OBJECTS | c4d.SCENEFILTER_MATERIALS, None) c4d.EventAdd() return True
Any thoughts?
Cheers!
MattG
Hi,
with the information provided here it is rather hard to give you an answer (at least for me). You should provide:
c4d.documents.MergeDocument(...
No offense intended, but you also might want to stick to naming conventions, upper case symbols are universally reserved for global constants in all languages.
With that out of the way:
c4d.BaseContainer
BaseContainer.SetFilename
__setitem__
FILEPATH
LIBPATH
Cheers, zipit
Hey Zipit!
Thanks for the response, I actually completely overlooked the fact that I had to convert it to a string......(insert hammer on head here)
Note to self hahaha!
Stay safe out there!
Just to add on top, os.path.listdir and os.path.join in python 2 are context-specific, so if you input a Unicode string it will output a Unicode string, if you input a regular string it will output a regular string. Now the culprit is on c4d.documents.MergeDocument because normally this method accepts a C++ Filename object (which is the Classic API that under the hood uses the new MaxonAPI maxon::Url). Unfortunately, the Python parser is not able to convert from a Python Unicode string to a C++ Filename, but only from a Python ASCII string to a filename.
So indeed casting from Unicode string to ASCII is the solution. Cheers, Maxime.