We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2019-04-26 11:19 AM - last edited on 2022-10-05 01:27 PM by Daniel Kassai
Solved! Go to Solution.
2019-04-26 02:23 PM - last edited on 2021-09-19 03:01 PM by Laszlo Nagy
#include "ClipBoard.hpp"
static GS::Array<API_Guid> GetSelectedElements ()
{
GSErrCode err;
API_SelectionInfo selectionInfo;
API_Neig **selNeigs;
err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false);
BMKillHandle ((GSHandle *)&selectionInfo.marquee.coords);
if (err != NoError || selectionInfo.typeID == API_SelEmpty) {
BMKillHandle ((GSHandle *)&selNeigs);
return GS::Array<API_Guid>();
}
const UInt32 nSel = BMGetHandleSize ((GSHandle)selNeigs) / sizeof (API_Neig);
GS::Array<API_Guid> guidArray;
for (UInt32 i = 0; i < nSel; ++i) {
guidArray.Push ((*selNeigs).guid);
}
BMKillHandle ((GSHandle *)&selNeigs);
return guidArray;
}
static void CopyGUIDsOfCurrentSelectionToClipboard ()
{
GS::UniString string;
const GS::Array<API_Guid> guidsOfCurrentSelection = GetSelectedElements ();
for (UIndex ii = 0; ii < guidsOfCurrentSelection.GetSize (); ++ii) {
string += APIGuidToString (guidsOfCurrentSelection[ii]) + '\n';
}
Clipboard::GetInstance ().SetUniString (Clipboard::uniTextTypeId, string);
}
Simply call CopyGUIDsOfCurrentSelectionToClipboard function to use.
You're welcome
UPDATE: I modified the code, now it's platform independent, works both on Windows and macOS platforms.
2019-04-26 02:23 PM - last edited on 2021-09-19 03:01 PM by Laszlo Nagy
#include "ClipBoard.hpp"
static GS::Array<API_Guid> GetSelectedElements ()
{
GSErrCode err;
API_SelectionInfo selectionInfo;
API_Neig **selNeigs;
err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false);
BMKillHandle ((GSHandle *)&selectionInfo.marquee.coords);
if (err != NoError || selectionInfo.typeID == API_SelEmpty) {
BMKillHandle ((GSHandle *)&selNeigs);
return GS::Array<API_Guid>();
}
const UInt32 nSel = BMGetHandleSize ((GSHandle)selNeigs) / sizeof (API_Neig);
GS::Array<API_Guid> guidArray;
for (UInt32 i = 0; i < nSel; ++i) {
guidArray.Push ((*selNeigs).guid);
}
BMKillHandle ((GSHandle *)&selNeigs);
return guidArray;
}
static void CopyGUIDsOfCurrentSelectionToClipboard ()
{
GS::UniString string;
const GS::Array<API_Guid> guidsOfCurrentSelection = GetSelectedElements ();
for (UIndex ii = 0; ii < guidsOfCurrentSelection.GetSize (); ++ii) {
string += APIGuidToString (guidsOfCurrentSelection[ii]) + '\n';
}
Clipboard::GetInstance ().SetUniString (Clipboard::uniTextTypeId, string);
}
Simply call CopyGUIDsOfCurrentSelectionToClipboard function to use.
You're welcome
UPDATE: I modified the code, now it's platform independent, works both on Windows and macOS platforms.
2019-04-29 06:17 AM
2019-04-29 08:42 AM
2019-05-03 05:38 AM - last edited on 2021-09-19 02:59 PM by Laszlo Nagy
static void CopyGUIDsOfCurrentSelectionToClipboard()
{
GS::UniString string;
const GS::Array<API_Guid> guidsOfCurrentSelection = GetSelectedElements();
for (UIndex ii = 0; ii < guidsOfCurrentSelection.GetSize(); ++ii) {
string += APIGuidToString(guidsOfCurrentSelection[ii]) + '\n';
}
Clipboard::GetInstance().Empty();
Clipboard::GetInstance().SetUniString(Clipboard::uniTextTypeId, string);
}
It works.
I had to call Empty() as well.
2021-09-18 11:28 PM - edited 2021-09-20 02:02 PM
-
2021-09-20 06:05 PM
Hi Guys,
Let me inform you that clipboard handling is supported by C++ API from version 25.
The DGClipboard.hpp is part of the development kit (Support\Modules\DGLib). Using the DG::Clipboard singleton instance you can get or set the content of the clipboard easily.
Please note that the code I previously posted at this topic is outdated (worked for previous versions).
Here is the updated example code:
#include "APIEnvir.h"
#include "ACAPinc.h"
#include "APICommon.h"
#include "DGClipboard.hpp"
static GS::Array<API_Guid> GetSelectedElements ()
{
API_SelectionInfo selectionInfo = {};
GS::Array<API_Neig> selNeigs;
ACAPI_Selection_Get (&selectionInfo, &selNeigs, false);
BMKillHandle ((GSHandle*)&selectionInfo.marquee.coords);
return selNeigs.Transform<API_Guid> ([](const API_Neig& neig) { return neig.guid; });
}
static void CopyGUIDsOfSelectedElementsToClipboard ()
{
GS::UniString string;
const GS::Array<API_Guid> guidsOfCurrentSelection = GetSelectedElements ();
for (const API_Guid& guid : guidsOfCurrentSelection) {
string += APIGuidToString (guid) + '\n';
}
DG::Clipboard::GetInstance ().Clear ();
DG::Clipboard::GetInstance ().SetUniString (DG::Clipboard::uniTextTypeId, string);
}
static GSErrCode SelectElementsFromClipboard ()
{
GS::UniString clipboardString;
DG::Clipboard::GetInstance ().GetUniString (DG::Clipboard::uniTextTypeId, clipboardString);
GS::Array<GS::UniString> guidStrings;
clipboardString.Split ("\n", GS::UniString::SkipEmptyParts, &guidStrings);
const USize count = guidStrings.GetSize ();
GS::Array<API_Neig> neigs = guidStrings.Transform<API_Neig> ([] (const GS::UniString & string) {
return API_Neig (APIGuidFromString (string.ToCStr ().Get ()));
});
return ACAPI_Element_Select (neigs, true);
}