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

How to get parent dimension elem from its text on marquee (API_Neig)?

Erenford
Booster
I have the dimension text on marquee, and with ACAPI_Selection_Get I can get the API_Neig. I'm trying to obtain the text's parent dimension elem with just the neig, what should I use?
I've tried APIAny_GetSelectedElementID but it just returns the same guid of the API_Neig.
Directly using the guid for ACAPI_Element_Get returns APIERR_BADID.
Archicad 25 5010 INT FULL
Archicad 26 5002 INT FULL
Visual Studio Professional 2019
Win 10 Pro 64-bit
1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Akos Somorjai
Graphisoft
Graphisoft
Ralph wrote:
Erenford wrote:
Ralph wrote:
The text shown in the dimension shouldn't be a separate element, i.e. the dimension and the text are bound together. So the guid in the API_Neig references the dimension.
That's what I thought as well. That's the case for other elems but the text neig has a different guid than the dimension.
I've just done a few quick tests and confirmed what you've found. Although the note is actually part of the dimension element structure, it appears to present itself independently for selection. And from the API perspective, the guid doesn't refer to an actual element.

I tried a few API calls that lookup linked or connected elements, but nothing produced a result. It's an interesting problem because it could affect at least one of our add-ons (in edge cases). Hopefully there is a call which finds the dimension linked to the note, but someone from GS might need to respond at this point.
There!s no easy way to do that in AC22. In AC23 a new ACAPI_Goodies (APIAny_GetHierarchicalElementOwnerID, ...) will solve this issue.

Best, Akos

View solution in original post

8 REPLIES 8
Ralph Wessel
Mentor
Erenford wrote:
I have the dimension text on marquee, and with ACAPI_Selection_Get I can get the API_Neig. I'm trying to obtain the text's parent dimension elem with just the neig, what should I use?
I've tried APIAny_GetSelectedElementID but it just returns the same guid of the API_Neig.
Directly using the guid for ACAPI_Element_Get returns APIERR_BADID.
The text shown in the dimension shouldn't be a separate element, i.e. the dimension and the text are bound together. So the guid in the API_Neig references the dimension.
Ralph Wessel BArch
Anonymous
Not applicable
check API_DimensionType description.
I couldn't find direct value but you have a bunch of vectors to play if you need to calculate a value.

If you need to access dimension note itself I would try defNote value which is API_​NoteType and then content parameter.
Erenford
Booster
Ralph wrote:
The text shown in the dimension shouldn't be a separate element, i.e. the dimension and the text are bound together. So the guid in the API_Neig references the dimension.
That's what I thought as well. That's the case for other elems but the text neig has a different guid than the dimension.

Below, I attached my debug prints when I selected the text, and then the dimension. Plus the code I used to print it. As you can see, both have different guids. I can get the element using the guid on APINeig_DimOn, but not on the APINeig_Note. Maybe I'm missing another step? Or maybe this a bug?

Thanks for the reply.

void Test6()
{
	API_Neig** selNeigs;
	API_SelectionInfo selectionInfo;
	BNZeroMemory(&selectionInfo, sizeof(selectionInfo));
	GSErrCode err = ACAPI_Selection_Get(&selectionInfo, &selNeigs, false, true, API_InsidePartially);
	BMKillHandle((GSHandle*)&selectionInfo.marquee.coords);
	if (err != NoError)
		goto Test_Err;

	API_Element elem;
	const UInt32 nSel = BMGetHandleSize((GSHandle)selNeigs) / sizeof(API_Neig);
	WriteReport("nSel = %d", nSel);
	for (UInt32 ii = 0; ii <  nSel && err == NoError; ++ii)
	{
		auto& neig = (*selNeigs)[ii];
		Write2DebugNeig(neig); // Prints all variables of API_Neig

		BNZeroMemory(&elem, API_ElementSize);
		elem.header.guid = neig.guid;
		err = ACAPI_Element_Get(&elem);
		if (err != NoError)
		{
			WriteReport("[Error] %s - ACAPI_Element_Get()", ErrId2Name(err));
			continue;
		}
		Write2DebugElem_ElemHead(elem.header); // Prints all variables of API_Elem_Head
	}
	Test_Err:
	BMKillHandle((GSHandle*)&selNeigs);
}
Archicad 25 5010 INT FULL
Archicad 26 5002 INT FULL
Visual Studio Professional 2019
Win 10 Pro 64-bit
Anonymous
Not applicable
If I understood docs correctly notes and other parts of dimension are stored in memo:

