2019-03-07 05:58 PM - last edited on 2022-10-04 04:35 PM by Daniel Kassai
// ***************************************************************************** // Source code for the Geometry Test Add-On // API Development Kit 21; Mac/Win // // Namespaces: Contact person: // -None- // // [SG compatible] - Yes // ***************************************************************************** #include "APIEnvir.h" #define _Geometry_Test_TRANSL_ // ---------------------------------- Includes --------------------------------- //#include <stdio> #include <string> #include "ACAPinc.h" // also includes APIdefs.h #include "APICommon.h" #include "basicgeometry.h" // ---------------------------------- Types ------------------------------------ // ---------------------------------- Variables -------------------------------- // ---------------------------------- Prototypes ------------------------------- bool GetZoneElement(API_Guid &OutGuid) { API_SelectionInfo selectionInfo; // Get selection API_Neig **selNeig; // Get selection GSErrCode err; UInt32 nSel; UInt32 k = 0; err = ACAPI_Selection_Get(&selectionInfo, &selNeig, true); BMKillHandle((GSHandle *)&selectionInfo.marquee.coords); if (err != NoError && err != APIERR_NOSEL) { ErrorBeep("ACAPI_Selection_GetInfo", err); BMKillHandle((GSHandle *)& selNeig); return false; } if (selectionInfo.typeID != API_SelEmpty) { nSel = BMGetHandleSize((GSHandle)selNeig) / sizeof(API_Neig); for (UInt32 i = 0; i < nSel && err == NoError; i++) { if (!ACAPI_Element_Filter((*selNeig).guid, APIFilt_IsEditable)) continue; OutGuid = (*selNeig).guid; WriteReport("Guid select: %s", static_cast<const char *> (APIGuid2GSGuid(OutGuid).ToUniString().ToCStr())); ++k; } } if (k == 0) WriteReport("No select %ld", k); BMKillHandle((GSHandle *)&selNeig); return k > 0 ? true : false; } GSErrCode ModifyZonePos(const API_Guid& guid) { API_Element element; API_ElementMemo memo; GSErrCode err; BNZeroMemory(&element, sizeof(API_Element)); BNZeroMemory(&memo, sizeof(API_ElementMemo)); // get actual zone element.header.guid = guid; err = ACAPI_Element_Get(&element); if (err == NoError) err = ACAPI_Element_GetMemo(element.header.guid, &memo); if (err != NoError) return err; // delete original zone, before create a new zone, if not want get alert API_Elem_Head** heads = (API_Elem_Head**)BMhAllClear(sizeof(API_Elem_Head)); (*heads)[0].guid = guid; // 0 -1 zones ACAPI_Element_Delete(heads, 1); BMhKill((GSHandle*)&heads); // modify pos and create a new zone WriteReport("Create %s: %s", (ElemID_To_Name (element.header.typeID)).ToCStr().Get(), static_cast<const char *> (APIGuid2GSGuid(guid).ToUniString().ToCStr())); err = ACAPI_Element_Create (&element, &memo); ACAPI_DisposeElemMemoHdls(&memo); return err; } // ============================================================================= // // Main functions // // ============================================================================= static void Do_Test (void) { ACAPI_CallUndoableCommand ("Geometry Test -- Create elements", [&] () -> GSErrCode { GSErrCode err; API_Guid guid; GetZoneElement (guid); err = ModifyZonePos(guid); return err; }); return; } /* Do_Test */ // ----------------------------------------------------------------------------- // Entry points to handle Archicad events // // ----------------------------------------------------------------------------- GSErrCode __ACENV_CALL MenuCommandHandler (const API_MenuParams *params) { switch (params->menuItemRef.itemIndex) { case 1: Do_Test (); break; } return NoError; } // DoCommand // ============================================================================= // // Required functions // // ============================================================================= //------------------------------------------------------ // Dependency definitions //------------------------------------------------------ API_AddonType __ACENV_CALL CheckEnvironment (API_EnvirParams* envir) { RSGetIndString (&envir->addOnInfo.name, 32000, 1, ACAPI_GetOwnResModule ()); RSGetIndString (&envir->addOnInfo.description, 32000, 2, ACAPI_GetOwnResModule ()); return APIAddon_Normal; } /* CheckEnvironment */ //------------------------------------------------------ // Interface definitions //------------------------------------------------------ GSErrCode __ACENV_CALL RegisterInterface (void) { ACAPI_Register_Menu (32500, 0, MenuCode_UserDef, MenuFlag_Default); return NoError; } /* RegisterInterface */ //------------------------------------------------------ // Called when the Add-On has been loaded into memory // to perform an operation //------------------------------------------------------ GSErrCode __ACENV_CALL Initialize (void) { GSErrCode err = ACAPI_Install_MenuHandler (32500, MenuCommandHandler); if (err != NoError) DBPrintf ("Geometry_Test:: Initialize() ACAPI_Install_MenuHandler failed\n"); return err; } /* Initialize */ // ----------------------------------------------------------------------------- // FreeData // called when the Add-On is going to be unloaded // ----------------------------------------------------------------------------- GSErrCode __ACENV_CALL FreeData (void) { return NoError; } // FreeData
Solved! Go to Solution.
2019-03-20 05:34 PM
2019-03-20 05:34 PM
2019-04-20 06:57 PM