Exporting to JSON

Exporting to JSON

Anonymous
Not applicable
1,341 Views
3 Replies
Message 1 of 4

Exporting to JSON

Anonymous
Not applicable

I want to export all the information that i am printing on Autocad console to a json file. 

I have gone through the spotify, nholmann,s code. But those are not working.

As i am working in c++ on my plugin, i want to export the data to json.

 

Please help

0 Likes
1,342 Views
3 Replies
Replies (3)
Message 2 of 4

tbrammer
Advisor
Advisor

I'm not sure whether I fully understand what you want to do.

Do you want to write everything that you write to the text screen with acutPrintf(...) into a JSON file?

You could try to redefine acutPrintf() as a variadic macro, that formats the string with acutSPrintf(ACHAR *buffer, ...), than calls acutPrintf(L"%s", buffer)and finally writes buffer into your JSON file.

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 3 of 4

Anonymous
Not applicable

Yes, initially i want to do exactly what you said.

But i was thinking that i need to include some json libraries first or some include directories for exporting everything to json. 

Is your solution create a new json file and put all my text into that? Or it is totally a different method.

I want to know as i am stuck in this exporting problem.

0 Likes
Message 4 of 4

tbrammer
Advisor
Advisor

There is no JSON API in ObjectARX.  You could either simply write the strings in JSON format using basic C++ I/O functions and do the formatting yourself, or you can use any available JSON C++ lib that suit your needs.

 

It depends on your needs how you manage to create the JSON output. Let's say in your ARX you call

 

 

acutPrintf(L"My first line");
acutPrintf(L"My second line");

and you want your JSON to look like this:

 

 

 

{ "TextScreen": [ ""
,"My first line"
,"My second line"
]}

To make sure that you get a valid JSON:

 

  • your output needs a "header line" like the above line   { "TextScreen": [ ""
  • you have to comma-separate the strings in each output from acutPrintf(). No comma after last entry!
  • you have to make sure that you add a "footer line" like the line       ])  to terminate your JSON.
    Ask yourself at which point you need the proper termination line.
  • Take care with special characters. I.e. newline (\n) should be replaced by L"\\n". 

Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.