I find myself woefully lacking in understanding of when, why, and how (which type) to do screen draw/refresh/partial refresh. For instance, in a standalone Python script outside the application boundary, I have a function that is trying to draw graphic elements in the data view. Specifically, the elements will be a TextElement on top of a RectangleElement. The function loads the two elements into a GroupElement, which is in turn added to the ActiveView's GraphicsContainer for drawing on the screen. (As far as I can tell the graphic elements are valid.) I am really not understanding what Draw/Refresh/ParitalRefresh methods to put where.
Can you give me or point to a good explanation or tutorial about screen drawing/refreshing?
Below is a bit of selected code from my function. I have a PartialRefresh in the last line, but I don't know if that is correct or not.
pGroupElement = NewObj(esriCarto.GroupElement, esriCarto.IGroupElement3)
pTextElement = NewObj(esriCarto.TextElement, esriCarto.ITextElement)
pRectElement = NewObj(esriCarto.RectangleElement, esriCarto.IElement)
.
.
(configure TextElement) [tedious code removed]
.
.
(configure RectElement)
.
.
ptxtElem = CType(pTextElement, esriCarto.IElement)
pGroupElement.AddElement(ptxtElem)
pGroupElement.AddElement(pRectElement)
pContainer = mxDoc.ActiveView.GraphicsContainer
pGrpElem = CType(pGroupElement, esriCarto.IElement)
pContainer.AddElement(pGrpElem, 0)
mxDoc.ActiveView.PartialRefresh(esriCarto.esriViewGraphics, None, None)
Added: So, is creating objects with the following code - as I do now - not creating them in process?
def NewObj(MyClass, MyInterface):
"""Creates a new comtypes POINTER object where\n\
MyClass is the class to be instantiated,\n\
MyInterface is the interface to be assigned"""
from comtypes.client import CreateObject
try:
ptr = CreateObject(MyClass, interface=MyInterface)
return ptr
except:
return None
If not, I gather I must use IObjectFactory. Assuming that my current objects are not in process, I must say I haven't seen any great performance hit, but I guess I'm just asking for trouble forcing lots of interprocess calls.