<?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 Import external detail in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Import-external-detail/m-p/265307#M2351</link>
    <description>&lt;DIV class="actalk-migrated-content"&gt;Hello developers,&lt;BR /&gt;my goal is to import an external DWG file as a drawing in a new detail window. This is very trivial to do as a user, but I am having an issue with doing it programmatically.&lt;BR /&gt;As I have understood in the documentation I can't just create a new drawing element and bind a link to it. I should rather use a call to DXF/DWG add-on and it is where I got stuck on.&lt;BR /&gt;&lt;BR /&gt;I haven't found much about that. Just one example in the documentation where a dwg file is imported as lib part. So I tried similar to create a drawing. Can I get some advice from you? &lt;BR /&gt;&lt;BR /&gt;Trying to run DXF/DWG add-on between APIDb_StartDrawingDataID and APIDb_StopDrawingDataID calls.
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;class IDFSession {

private:
	bool    inited;

public:
	explicit IDFSession() {
		inited = (ACAPI_Database(APIDb_StartDrawingDataID, nullptr, nullptr) == NoError);
	}

	~IDFSession() {
		if (inited) {
			GSPtr outIDFData = nullptr;
			if (GetIDFData(&amp;amp;outIDFData, nullptr))
				BMKillPtr(&amp;amp;outIDFData);
		}
	}

	bool GetIDFData(GSPtr *outIDFData, API_Box *bounds) {
		if (!inited || outIDFData == nullptr)
			return false;

		bool ret = (ACAPI_Database(APIDb_StopDrawingDataID, outIDFData, bounds) == NoError);

		inited = false;
		return ret;
	}
};

GSErrCode ImportDrawing()
{
	IDFSession  idfSession;                      // 1

	GSErrCode   ret = ReadAction();              // 2

	if (ret == NoError) {
		API_Box bounds = { 0.0, 0.0, 0.0, 0.0 };
		GSPtr   idfData = nullptr;

		if (idfSession.GetIDFData(&amp;amp;idfData, &amp;amp;bounds)) {    // 3
			CreateDrawing_UndoableCall(idfData, bounds);   // 4
		} else {
			WriteReport("No drawing data.");
		}
	}

	return ret;
}

static GSErrCode		ReadAction(void)
{
	API_ModulID	mdid = { 1198731108, 1322668197 };		// DXF/DWG add-on
	GSErrCode	err;

	double scale = 100.0;
	bool rebuild = false;
	err = ACAPI_Database(APIDb_ChangeDrawingScaleID, &amp;amp;scale, &amp;amp;rebuild);
	if (err != NoError) {
		WriteReport("Error in APIDb_ChangeDrawingScaleID: %s", ErrID_To_Name(err));
		return err;
	}

	IO::Location dwgFileLoc;
	if (!GetOpenFile(&amp;amp;dwgFileLoc, "dwg", "*.dwg"))
		return Cancel;
	
	// call the Dxf add-on
	GSHandle parHdl;
	err = ACAPI_Goodies(APIAny_InitMDCLParameterListID, &amp;amp;parHdl);
	if (err == NoError) {
		IO::URL url;
		dwgFileLoc.ToURL(&amp;amp;url);

		API_MDCLParameter par;
		BNZeroMemory(&amp;amp;par, sizeof(par));
		par.name = "FileName";
		par.type = MDCLPar_string;

		char str[512] = { 0 };
		CHTruncate((const char*)url, str, sizeof(str));
		par.string_par = str;

		err = ACAPI_Goodies(APIAny_AddMDCLParameterID, parHdl, &amp;amp;par);

		if (err == NoError)
			err = ACAPI_Command_Call(&amp;amp;mdid, 'OOBJ', 1, parHdl, nullptr, true);
	}

	ACAPI_Goodies(APIAny_FreeMDCLParameterListID, &amp;amp;parHdl);
	
	return err;
}		// ReadAction
&lt;/PRE&gt;
I am not sure about my command call, maybe I just need a different cmdID. I haven't found any documentation for it. Maybe I should focus on if I can use a lib part to create drawing from. I will be glad for every opinion.&lt;BR /&gt;&lt;BR /&gt;Thank you for your attention.&lt;/DIV&gt;</description>
    <pubDate>Wed, 15 Sep 2021 08:31:01 GMT</pubDate>
    <dc:creator>Dejmas</dc:creator>
    <dc:date>2021-09-15T08:31:01Z</dc:date>
    <item>
      <title>Import external detail</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Import-external-detail/m-p/265307#M2351</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;Hello developers,&lt;BR /&gt;my goal is to import an external DWG file as a drawing in a new detail window. This is very trivial to do as a user, but I am having an issue with doing it programmatically.&lt;BR /&gt;As I have understood in the documentation I can't just create a new drawing element and bind a link to it. I should rather use a call to DXF/DWG add-on and it is where I got stuck on.&lt;BR /&gt;&lt;BR /&gt;I haven't found much about that. Just one example in the documentation where a dwg file is imported as lib part. So I tried similar to create a drawing. Can I get some advice from you? &lt;BR /&gt;&lt;BR /&gt;Trying to run DXF/DWG add-on between APIDb_StartDrawingDataID and APIDb_StopDrawingDataID calls.
