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

v27 How to set and turn off overrides for fills and surfaces (Not Graphic Overrides)

Ben Cohen
Advocate

Hi All

 

I am in the process of upgrading another addon to v27.. This one loops through a plan and sets the pens and surfaces to the companies standards.. 

Back in v24, i could set an overridden cutfill fairly easily, say

element.slab.penOverride.cutFillBackgroupPen = 19;

or

element.wall.refMat.attributeIndex = 100;

 

In version 27 this has changed and for the life of me I can't work it out.. 

Question 1. How do we set these override pens and surfaces in v27

Question 2. How to we set the override to off in v27

 

Below is the fill overrides I am talking about

 

BenCohen_0-1698134439381.png

 

These are the surface overrides I am talking about

BenCohen_1-1698134948051.png

 

Any help is greatly appreciate .. TIA 🙏

Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution

Hi Ben,

 

The types behind these members changed to GS::Optional<API_PenType> APIOptional<API_PenType> and GS::Optional<API_AttributeIndex> APIOptional<API_AttributeIndex> behind the scenes. Also API_AttributeIndex changed a bit.

So to turn an override off I think you can just assign APINullValue.

To set a value for the cutFillPen you could use a cast and for refMat use ACAPI_CreateAttributeIndex:

 

// previous typo: elem.slab.cutFillBackgroundPen = APINULLGuid;
elem.slab.cutFillBackgroundPen = APINullValue;  // correct version to turn off
elem.slab.cutFillBackgroundPen = (API_PenIndex)19; // Set override pen to 19

elem.wall.refMat = APINullValue; // Turn off
elem.wall.refMat = ACAPI_CreateAttributeIndex (100);

 

 

Hope that helps!
Bernd

Edit (2023-10-26): Fixed incorrect values/types as discussed below.

View solution in original post

Solution

Actually, the correct code is quite different. You can't use APINULLGuid .. because cutFillBackgroundPen is a pen index - not a GUID..

There is a new boolean parameter ".hasValue" just set this to false.

My problem was I hadn't changed the MASK_SET to these new parameters and therefore it wasn't working.. 

ACAPI_ELEMENT_MASK_SET(mask, API_SlabType, cutFillBackgroundPen);
ACAPI_ELEMENT_MASK_SET(mask, API_SlabType, cutFillPen);

if (element.slab.cutFillBackgroundPen.hasValue) {
	element.slab.cutFillBackgroundPen.hasValue = false;
	element.slab.cutFillPen.hasValue = false;
}

 Thanks for your help anyway Bernd 👍

Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au

View solution in original post

4 REPLIES 4
Solution

Hi Ben,

 

The types behind these members changed to GS::Optional<API_PenType> APIOptional<API_PenType> and GS::Optional<API_AttributeIndex> APIOptional<API_AttributeIndex> behind the scenes. Also API_AttributeIndex changed a bit.

So to turn an override off I think you can just assign APINullValue.

To set a value for the cutFillPen you could use a cast and for refMat use ACAPI_CreateAttributeIndex:

 

// previous typo: elem.slab.cutFillBackgroundPen = APINULLGuid;
elem.slab.cutFillBackgroundPen = APINullValue;  // correct version to turn off
elem.slab.cutFillBackgroundPen = (API_PenIndex)19; // Set override pen to 19

elem.wall.refMat = APINullValue; // Turn off
elem.wall.refMat = ACAPI_CreateAttributeIndex (100);

 

 

Hope that helps!
Bernd

Edit (2023-10-26): Fixed incorrect values/types as discussed below.

Awesome Bernd.. you've done it again.

I don't know how I missed this..

but also setting the mask helps 😂

 

Thanks, once again mate.👍

Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
Solution

Actually, the correct code is quite different. You can't use APINULLGuid .. because cutFillBackgroundPen is a pen index - not a GUID..

There is a new boolean parameter ".hasValue" just set this to false.

My problem was I hadn't changed the MASK_SET to these new parameters and therefore it wasn't working.. 

ACAPI_ELEMENT_MASK_SET(mask, API_SlabType, cutFillBackgroundPen);
ACAPI_ELEMENT_MASK_SET(mask, API_SlabType, cutFillPen);

if (element.slab.cutFillBackgroundPen.hasValue) {
	element.slab.cutFillBackgroundPen.hasValue = false;
	element.slab.cutFillPen.hasValue = false;
}

 Thanks for your help anyway Bernd 👍

Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au

Yes APINULLGuid was a typo sorry! It's still possible to use APINullValue though. It should have the same effect as setting .hasValue = false.

Here's the corresponding code for APIOptional in AC27 headers:

void operator = (NullValueType nullOpt) {
    static_assert (nullOpt == APINullValue, "Unsafe assignment! Use APINullValue to indicate the loss of valid stored value.");
    hasValue = false;
}


Also I've just realized that I've written GS::Optional<API_PenType>. That's also wrong because it's APIOptional<API_PenType>. Sorry for mixing it all up 😅  I'll edit my answer above.

And good catch with the mask!