<?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: Call ArchiCAD api functions from Wpf window button in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/622386#M9752</link>
    <description>&lt;P&gt;Up&lt;/P&gt;</description>
    <pubDate>Mon, 12 Aug 2024 09:20:11 GMT</pubDate>
    <dc:creator>Islam_Mohamed</dc:creator>
    <dc:date>2024-08-12T09:20:11Z</dc:date>
    <item>
      <title>Call ArchiCAD api functions from Wpf window button</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/622260#M9749</link>
      <description>&lt;P&gt;Hi folks,&lt;BR /&gt;I'm working on an Addon where I need to have a wpf window so now I'm trying to create a prototype and what I did up till now is to use c++/CLI as a bridge between wpf project and c++ project.&lt;BR /&gt;I managed to call an ArchiCAD api function when a button in wpf window is clicked but ArchiCAD crashes I think because I'm in the wpf thread and I'm not in ArchiCAD context.&lt;BR /&gt;&lt;BR /&gt;Does anyone have an idea how can I handle that ?&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;DIV&gt;&lt;LI-CODE lang="cpp"&gt;#include "ExportIfcUtils.h"
#include &amp;lt;shlobj.h&amp;gt;
#include &amp;lt;iostream&amp;gt;
#include &amp;lt;string&amp;gt;

bool ShowFolderSelectionDialog(IO::Location&amp;amp; selectedFolder) {
BROWSEINFO bi;
ZeroMemory(&amp;amp;bi, sizeof(bi));
TCHAR path[MAX_PATH];
bi.pszDisplayName = path;
bi.lpszTitle = L"Select a folder";
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;

LPITEMIDLIST pidl = SHBrowseForFolder(&amp;amp;bi);
if (pidl != 0) {
if (SHGetPathFromIDList(pidl, path)) {
// Ensure that the path is properly converted to a wide string and used to construct IO::Location
std::wstring wPath(path);
std::string nPath = ConvertWideToNarrow(wPath); // Convert wide string to narrow string
IO::Name folderName(nPath.c_str()); // Construct IO::Name from the narrow string
selectedFolder = IO::Location(folderName); // Construct IO::Location from IO::Name

// Free memory used
IMalloc* imalloc = 0;
if (SUCCEEDED(SHGetMalloc(&amp;amp;imalloc))) {
imalloc-&amp;gt;Free(pidl);
imalloc-&amp;gt;Release();
}
// Add logging to verify the value of selectedFolder
ACAPI_WriteReport("Selected Folder: " + folderName.ToString(), false);
return true;
}
}
return false;
}
void PrintError(GSErrCode err) {
char errorMessage[256];
sprintf(errorMessage, "Error code: 0x%X", err);
ACAPI_WriteReport(errorMessage, true);
}

void Do_Save_IfcFile(API_IfcTypeID ifcFileType)
{
IO::Location selectedFolder;
if (!ShowFolderSelectionDialog(selectedFolder)) {
ACAPI_WriteReport("Folder selection canceled.", false);
return;
}
try
{
API_IFCTranslatorIdentifier firstTranslator;
GS::Array&amp;lt;API_IFCTranslatorIdentifier&amp;gt; ifcExportTranslators;
GSErrCode err = ACAPI_IFC_GetIFCExportTranslatorsList(ifcExportTranslators);
if (err != NoError) {
ACAPI_WriteReport("Can't get IFC export translator", true);
return;
}

if (DBVERIFY(!ifcExportTranslators.IsEmpty())) {
firstTranslator = ifcExportTranslators.GetFirst();
}

API_SavePars_Ifc pars_ifc = {};
pars_ifc.subType = ifcFileType;
pars_ifc.translatorIdentifier = firstTranslator;
//pars_ifc.elementsToIfcExport = API_VisibleElementsOnAllStories;
pars_ifc.elementsToIfcExport = API_EntireProject;

pars_ifc.elementsSet = nullptr;

API_FileSavePars fsp = {};
fsp.fileTypeID = APIFType_IfcFile;
IO::Name fileName;

switch (ifcFileType) {
case API_IFCZIP:
fileName = IO::Name("IFCTest.ifczip");
break;
case API_IFC:
default:
fileName = IO::Name("IFCTest.ifc");
break;
}
IO::Location outputIFCFile(selectedFolder, fileName);

fsp.file = &amp;amp;outputIFCFile;
err = ACAPI_ProjectOperation_Save(&amp;amp;fsp, &amp;amp;pars_ifc);
if (err == APIERR_READONLY) {
ACAPI_WriteReport("The plan could not be saved either because it's open in read-only mode, or has never been saved to a file and the fileSavePars is nullptr.", true);
}
if (err == APIERR_REFUSEDCMD) {
ACAPI_WriteReport("You are running from Demo version", true);
}
if (err != NoError) {
ACAPI_WriteReport("Error in APIDo_SaveID (IFC): %s", true);
}
}
catch (const std::exception&amp;amp; ex)
{
ACAPI_WriteReport("Exception", true);
}
}&lt;/LI-CODE&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 12 Aug 2024 06:19:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/622260#M9749</guid>
      <dc:creator>hossamamer7</dc:creator>
      <dc:date>2024-08-12T06:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: Call ArchiCAD api functions from Wpf window button</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/622386#M9752</link>
      <description>&lt;P&gt;Up&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 09:20:11 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/622386#M9752</guid>
      <dc:creator>Islam_Mohamed</dc:creator>
      <dc:date>2024-08-12T09:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: Call ArchiCAD api functions from Wpf window button</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/627365#M9759</link>
      <description>&lt;P&gt;Hi. I don't have any experience with WPF so can't comment on that part specifically.&lt;BR /&gt;But it's possible to expose add-on functions that can than be called by other programs fia http calls. (That's how the python API works and can be extended).&lt;BR /&gt;So an alternative would be to create an add-on that exposes the needed functionality and have the WPF part as a separate program that calls into the API via http requests.&lt;BR /&gt;Check out &lt;A href="https://graphisoft.github.io/archicad-api-devkit/group___add_on_add_on_communication.html#gac25df37404cabb785e572a4d168b5d52" target="_self"&gt;ACAPI_AddOnAddOnCommunication_InstallAddOnCommandHandler&lt;/A&gt;, the CommandTest example Add-On and also this project &lt;A href="https://github.com/tlorantfy/archicad-additional-json-commands" target="_blank"&gt;https://github.com/tlorantfy/archicad-additional-json-commands&lt;/A&gt; to see how it's used.&lt;BR /&gt;&lt;BR /&gt;Hope that helps,&lt;BR /&gt;Bernd&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2024 06:20:49 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/627365#M9759</guid>
      <dc:creator>BerndSchwarzenbacher</dc:creator>
      <dc:date>2024-08-22T06:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Call ArchiCAD api functions from Wpf window button</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/627534#M9764</link>
      <description>&lt;P&gt;Thanks for your contribution,&amp;nbsp;&lt;BR /&gt;Actually, the problem wasn't in the attached code, the problem was that I was trying to open the wpf window as a modeless window which I think ArchiCAD doesn't support so I had to make it modal window and open it with ShowDialog() instead of Show() and the issue now is solved.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2024 11:06:47 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/Call-ArchiCAD-api-functions-from-Wpf-window-button/m-p/627534#M9764</guid>
      <dc:creator>hossamamer7</dc:creator>
      <dc:date>2024-08-23T11:06:47Z</dc:date>
    </item>
  </channel>
</rss>

