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

How to Create Layer ArchiCAD27/C++

nishida_jp
Booster

I'm programing on ArchiCAD27/VisualStudio C++2019/Windows10.
But my function can not create layer

GSErrCode CreateLayer(GS::UniString layer_name, API_Attribute* attr) {
BNZeroMemory(attr, sizeof(API_Attribute));
attr->header.typeID = API_LayerID;
attr->header.uniStringNamePtr = &layer_name;

GS::UniString title = u8"Create Layer";
GSErrCode res = ACAPI_Attribute_Create(attr, nullptr);    //1)
if (res == APIERR_NEEDSUNDOSCOPE) {
        res = ACAPI_CallUndoableCommand(title, [&]()->GSErrCode {
            return(ACAPI_Attribute_Create(attr, nullptr));
        });
}
return(res);
}



1) res ==  -213031231  meaning
APIERR_NOTSUPPORTED

why i cannot create layer ?


 

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Hi,

 

Are you using a demo version or full version of ArchiCAD? Can you show us how you are calling your function? I was able to call your function successfully and create a layer using;

 

	GS::ErrCode		err = NoError;
	API_Attribute	myAttribute = {};

	err = CreateLayer("A TEST LAYER", &myAttribute);

	ACAPI_WriteReport("CreateLayer returned error [%ld]", false, err);

 

Also, creating an attribute / layer is non-undoable, so doesn't need the undo fallback code.

 

Hope this helps.

Danny

 

View solution in original post

2 REPLIES 2
Solution

Hi,

 

Are you using a demo version or full version of ArchiCAD? Can you show us how you are calling your function? I was able to call your function successfully and create a layer using;

 

	GS::ErrCode		err = NoError;
	API_Attribute	myAttribute = {};

	err = CreateLayer("A TEST LAYER", &myAttribute);

	ACAPI_WriteReport("CreateLayer returned error [%ld]", false, err);

 

Also, creating an attribute / layer is non-undoable, so doesn't need the undo fallback code.

 

Hope this helps.

Danny

 

Thank you.
I success [CreateLayer]

My ArchiCAD is not DEMO version.

I think on our result.
My Error Reason is that [Create Layer] is on Constructor in Global Variables.

CreateLayer() move to oter function from Constructor.

===== Addon.cpp
class MainData {
public:
  MainData() {
   ...
    CreateLayer(...);
   ...
  }
};

MainData mMaindata;
----Addon's Functions
....
================
Error 
Start ArchiCAD27 execute constructor of mMainData before [New Project] or [Load Project].
-->constructor of mMainData
-> CreateLayer() Error
->after [New Project] or [Load Project].
-->on Select Addon Menu
-->call CreateLayer() on button 
-> CreateLayer() Error

//----Success Pattern

 

class MainData {
public:
  MainData() {
   ...
   // CreateLayer(...);
   ...
  }
  void Go() {
   CreateLayer(...);
  }
};
MainData mMaindata;

And 
On Addon - Menu Click
  mMainData.go();