How to get currently selected Library Part
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2015-11-02
05:25 PM
- last edited on
2023-07-13
02:56 PM
by
Doreena Deng
2015-11-02
05:25 PM
Hi all 
I try to get the currently selected library part.
I mean the object selected (in green) by user in the current model.
I have tried following code but it doesn't seem to work
(this is a quick and dirty testing code)

I try to get the currently selected library part.
I mean the object selected (in green) by user in the current model.
I have tried following code but it doesn't seem to work

GSErrCode err; // Get selected elements API_SelectionInfo selectionInfo; API_Neig **selNeigs; err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false); if (err == NoError) { if (selectionInfo.typeID != API_SelEmpty) { UInt32 ii, nSel; nSel = BMGetHandleSize ((GSHandle) selNeigs) / sizeof (API_Neig); for (ii = 0; ii < nSel && err == NoError; ii++) { GS::UniString selectedGuid = APIGuidToString((*selNeigs)[ii].guid); API_NeigID selectedID = (*selNeigs)[ii].neigID; API_Element element; BNZeroMemory (&element, sizeof (API_Element)); element.header.guid = (*selNeigs)[ii].guid; err = ACAPI_Element_Get(&element); if(err == NoError) { // Find the library part API_LibPart libpart; BNZeroMemory (&libpart, sizeof (libpart)); libpart.index = element.object.libInd; err = ACAPI_LibPart_Search (&libpart, false); if (err == NoError) { double aParam = 0.0; double bParam = 0.0; Int32 paramNum = 0; API_AddParType** addPars = NULL; err = ACAPI_LibPart_GetParams (libpart.index, &aParam, &bParam, ¶mNum, &addPars); if (err == NoError) { for (Int32 i = 0; i < paramNum; i++) { if(CHCompareCStrings ("BimObject id", (*addPars).name) == 0) { std::wstring objectUrl = L"xxx"; ShowPlatform(objectUrl); BMKillHandle ((GSHandle *) &selNeigs); return; } } } } } } BMKillHandle ((GSHandle *) &selNeigs); } }What am i doing wrong in this code ?
(this is a quick and dirty testing code)
Labels:
- Labels:
-
Add-On (C++)
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2015-11-02 06:07 PM
2015-11-02
06:07 PM
Me again 
I have finally found out what was wrong.
Here is the working code (draft code...to be cleaned😉 )

I have finally found out what was wrong.
Here is the working code (draft code...to be cleaned
GSErrCode err; // Get selected elements API_SelectionInfo selectionInfo; API_Neig **selNeigs; err = ACAPI_Selection_Get (&selectionInfo, &selNeigs, false); if (err == NoError) { if (selectionInfo.typeID != API_SelEmpty) { UInt32 ii, nSel; nSel = BMGetHandleSize ((GSHandle) selNeigs) / sizeof (API_Neig); for (ii = 0; ii < nSel && err == NoError; ii++) { GS::UniString selectedGuid = APIGuidToString((*selNeigs)[ii].guid); API_NeigID selectedID = (*selNeigs)[ii].neigID; API_Element element; BNZeroMemory (&element, sizeof (API_Element)); element.header.guid = (*selNeigs)[ii].guid; err = ACAPI_Element_Get(&element); if(err == NoError) { // Find the library part API_LibPart libpart; BNZeroMemory (&libpart, sizeof (libpart)); libpart.index = element.object.libInd; err = ACAPI_LibPart_Get (&libpart); if (err == NoError) { double aParam = 0.0; double bParam = 0.0; Int32 paramNum = 0; API_AddParType** addPars = NULL; err = ACAPI_LibPart_GetParams (libpart.index, &aParam, &bParam, ¶mNum, &addPars); if (err == NoError) { for (Int32 i = 0; i < paramNum; i++) { GS::UniString us = (*addPars).uDescname; if(us == L"BimObject id") { // Todo : Do someting here BMKillHandle ((GSHandle *) &selNeigs); return; } } } } } } BMKillHandle ((GSHandle *) &selNeigs); } }