cancel
Showing results for 
Search instead for 
Did you mean: 
EN
cancel
Showing results for 
Search instead for 
Did you mean: 
dushyant
Enthusiast

How to select elements of a particular ElementID or Classification

Hi,

 

ACAPI_Element_GetElemList() allows selection of all elements of a particular type.

 

How do we select elements of a particular ElementID or Classification?

 

Thanks.

2 Replies 2

Hi dushyant,

Element ID Property
You mean the Element ID property right? Unfortunately in that case, I don't think there's a single command to do that. My approach would be to make a candidate list of element GUIDs and then filter the matching ones yourself by accessing the property value similar to this:

 

API_Property prop;
ACAPI_Element_GetPropertyValue (elemGuid, elemIdGuid, prop);

auto value = prop.value.singleVariant.variant.uniStringValue;

 

where "elemGuid" is the GUID of the current element to test and "elemIdGuid" is the GUID of the "Element ID" property itself. I think that property GUID never changes and even is the same for different AC installs, but I'm not 100% sure. That's why I wrote myself the following function which you are free to copy:

 

GSErrCode GetElemIdPropertyGuid (API_Guid& elemIdGuid)
{
	GSErrCode err = NoError;

	// This is our initial guess.
	elemIdGuid = GSGuid2APIGuid (GS::Guid ("B1B54D45-C951-42C9-9AF8-898F0BF212AB"));

	API_PropertyDefinition elemIdPropDef;
	elemIdPropDef.guid = elemIdGuid;
	err = ACAPI_Property_GetPropertyDefinition (elemIdPropDef);
	if (err != NoError) { return err; }

    // We check if it gives us the correct property.
	if (elemIdPropDef.name == "Element ID") { return NoError; }
	// Otherwise we have to search for it
	GS::Array<API_PropertyGroup> groups;
	err = ACAPI_Property_GetPropertyGroups (groups);
	if (err != NoError) { return err; }

	for (GS::USize i = 0; i < groups.GetSize(); ++i) {
		if (groups[i].name == "ID and Categories") {
			GS::Array<API_PropertyDefinition> definitions;
			err = ACAPI_Property_GetPropertyDefinitions (groups[i].guid, definitions);
			if (err != NoError) { return err; }

			for (GS::USize j = 0; j < definitions.GetSize (); ++j) {
				if (definitions[j].name == "Element ID") {
					elemIdGuid = definitions[j].guid;
					return NoError;
				}
			}
		}
	}

	return APIERR_GENERAL;
}

 


Classification

I didn't manipulate classifications yet with the AC API so I can only give rough guesses from what I gathered from the documentation. It seems like the function ACAPI_Element_GetElementsWithClassification might do exactly what you want. Again there's the problem of figuring out what the GUID of the classification item is. My first idea was to use ACAPI_Classification_GetClassificationSystem then ACAPI_Classification_GetClassificationSystemRootItems and recursively iterate on the child items ACAPI_Classification_GetClassificationItemChildren until you get the desired classification item. In case you find an easier way let us know 🙂

Automating Archicad with Add-Ons, GDL-Objects & Python Archi-XT.com
dushyant
Enthusiast

Hi Bernd,

Yes, I had been following the method of getting a set of elements and filter them based on the criteria. I was only curious if I there was any single command available to select elements using a classification-item ID or element ID, like ACAPI_Element_GetElemList() which takes an element-typeID (API_ElemTypeID) as the filter.

So looks like there isn't any.

 

Thanks for sharing that info!!

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!