Determining an Element's Envelope Without Adding to GroupElement/Layout

260
0
01-06-2022 02:36 PM
TheBobScript
New Contributor III

I need to determine the width of a graphic (typically CIMTextGraphic) so that I can place subsequent graphics as they relate to the location of the preceding graphic.

I can do this by creating a (throw-away/temporary) GroupElement and then retrieving the envelope like so:

 

 

Coordinate2D pnt = new Coordinate2D(xCanvas, yCanvas);
GroupElement dummyGE;
GroupElement groupElement;
List<CIMGraphic> newElements = new List<CIMGraphic>();

await QueuedTask.Run(() => {
	dummyGE = LayoutElementFactory.Instance.CreateGroupElement(myLayout));
	
	//create foreign text
	CIMTextGraphic tg = new CIMTextGraphic { Symbol = myTextSymbol.MakeSymbolReference(), Text = "Hallo Venn!", Shape = pnt.ToMapPoint() };
	CIMGraphicElement graphic = new CIMGraphicElement() { Graphic = tg };
	LayoutElementFactory.Instance.CreateElement(dummyGE, graphic);
	Element tmpElem = dummyGE.Elements[dummyGE.Elements.Count - 1];
	Envelope tmpEnv = tmpElem.GetBounds();
	pnt = new Coordinate2D(xCanvas + (tmpEnv.Width + 1), yCanvas);
	tg.Shape = pnt.ToMapPoint();
	newElements.Add(tg);
	
	//create english text
	tg = new CIMTextGraphic { Symbol = myTextSymbol.MakeSymbolReference(), Text = "Hello Friend!", Shape = pnt.ToMapPoint() };
	graphic = new CIMGraphicElement() { Graphic = tg };
	LayoutElementFactory.Instance.CreateElement(dummyGE, graphic);
	tmpElem = dummyGE.Elements[dummyGE.Elements.Count - 1];
	tmpEnv = tmpElem.GetBounds();
	pnt = new Coordinate2D(xCanvas + (tmpEnv.Width + 1), yCanvas);
	tg.Shape = pnt.ToMapPoint();
	newElements.Add(tg);
	
	myLayout.DeleteElement(dummyGE);
	
	groupElement = LayoutElementFactory.Instance.CreateGroupElement(myLayout);
	LayoutElementFactory.Instance.CreateGraphicElements(groupElement, newElements, null);
});

 

 

Using this method is detrimental to performance.  If I am iteratively using the above code it can take nearly a minute to add ~100 elements.

If I don't need to determine the location based on preceding elements I can avoid the creation of the 'dummy' element;  I just add the new element to the CIMGraphic list and once I have all elements added, use a single call (LayoutElementFactory.Instance.CreateGraphicElements) to add to a GroupElement/Layout.  That works great, but it doesn't help me when trying to create elements as the relate to other new elements.

Anyone out there have a method to determine the extent of an element without adding it the layout?

 

0 Kudos
0 Replies