<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to export json file from autocad? in ObjectARX Forum</title>
    <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761674#M7044</link>
    <description>&lt;P&gt;&lt;SPAN&gt;"now I need to export these values in the form of JSON to my desktop."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For this you need to write you app logic to insert streams in to Json, AutoCAD doesn't have such API which will dump Line information to JSON.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I suggest you search in StackOverFlow or ask any other C++ forum as it is not relevant to AutoCAD API.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 10:47:43 GMT</pubDate>
    <dc:creator>moogalm</dc:creator>
    <dc:date>2018-02-08T10:47:43Z</dc:date>
    <item>
      <title>How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761446#M7041</link>
      <description>&lt;P&gt;I am fetching some information from the autocad file&amp;nbsp;and i am saving those information in the json format.Now i need to export this json.&lt;/P&gt;&lt;P&gt;How can i export the the json to my desktop.&lt;/P&gt;&lt;P&gt;I am using c++ and want to save the file on my desktop.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 09:19:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761446#M7041</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T09:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761590#M7042</link>
      <description>&lt;P&gt;Which file you want to export to Json, can please explain your question in more detail.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 10:10:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761590#M7042</guid>
      <dc:creator>moogalm</dc:creator>
      <dc:date>2018-02-08T10:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761615#M7043</link>
      <description>&lt;P&gt;Actually i want to save information of Line objects from autocad like start point,endpoint and layer name.now I need to export these values in the form of json to my desktop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please Check the attached file.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 10:22:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761615#M7043</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T10:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761674#M7044</link>
      <description>&lt;P&gt;&lt;SPAN&gt;"now I need to export these values in the form of JSON to my desktop."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For this you need to write you app logic to insert streams in to Json, AutoCAD doesn't have such API which will dump Line information to JSON.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I suggest you search in StackOverFlow or ask any other C++ forum as it is not relevant to AutoCAD API.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 10:47:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761674#M7044</guid>
      <dc:creator>moogalm</dc:creator>
      <dc:date>2018-02-08T10:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761813#M7045</link>
      <description>&lt;P&gt;ok man..thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:45:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761813#M7045</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T11:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761836#M7046</link>
      <description>&lt;P&gt;@Anonymous&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example: &lt;A href="https://github.com/nlohmann/json" target="_blank"&gt;https://github.com/nlohmann/json&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 11:56:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761836#M7046</guid>
      <dc:creator>Alexander.Rivilis</dc:creator>
      <dc:date>2018-02-08T11:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761891#M7047</link>
      <description>&lt;P&gt;thank you man..&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 12:14:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7761891#M7047</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-08T12:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7776451#M7048</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did the same process some months ago.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attaching you an example of a 3dpolyline which may help you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This structure worked for me fine and I was able to use the json files with no problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I changed the extension of the file from .json to .txt because I could not post my reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that this will help you.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 09:00:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7776451#M7048</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-14T09:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7776481#M7049</link>
      <description>&lt;P&gt;thanx man..i will look&amp;nbsp; into it&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 09:23:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7776481#M7049</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-14T09:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7808876#M7050</link>
      <description>&lt;P&gt;Sir, the format you provided is exactly what i want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please guide me about how you fetched that data. Can you please share your code so that i can get some help. As i haven't worked on C++ before so it will be so kind of you if you share the code or guide me to that output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 26 Feb 2018 13:05:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7808876#M7050</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-26T13:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7815781#M7051</link>
      <description>&lt;P&gt;Hello again saurabh,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I cannot share my entire code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I can give some guidelines.&lt;/P&gt;&lt;P&gt;First, create a code which prints the data of your entities, for example if a line is found print the start and end point.&lt;/P&gt;&lt;P&gt;When your code is functional and you can read many different entities start adding json commands in order to start creating your json file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You need to understand how to generate a proper structure for your json file so you can then represent your entity in another software.&lt;/P&gt;&lt;P&gt;I would suggest to see some examples in Internet, e.g. &lt;A href="https://stackoverflow.com/questions/4289986/jsoncpp-writing-to-files" target="_blank"&gt;https://stackoverflow.com/questions/4289986/jsoncpp-writing-to-files&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Just start creating a simple json file for a line and then you can develop it even more.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In addition, take a look to the samples of ObjectARX there is very useful information for the different entities.&lt;/P&gt;&lt;P&gt;This will help you to create your own code to read your AutoCAD files. (especially for the 3d solids)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have a proper code to print your entities geometric data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Evangelos&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 13:20:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7815781#M7051</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-02-28T13:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7826456#M7052</link>
      <description>&lt;P&gt;Yes, I do have a proper code and fortunately i am able to print that all in the json file.&lt;/P&gt;&lt;P&gt;I want to use the class structure or struct structure to represent my data in a proper way. But while using struct i am facing the problem in serializing/deserializing data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you help ?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 05:18:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7826456#M7052</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-05T05:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to export json file from autocad?</title>
      <link>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7826925#M7053</link>
      <description>&lt;P&gt;I can sure try,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it depends the way you created your code, so let me give you some ideas:&lt;/P&gt;&lt;P&gt;However, you need to convert from QJson to Json by yourself.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First you need to create a general class in order to dump each entity:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;class EntityDump
{
public:
	EntityDump( const QString&amp;amp; fileName );

	void getLineData(const AcDbEntity* pEnt);

	void write();

private:
	void addEntity(const QJsonObject&amp;amp; obj);

private:
	QString     m_fileName;
	QJsonObject m_root;
	QJsonArray  m_array;

};&lt;/PRE&gt;&lt;P&gt;The constructor should look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;EntityDump::EntityDump( const QString&amp;amp; fileName )
	: m_fileName( fileName )
{
}&lt;/PRE&gt;&lt;P&gt;The method to take the line data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void EntityDump::getLineData(const AcDbEntity* pEnt)
{
	static int lineCount = 1;
	QString lineName = QString("line %1").arg(lineCount++);
	QJsonObject ent, line;

	// Specify that the pEnt is a AcDbLine type
	AcDbLine *pLine = AcDbLine::cast(pEnt);
	// Get the start point
	AcGePoint3d startPoint;
	pLine-&amp;gt;getStartPoint(startPoint);
	// Get the end point
	AcGePoint3d endPoint;
	pLine-&amp;gt;getEndPoint(endPoint);

	// Print the end points
	acutPrintf(L"\nStart point: [%.3f, %.3f, %.3f]",
		startPoint.x, startPoint.y, startPoint.z);
	acutPrintf(L"\nEnd point: [%.3f, %.3f, %.3f]",
		endPoint.x, endPoint.y, endPoint.z);

	// Save to json file
	QJsonArray startCoords;
	startCoords.append(startPoint.x);
	startCoords.append(startPoint.y);
	startCoords.append(startPoint.z);
	line.insert( "start", startCoords);

	QJsonArray endCoords;
	endCoords.append(endPoint.x);
	endCoords.append(endPoint.y);
	endCoords.append(endPoint.z);
	line.insert("end", endCoords);

	ent.insert(lineName, line);
	addEntity(ent);

}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then we need to write it to the array:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void EntityDump::addEntity(const QJsonObject&amp;amp; obj)
{
	m_array.append(obj);
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Finally we need to add the QJson object:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void EntityDump::write()
{
	QFile f(m_fileName);
	if (!f.open(QIODevice::WriteOnly)) {
		acutPrintf(L"\nEntityDump failed to write!");
		return;
	}

	acutPrintf(L"\nEntityDump writing to file");
	m_root["model"] = m_array;
	QJsonDocument doc(m_root);
	QString tmp = doc.toJson();
	//acutPrintf(L"\ncontents: \n%s", tmp.toStdWString().c_str() );
	f.write(doc.toJson());
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As you have this class, you can use it when you read the entities to create your QJson file, So you can have a function like the following.&lt;/P&gt;&lt;P&gt;Here we initialize the class EntityDump and it will be ready to be populated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;void readEntities(AcDbDatabase* pDb)
{
	acutPrintf(L"\nFunction \"readEntities\" is initialized!");
	AcDbBlockTable *pBlkTbl;
	pDb-&amp;gt;getSymbolTable(pBlkTbl, AcDb::kForRead);
	AcDbBlockTableRecord *pBlkTblRcd;
	pBlkTbl-&amp;gt;getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead);
	pBlkTbl-&amp;gt;close();

	AcDbBlockTableRecordIterator *pBlkTblRcdItr;
	pBlkTblRcd-&amp;gt;newIterator(pBlkTblRcdItr);
	AcDbEntity *pEnt;
	EntityDump d("C:\\YourPath\\export.json");
	for (pBlkTblRcdItr-&amp;gt;start(); !pBlkTblRcdItr-&amp;gt;done();
		pBlkTblRcdItr-&amp;gt;step())
	{
		pBlkTblRcdItr-&amp;gt;getEntity(pEnt, AcDb::kForRead);
		acutPrintf(L"\nEntity found!");
		exportGeoProps(pEnt, pDb, d);
		pEnt-&amp;gt;close();
	}
	pBlkTblRcd-&amp;gt;close();
	delete pBlkTblRcdItr;
	d.write();
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The last part now is to use the function exportGeoProps to add a line in your QJson file:&lt;/P&gt;&lt;PRE&gt;void exportGeoProps(AcDbEntity* pEnt, AcDbDatabase* pDb, EntityDump&amp;amp; d)
{
	acutPrintf(L"\nFunction \"exportGeoProps\" is initialized!");
	acutPrintf(L"\nClass type: \"%s\"", pEnt-&amp;gt;isA()-&amp;gt;name());

	if (pEnt-&amp;gt;isKindOf(AcDbLine::desc()))
	{
		d.getLineData(pEnt);
	}
	else
	{
		acutPrintf(L"\n...The found class type is not yet supported");
	}
}&lt;/PRE&gt;&lt;P&gt;So, this is a general process you may use to generate a proper QJson file.&lt;/P&gt;&lt;P&gt;As I said you need to convert the latter process to Json file format but this is not hard at all. QJson and Json are very similar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this process you can dump all the entites you get from AutoCAD but for each entity you must create a different structure in the Json file.&lt;/P&gt;&lt;P&gt;Please not that this is a functional code but it may not be the most efficient one so you can develop it even more &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Evangelos&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Mar 2018 09:42:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/objectarx-forum/how-to-export-json-file-from-autocad/m-p/7826925#M7053</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-03-05T09:42:43Z</dc:date>
    </item>
  </channel>
</rss>

