API hide all layers

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-07
05:13 AM
- last edited on
‎2023-08-03
01:17 PM
by
Doreena Deng
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.
- Labels:
-
Add-On (C++)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-07 07:33 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-07 07:51 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-07 11:49 AM
Ben wrote:You should first retrieve all the other attributes of the layer with
creating a loop and hiding all layers so far is not working.
attrib.layer.head.flags |= APILay_Hidden;not
attrib.layer.head.flags = APILay_Hidden;
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-07 03:07 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-07 03:37 PM
Ben wrote:The problem with the original code was not using ACAPI_Attribute_Get first.
It would be nice to know what was wrong with the original code
Central Innovation

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2009-12-08 01:24 AM
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎2010-01-06 07:07 AM