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

Is there any way to lock GDL using API C++?

LeeJaeYoung
Virtuoso

Is there any way to lock GDL using API C++?

 

for example

1. When the api is executed, the cpu id is read, and if it is correct, a specific variable is created so that GDL can read this variable so that the value of GDL can be changed.

 

2. How to create a variable in the api c++ model view option so that GDL can read this variable and change the value of GDL if correct

 

It's not my opinion, it's a question I'm asking because I'm curious about how I can do it because someone told me that they are locking GDL using the api.

 

AC27 on window 11
8 REPLIES 8

I asked AI and he said:

 

"It is not possible to "lock" GDL using the API in ARCHICAD. GDL is a programming language used to create parametric objects in ARCHICAD, and it can be freely modified by the user. The API provides a way to interact with ARCHICAD programmatically, but it does not provide a way to prevent the user from modifying GDL code.

That being said, it is possible to use the API to create custom parameters or variables that can be used by GDL scripts. For example, you could create a custom parameter that stores a value, and then read that value in a GDL script to modify the behavior of an object.

To create a custom parameter using the ARCHICAD API, you can use the ACAPI_Parameter_Create function. Here's an example of how you could create a custom parameter named "MyParam" that stores a Boolean value:

 

API_ParID paramId = ACAPI_Parameter_Create("MyParam", APIParBooleanType);

 

You can then set the value of the parameter using the ACAPI_Parameter_SetValue function:

API_ParValue paramValue;
BNZeroMemory(&paramValue, sizeof(paramValue));
paramValue.boolValue = true; // set the parameter value to true
ACAPI_Parameter_SetValue(paramId, &paramValue, sizeof(paramValue));

 

In your GDL script, you can read the value of the parameter using the "Parameter" command:

Parameter("MyParam", MyParam)

 

The value of the "MyParam" variable in the GDL script will be set to the value of the "MyParam" custom parameter you created using the API.

Note that this approach does not "lock" GDL in any way, as the user can still modify the GDL code directly if they choose to do so. However, it does provide a way to create custom parameters that can be used to modify the behavior of objects created with GDL."

arch. ernest atanasiu
AC 10-26 INT/GER/FR on Win 10/ Win 11

The variable you are talking about is a variable within archicad.
That means you can call it from GDL.
thank you

AC27 on window 11

I'm trying to study ACAPI_Parameter_Create.
But which manual should I look at?
I couldn't find the function in apidevkit.chm.
It would be more appreciated if you could point me to a sample file.

AC27 on window 11

LeeJaeYoung_0-1679386737554.png

 

All warning messages appear.

Are there any items that need to be included?
I would like to know the manual.
I can't find it no matter how much I look for it.

AC27 on window 11

Those functions don't exist in the Archicad C++ API. @Ernest Atanasiu cited an answer from an AI which seems to have hallucinated the functions. The whole AI answer is incorrect in many different ways, I would completely disregard it in your case.

Bernd Schwarzenbacher - Archicad Add-On Developer - Get Add-Ons & Archicad Tips on my Website: bschwb.com
Laszlo Nagy
Community Admin
Community Admin

I also asked ChatGPT about GDL-related things for fun. It gave me incorrect answers almost every time, it is really not a reliable source of GDL and Archicad API knowledge. 

 

Loving Archicad since 1995 - Find Archicad Tips at x.com/laszlonagy
AMD Ryzen9 5900X CPU, 64 GB RAM 3600 MHz, Nvidia GTX 1060 6GB, 500 GB NVMe SSD
2x28" (2560x1440), Windows 10 PRO ENG, Ac20-Ac27

Sorry I didn't specify, I don't know GDL to correct ChatGPT but I wanted to see if it works.
I reposted the question again and I got a different answer. Is this any good?

Yes, it is possible to lock GDL using API C++. You can use the API to create a custom parameter or attribute for your GDL object, which can be set or retrieved programmatically.

To achieve your specific use case, you can follow the following steps:

1. Use the API to read the CPU ID of the computer where the ArchiCAD application is running.
2. Compare the CPU ID with the correct value, and if it matches, create a custom parameter or attribute in the GDL object with a specific name and value.
3. In the GDL object, read the value of the custom parameter or attribute created in step 2 and check if it matches the correct value.
4. If the value matches, you can allow the GDL object to perform the required action or change its behavior.

To create a custom parameter or attribute in the API C++ model view option, you can use the `API_Attribute` and `API_Property` structures provided by the API. Here's an example of how you can create a custom attribute:

 

API_Attribute attr;
BNZeroMemory(&attr, sizeof(API_Attribute));
attr.header.typeID = API_Attr_Types;
attr.header.version = API_VERSION;
attr.header.attrType = APIAttr_IntegerType;
BNZeroMemory(&attr.name, sizeof(API_String128));
BNstrcpy(attr.name, "CustomAttr");
attr.header.flags = APIAttr_Permanent;
attr.int32 = 123;

GSErrCode err = ACAPI_Attribute_Create(&attr, API_ANY);
if (err != NoError) {
// handle error
}

 

This code creates a custom attribute named "CustomAttr" with an integer value of 123.

In your GDL object, you can read the value of this attribute using the `Attribute` function, like this:

```
IF Attribute ("CustomAttr") = 123 THEN
! perform action
ENDIF
```

This code checks if the value of the "CustomAttr" attribute is 123 and performs the required action if it is true.

arch. ernest atanasiu
AC 10-26 INT/GER/FR on Win 10/ Win 11

LeeJaeYoung_0-1682609853106.png

I couldn't find the attribute function.

AC27 on window 11

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!