DimensionID - (API_DimElem **) - dimElems Returns the coordinates, the neig information, the text, and the witness line information of the dimension form memo description

So I would try accessing memo of API_DimensionType and then API_DimElem.

I'm not sure if you are able to access API_Note directly with API_ElementGet. Since it's not API_Element it seems not to have header and GUID?! So as far as I understand taking dimension and then access associated elements would be some way. The other maybe exploding geometry and then a note is converted to txt... but I assume that this is less satisfying since it won't be dimension anymore
Erenford
Booster
kzaremba wrote:
If I understood docs correctly notes and other parts of dimension are stored in memo:

DimensionID - (API_DimElem **) - dimElems Returns the coordinates, the neig information, the text, and the witness line information of the dimension form memo description

So I would try accessing memo of API_DimensionType and then API_DimElem.

I'm not sure if you are able to access API_Note directly with API_ElementGet. Since it's not API_Element it seems not to have header and GUID?! So as far as I understand taking dimension and then access associated elements would be some way. The other maybe exploding geometry and then a note is converted to txt... but I assume that this is less satisfying since it won't be dimension anymore
This would work if I already have the Dimension elem at start.
My problem is that I only have the API_Neig of the text from the marquee and I want to get its parent dimension elem using only that.

Usually you can use the neig guid directly for ACAPI_Element_Get, but in this case it has different a guid, so I'm wondering if I need another function to convert it to the element guid, or something else.
Archicad 25 5010 INT FULL
Archicad 26 5002 INT FULL
Visual Studio Professional 2019
Win 10 Pro 64-bit
Anonymous
Not applicable
If I understand correctly Note structure is design to be related to Dimension. So It doesn't exist as a separate entity and it's GUID is not exposed to API. Also in Note type, there is no parent information available. I think someone from Graphisoft could help to access it.

Another question is do you really need it. If Note exists only when there is Dimension then instead of iterating through selected Notes iterate thru selected Dimensions. But it, of course, it depends on what you are trying to achieve.
Ralph Wessel
Mentor
Erenford wrote:
Ralph wrote:
The text shown in the dimension shouldn't be a separate element, i.e. the dimension and the text are bound together. So the guid in the API_Neig references the dimension.
That's what I thought as well. That's the case for other elems but the text neig has a different guid than the dimension.
I've just done a few quick tests and confirmed what you've found. Although the note is actually part of the dimension element structure, it appears to present itself independently for selection. And from the API perspective, the guid doesn't refer to an actual element.

I tried a few API calls that lookup linked or connected elements, but nothing produced a result. It's an interesting problem because it could affect at least one of our add-ons (in edge cases). Hopefully there is a call which finds the dimension linked to the note, but someone from GS might need to respond at this point.
Ralph Wessel BArch
Solution
Akos Somorjai
Graphisoft
Graphisoft
Ralph wrote:
Erenford wrote:
Ralph wrote:
The text shown in the dimension shouldn't be a separate element, i.e. the dimension and the text are bound together. So the guid in the API_Neig references the dimension.
That's what I thought as well. That's the case for other elems but the text neig has a different guid than the dimension.
I've just done a few quick tests and confirmed what you've found. Although the note is actually part of the dimension element structure, it appears to present itself independently for selection. And from the API perspective, the guid doesn't refer to an actual element.

I tried a few API calls that lookup linked or connected elements, but nothing produced a result. It's an interesting problem because it could affect at least one of our add-ons (in edge cases). Hopefully there is a call which finds the dimension linked to the note, but someone from GS might need to respond at this point.
There!s no easy way to do that in AC22. In AC23 a new ACAPI_Goodies (APIAny_GetHierarchicalElementOwnerID, ...) will solve this issue.

Best, Akos