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

How do i get edit a Property?

Dayiz
Booster

Dear Graphisoft-Community,

 

I'm currently trying to build my first C++ AddOn, but I'm struggeling a bit.

I'm trying to set a property for selected elements, but the part where I set doesn't seem to work.

 

My current code looks/works somewhat like this:

1) I get the selected Elements with ACAPI_Selection_Get

Spoiler

static void getSelectedElements(GS::Array<API_Neig>& selNeigs)
{
  GSErrCode err;
  API_SelectionInfo selectionInfo;

  err = ACAPI_Selection_Get(&selectionInfo, &selNeigs, true);
}

2) Looking for the Property I want to edit (2 Steps)

This method finds the wanted PropertyGroup by its name

Spoiler
static void findPropertyGroupByName(GS::UniString name, API_PropertyGroup& target)
{
  GS::Array<API_PropertyGroup> propertyGroups;
  GSErrCode err{ ACAPI_Property_GetPropertyGroups(propertyGroups) };
  std::list<GS::UniString> groups;
  if (err == NoError)
    for (API_PropertyGroup pg : propertyGroups)
      if (pg.name == name)
        target = pg;
}

This method above gets used in the following:

Spoiler
static void findPropertyDefinition(API_PropertyDefinition& propertyDefinition)
{
  GSErrCode err;
  GS::UniString groupName{ "Identifizierung" };
  GS::UniString propertyName{ "Bezeichnung" };
  GS::Array <API_PropertyDefinition> propDefs;
  API_PropertyGroup propertyGroup;
  findPropertyGroupByName(groupName, propertyGroup);
  err = ACAPI_Property_GetPropertyDefinitions(propertyGroup.guid, propDefs);
  for (API_PropertyDefinition pd : propDefs)
    if (pd.name == propertyName)
      propertyDefinition = pd;
}

propertyDefintion will then have the information for our user-defined property ["Identifizierung","Bezeichnung"]

 

With the selected Neigs and the propertyDefinition accuired i wanted to use 

Spoiler
ACAPI_Element_GetPropertyValue(neig.guid, propertyDefinition.guid, property);

 to get the property of the Element and edit it

Spoiler
property.isDefault = false;
property.value.variantStatus = API_VariantStatusUserUndefined;
property.definition.collectionType = API_PropertySingleCollectionType;
property.definition.valueType = API_PropertyStringValueType;
property.definition.canValueBeEditable = true;
property.value.singleVariant.variant.uniStringValue = GS::ValueToUniString(i);

//i is an int which gets iterated everytime a new neig is selected through for (API_Neig neig : selNeigs), so the first one gets 1, the second 2 and so forth

but after I call 

Spoiler
ACAPI_Element_SetProperty(neig.guid, property);

none of the selected Elements have a changed their value of Bezeichnung.

 

So how can i edit a property of an element? What am i missing?

And on a side note, this my very first AC/C++ AddOn, so if you get any recommendations for my code (readability, performance or general things) those are much appreciated 🙂

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Dayiz
Booster

For anyone with the same problem as me: 

I think I used the wrong method.

I started using ACAPI_ElementList_ModifyPropertyValue() which resulted in change

View solution in original post

3 REPLIES 3
Ben Cohen
Enthusiast

Hi Dayiz

 

You may just need to encapsulate in an 'Undo' session.. this has got me a few times. 😀

ACAPI_CallUndoableCommand ("your command name",[&] () -> GSErrCode
// code in here..

});

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

Hello Ben,

 

Thanks four your help, i tried it out and encapsulated the important bits of the addon:

cap.PNG

 

the method "numberBezeichnung()" then gets called in MenuCommandHandler.

But when i execute the AddOn, no values get changed. To check if my selection works i added the line

    DG::InformationAlert(GS::ValueToUniString(selNeigs.GetSize()), "", "Ok");

which returns me after executing the addon the amount of the selected elements, which works.

Any idea why that still happens?

 

 

 

 

 

Solution
Dayiz
Booster

For anyone with the same problem as me: 

I think I used the wrong method.

I started using ACAPI_ElementList_ModifyPropertyValue() which resulted in change