Failed: Loading SU model by a path containing Chinese words

I develop with C++ SDK, and I found the interface SUModelCreateFromFile would return SU_ERROR_SERIALIZATION and couldn’t load the model when the path is containing Chinese words like “C:\Users\Administrator\Desktop\testone\风雨雷电a.skp”.

I have tried some ways like and some others ways ,but it seems no wording.,
I am looking forward to your help … (T T)

Can you post a complete example, with a short snippet ready to compile and a file that fails?

That’s interesting.

for example :
CString strPath;

std::string tempName = (LPCSTR)CStringA(strPath);  //CStringA、CStringW、CString对应字符类型分别为char,wchar_t,TCHAR

const char* p = tempName.c_str();

if (SU_ERROR_NONE != SUModelCreateFromFile(&m_model, p))//判断模型创建失败的话,释放空间
	return false;

SUEntitiesRef entities = SU_INVALID;

if(SU_ERROR_NONE != SUModelGetEntities(m_model, &entities))
	return false;

Do you have a sample SKP file?

this is a SKP file with Chinese name 中国CTO.skp (53.3 KB)

I have the same problem, too. Looking for solution…

develop in C++ ?

Yes , Visual C++ 2015.

did you work out this problem? I wonder if you have qq ?maybe we can have a deeper talk, myqq is 27925916

I find it’s an encoding problem.SU SDK receives char* encoded with utf-8 only .try this:

char *filename = L"模型.skp"; // an ANSI char array

const int SIZE = 2080; // Bytes , 
WCHAR w[SIZE] = { 0 };

MultiByteToWideChar(CP_ACP, 0, filename, -1, w, SIZE); // ANSI to UNICODE
WideCharToMultiByte(CP_UTF8, 0, w, -1, filename, SIZE, 0, 0); // UNICODE to UTF-8

Now “filename” is char* encoded with utf-8 , could be passed to SDK as file path .
Works for me, good luck!


Thanks,It works!

Yes, that is correct, SketchUp deals with UTF-8. This applies to Ruby API as well. I’m adding issues internally to clarify this in the documentation.

I also found this works on Windows using the SU functions. This avoids using Windows-specific functions so may be more cross-platform?

            SUResult res = SU_ERROR_NONE;
            std::wstring path = L"path.skp";
            SUStringRef out_str = SU_INVALID;
            // Because NTFS uses UTF16 encoding.
            SUStringCreateFromUTF16(&out_str, &path[0]);
            char buffer[2000] = "";
            size_t count;
            SUStringGetUTF8(out_str, 2000, buffer, &count);
            res = SUModelCreateFromFile(&model, buffer);


Windows is UTF16 - so it’ll be doing pretty much the same thing.