BIM Coordinator Program (INT) April 22, 2024

Find the next step in your career as a Graphisoft Certified BIM Coordinator!

Archicad C++ API
About Archicad add-on development using the C++ API.

Special Characters turn into ???

Dayiz
Booster

Hello dear Graphisoft Community,

 

I'm currently writing an AddOn to rename layouts, but im getting trouble with special characters.

We work in german and special chars like "äöüß" are part of our projects.

To rename the layouts, i read from a csv file the old and new ref and name (https://archicadapi.graphisoft.com/documentation/api_windowinfo for reference) and rename if i find a match. This part works fine, but as soon as a layout consists of special charaters, everything goes bad:

ForumThread.PNG

This is how the data looks after reading it from the .csv (i read the file with fstream and every string is saved as std::string inside a vector). Everytime there is a special characters, I only get ????????.

This also stays after renaming the layouts:

layouts.PNG

But as you can see, special characters work just fine (like Ü).

So I'm not sure what causes the behavior, most likely it is how I convert std::string to GS::uchar_t

 

I've tried (note - csvInfos[ev.GetListItem() - 1] returns a std::string):

Spoiler

str1 = GS::UniString(std::get<0>(csvInfos[ev.GetListItem() - 1]).c_str(), CC_UTF8)

str1 = tb.ToUniString(tb.StringToWString(std::get<2>(csvInfos[ev.GetListItem() - 1])))

(from https://community.graphisoft.com/t5/Developer-forum/Convert-from-GS-UniString-to-std-string/td-p/306...)
and some other things, which didn't work.

The above code was for displaying the old and new values in a list.

 

for the renaming part I tried the same things as for the list and

 

Spoiler
GS::ucsncpy(dbi.name, GS::UniString(std::get<3>(layoutCsvInfos[i]).c_str(), CC_UTF8).ToUStr(), API_UAddParStrLen - 1);

 

But nothing works.

Can anyone give me a tip on how to work with special characters in ArchiCAD or how I can properly convert std::string to GS::uchar_t?

 

 

3 REPLIES 3
Dayiz
Booster

Well, I found a solution...

Turns out my csv-File wasn't utf-8. After exporting my csv to utf-8, it worked like a charm.

Leonardo Lopes
Contributor

Hi, i am from Brazil and i went through something really similar when trying to write strings like "construção", "métodos", etc. I solved it by using a GS::UniString object with the macro L( ) inside it. Something like this:

GS::UniString name {L("Construção")}; // Ok
GS::UniString name_2 {"Construção"}; // Results in ??????????

 

I found this solution in some of the SDK examples. I don't know if the special characters you mentioned will work with this method, but you can give it a shot.

Hey, thanks for the suggestion, but  this method doesn't work for me since i don't know the strings during compile time and you can't do things like {u8(stringVariable)}

Learn and get certified!