Choose your top Archicad wishes!

Read more
Archicad C++ API
About Archicad add-on development using the C++ API.

Drawing positon changes after creating the drawing element

Leonardo Lopes
Contributor

Hi, i am having a really hard time figuring out how to place a drawing in a layout by specifing it's position and clip polygon, and making the drawing visible inside the crop region. A snippet of my code is as follows:

 

	// Init 
	GSErrCode err = NoError;

	// Default drawing settings
	API_Element drawingElem;
	BNZeroMemory(&drawingElem, sizeof(API_Element));
	drawingElem.header.typeID = API_DrawingID;

	err = ACAPI_Element_GetDefaults(&drawingElem, nullptr);

	// Set drawing params
	drawingElem.drawing.drawingGuid = tablePtr->scheduleNavItem.guid;
	drawingElem.header.typeID = API_DrawingID;
	drawingElem.drawing.ratio = 1.0;
	drawingElem.drawing.manualUpdate = true;
	drawingElem.drawing.anchorPoint = APIAnc_LB;
	drawingElem.drawing.pos.x = refPoint->x;
	drawingElem.drawing.pos.y = ((layoutHeight - SheetMargins.TopMargin - OffsetFromMargin) / 1000) - tablePtr->tableHeight;
	drawingElem.drawing.isCutWithFrame = true;

	// Set clip polygon
	API_ElementMemo memo;
	BNZeroMemory(&memo, sizeof(API_ElementMemo));

	drawingElem.drawing.poly.nCoords = 5;
	drawingElem.drawing.poly.nSubPolys = 1;
	drawingElem.drawing.poly.nArcs = 0;
	memo.coords = (API_Coord**)BMAllocateHandle((drawingElem.drawing.poly.nCoords + 1) * sizeof(API_Coord), ALLOCATE_CLEAR, 0);
	memo.pends = (Int32**)BMAllocateHandle((drawingElem.drawing.poly.nSubPolys + 1) * sizeof(Int32), ALLOCATE_CLEAR, 0);
	if (memo.coords != nullptr && memo.pends != nullptr) {
		(*memo.coords)[1].x = drawingElem.drawing.pos.x;
		(*memo.coords)[1].y = drawingElem.drawing.pos.y;
		(*memo.coords)[2].x = drawingElem.drawing.pos.x;
		(*memo.coords)[2].y = drawingElem.drawing.pos.y + tablePtr->tableHeight;
		(*memo.coords)[3].x = drawingElem.drawing.pos.x + tablePtr->columnWidths[colIndex];
		(*memo.coords)[3].y = drawingElem.drawing.pos.y + tablePtr->tableHeight;
		(*memo.coords)[4].x = drawingElem.drawing.pos.x + tablePtr->columnWidths[colIndex];
		(*memo.coords)[4].y = drawingElem.drawing.pos.y;
		(*memo.coords)[5].x = drawingElem.drawing.pos.x;
		(*memo.coords)[5].y = drawingElem.drawing.pos.y;
		(*memo.pends)[0] = 0;
		(*memo.pends)[1] = drawingElem.drawing.poly.nCoords;
	}

	// Create the drawing
	ACAPI_CallUndoableCommand("Create drawing", [&]() -> GSErrCode
		{
			err = ACAPI_Element_Create(&drawingElem, &memo);
			return err;
		});

	ACAPI_DisposeElemMemoHdls(&memo);

 

The problem is: when the drawing is created the clip polygon is in the exact position that i want, but the drawing's position is different then the drawingElem.drawing.pos that was set in the begining of the code. The "image1" shows the position of the clip polygon and "image2" shows the position of the drawing.

 

The only way i've found to achieve what i am looking for is setting the modelOffset of the drawing. By doing this, it's possible to change the position of the drawing and achieving the final result in "image3". However, the problem of doing this, is that when a user updates the drawing manually in Archicad the drawing resets to it's original position, so the drawing will look like the situation in "image2".

 

Does anyone know how to fix this?


Image1.pngImage2.pngImage3.png
0 REPLIES 0