cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 
2024 Technology Preview Program

2024 Technology Preview Program:
Master powerful new features and shape the latest BIM-enabled innovations

Archicad C++ API
About Archicad add-on development using the C++ API.

API hide all layers

Ben Cohen
Enthusiast
Total C++ newbie here, but I am making slow progress.... I am loving the God like powers of the API, but the learning curve is massive. Currently I am stuck on the following...
I am trying to hide all layers in my addon (before turning specific layers on). Turning on specific layers has been fairly easy using the ACAPI_Attribute_Search function but creating a loop and hiding all layers so far is not working. Here is my code

static void Do_HideLayers (void)
{
API_Attribute attrib;
short count, i;
GSErrCode err;

err = ACAPI_Attribute_GetNum (API_LayerID, &count);
if (err) {
WriteReport_Err ("ACAPI_Attribute_GetNum", err);
return;
}


for (i = 1; i <= count; i++) {
BNZeroMemory (&attrib, sizeof (API_Attribute));
attrib.header.typeID = API_LayerID;
attrib.header.index = i;

attrib.layer.head.flags = APILay_Hidden;

err = ACAPI_Attribute_Modify (&attrib, NULL);
if (err != NoError) {
WriteReport_Err ("Unable to modify the layer", err);
return;
}
}

return;
} // Do_HideLayers

I think the problem is in attrib.layer.head.flags but I cant work out what the problem is. Any help is much appreciated.
Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
7 REPLIES 7
Anonymous
Not applicable
hi ben,

it is better and fast way if you create a layer combo "API_HideAllLayers" and set that combo.

other wise try using fallowing way.

static void Do_HideLayers (void)
{
API_Attribute attrib;
short count, i;
GSErrCode err;

err = ACAPI_Attribute_GetNum (API_LayerID, &count);
if (err) {
WriteReport_Err ("ACAPI_Attribute_GetNum", err);
return;
}


for (i = 2; i <= count; i++) //I starts from 2 because 1 is Archicad layer
{
BNZeroMemory (&attrib, sizeof (API_Attribute));
attrib.header.typeID = API_LayerID;
attrib.header.index = i;
err = ACAPI_Attribute_Get(&attrib);
if(!err && attrib.later.head.flags != APILay_Hidden)
{
attrib.layer.head.flags |= APILay_Hidden; // you should add ‘|’ because flags has another bit of information (APILay_Locked)

err = ACAPI_Attribute_Modify (&attrib, NULL);
if (err != NoError) {
WriteReport_Err ("Unable to modify the layer", err);
return;
}
}
}

return;
} // Do_HideLayers
Ben Cohen
Enthusiast
Thanks for the quick reply Ranga

I couldnt get your modified code to work, I still get the error.
Your idea of creating a layer combo and then setting it, maybe a the way to go but there must be a way to set all layers to "hidden" fairly easily .
Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
Ralph Wessel
Mentor
Ben wrote:
creating a loop and hiding all layers so far is not working.
You should first retrieve all the other attributes of the layer with ACAPI_Attribute_Get before you attempt to modify it. ACAPI_Attribute_Modify writes the entire attribute, so the entire data structure must be filled (otherwise, for example, it appears that you are trying to change the layer name to an empty string). Also, make sure you don't change the other layer status bits in the process:
attrib.layer.head.flags |= APILay_Hidden;
not
attrib.layer.head.flags = APILay_Hidden;
Ralph Wessel BArch
Software Engineer Speckle Systems
Ben Cohen
Enthusiast
Thanks Ralph and Ranga

I noticed before your post Ralph that the layer cleanup values had changed to 0, so changing the assignment to |= fixed that. I have now studied some more on bitset operators.
I have since used Rangas suggestion of creating a layer combination to hide all the layers, then I just delete the layer combination once complete - the user will never know it existed. Seems a little backward but it gets the job done. (It would be nice to know what was wrong with the original code).

Thanks for your time .
Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
Ralph Wessel
Mentor
Ben wrote:
It would be nice to know what was wrong with the original code
The problem with the original code was not using ACAPI_Attribute_Get first.
Ralph Wessel BArch
Software Engineer Speckle Systems
Ben Cohen
Enthusiast
Got it working. Cheers Ralph. You get my vote for "Forum Guy of the Year 2009". I should start a poll!!

Thanks.
Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
Anonymous
Not applicable
Ben, I can't believe you didn't ask me first!