Archicad二次开发——元素

1、获取指定元素

Archicad通过guid获取指定元素

获取guid的方法:在样例代码的browser control里可以获得选中构件的guid

获取指定元素的样例:

				API_Element  element;
				GSErrCode    err;

				BNZeroMemory(&element, sizeof(API_Element));
				element.header.guid = GSGuid2APIGuid(GS::Guid("BACF8F36-631C-469C-A298-4DACB418D444"));
				err = ACAPI_Element_Get(&element);
				if (err==NoError)
				{
					MessageBox(ACAPI_GetMainWindow(), APIGuidToString(element.header.guid).ToCStr(), "title", 0);
				}

2、获取指定类型的元素

				//1、获取指定类型的所有元素
				GS::Array elemList;
				ACAPI_Element_GetElemList(API_WallID, &elemList);
				DBPrintf("number of wall on the active floor: %ld", elemList.GetSize());

3、获取关联的元素,如山墙、多边形节点

				API_Element     element;
				API_ElementMemo memo;
				GSErrCode       err;

				BNZeroMemory(&element, sizeof(API_Element));
				BNZeroMemory(&memo, sizeof(API_ElementMemo));

				element.header.typeID = API_ObjectID;
				element.header.variationID = APIVarId_SymbStair;
				err = ACAPI_Element_GetDefaults(&element, &memo);
				if (err == NoError) {
					/* do what you want */
				}

				ACAPI_DisposeElemMemoHdls(&memo);

4、遍历全部类型的数据

GS::Array elemList;
				GSErrCode err = ACAPI_Element_GetElemList(API_WallID, &elemList);
				if (err==NoError)
				{
					for (Int32 i = 0; i < elemList.GetSize(); ++i) {
						API_Element element;
						BNZeroMemory(&element, sizeof(API_Element));
						element.header.guid = elemList[i];
						if (ACAPI_Element_Get(&element) == NoError) {
							DBPrintf("墙的variationID: %d\n", element.header.variationID);
						}
					}
				}

5、加上过滤器,然后遍历元素

GS::Array elemList;
				ACAPI_Element_GetElemList(API_WallID, &elemList, APIFilt_OnActFloor);
				for (GS::Array::ConstIterator it = elemList.Enumerate(); it != nullptr; ++it) {
					API_Element element;
					BNZeroMemory(&element, sizeof(API_Element));
					element.header.guid = *it;
					if (ACAPI_Element_Get(&element) == NoError) {
						/* do what you want */
						MessageBox(ACAPI_GetMainWindow(), APIGuidToString(element.header.guid).ToCStr(), "title", 0);
					}
				}

 

你可能感兴趣的:(Archicad二次开发)