&lt;PRE&gt;&lt;I&gt;
&lt;/I&gt;class IDFSession {

private:
	bool    inited;

public:
	explicit IDFSession() {
		inited = (ACAPI_Database(APIDb_StartDrawingDataID, nullptr, nullptr) == NoError);
	}

	~IDFSession() {
		if (inited) {
			GSPtr outIDFData = nullptr;
			if (GetIDFData(&amp;amp;outIDFData, nullptr))
				BMKillPtr(&amp;amp;outIDFData);
		}
	}

	bool GetIDFData(GSPtr *outIDFData, API_Box *bounds) {
		if (!inited || outIDFData == nullptr)
			return false;

		bool ret = (ACAPI_Database(APIDb_StopDrawingDataID, outIDFData, bounds) == NoError);

		inited = false;
		return ret;
	}
};

GSErrCode ImportDrawing()
{
	IDFSession  idfSession;                      // 1

	GSErrCode   ret = ReadAction();              // 2

	if (ret == NoError) {
		API_Box bounds = { 0.0, 0.0, 0.0, 0.0 };
		GSPtr   idfData = nullptr;

		if (idfSession.GetIDFData(&amp;amp;idfData, &amp;amp;bounds)) {    // 3
			CreateDrawing_UndoableCall(idfData, bounds);   // 4
		} else {
			WriteReport("No drawing data.");
		}
	}

	return ret;
}

static GSErrCode		ReadAction(void)
{
	API_ModulID	mdid = { 1198731108, 1322668197 };		// DXF/DWG add-on
	GSErrCode	err;

	double scale = 100.0;
	bool rebuild = false;
	err = ACAPI_Database(APIDb_ChangeDrawingScaleID, &amp;amp;scale, &amp;amp;rebuild);
	if (err != NoError) {
		WriteReport("Error in APIDb_ChangeDrawingScaleID: %s", ErrID_To_Name(err));
		return err;
	}

	IO::Location dwgFileLoc;
	if (!GetOpenFile(&amp;amp;dwgFileLoc, "dwg", "*.dwg"))
		return Cancel;
	
	// call the Dxf add-on
	GSHandle parHdl;
	err = ACAPI_Goodies(APIAny_InitMDCLParameterListID, &amp;amp;parHdl);
	if (err == NoError) {
		IO::URL url;
		dwgFileLoc.ToURL(&amp;amp;url);

		API_MDCLParameter par;
		BNZeroMemory(&amp;amp;par, sizeof(par));
		par.name = "FileName";
		par.type = MDCLPar_string;

		char str[512] = { 0 };
		CHTruncate((const char*)url, str, sizeof(str));
		par.string_par = str;

		err = ACAPI_Goodies(APIAny_AddMDCLParameterID, parHdl, &amp;amp;par);

		if (err == NoError)
			err = ACAPI_Command_Call(&amp;amp;mdid, 'OOBJ', 1, parHdl, nullptr, true);
	}

	ACAPI_Goodies(APIAny_FreeMDCLParameterListID, &amp;amp;parHdl);
	
	return err;
}		// ReadAction
&lt;/PRE&gt;
I am not sure about my command call, maybe I just need a different cmdID. I haven't found any documentation for it. Maybe I should focus on if I can use a lib part to create drawing from. I will be glad for every opinion.&lt;BR /&gt;&lt;BR /&gt;Thank you for your attention.&lt;/DIV&gt;</description>
      <pubDate>Wed, 15 Sep 2021 08:31:01 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Import-external-detail/m-p/265307#M2351</guid>
      <dc:creator>Dejmas</dc:creator>
      <dc:date>2021-09-15T08:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Import external detail</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Import-external-detail/m-p/265308#M2352</link>
      <description>Your overall process (using the existing DXF/DWG importer) is correct. I've only used this add-on through the API for creating library parts (as the example shows), so I can't say for sure that it can import as a plain drawing. However, if you don't find any way to make that work, you could place the DWG as a library part and then use the API to explode it into constituent parts, e.g. &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;ACAPI_LibPart_ShapePrims&lt;E&gt;&lt;/E&gt; or &lt;I&gt;&lt;/I&gt;&lt;S&gt;&lt;I&gt;&lt;I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/S&gt;ACAPI_Element_ShapePrims&lt;E&gt;&lt;/E&gt;.</description>
      <pubDate>Tue, 28 Jul 2020 08:02:30 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Import-external-detail/m-p/265308#M2352</guid>
      <dc:creator>Ralph Wessel</dc:creator>
      <dc:date>2020-07-28T08:02:30Z</dc:date>
    </item>
  </channel>
</rss>

