计算Layout上所有图形元素个数 Public void CountLayoutElements() {IMxDocument pMxDoc =ThisDocument IGraphicsContainer pGContainer =pMxDoc.PageLayout; pGContainer.Reset();//确保指针指向最初的位置 IElement pElement = pGContainer.Next(); Int intGraphicCount = 0; Do {If TypeOf(pElement) is IGraphicElement { intGraphicCount = itGraphicCount +1} pElement = pGContainer.Next(); }While(pElement=null) MsgBox.show(“There are " & intGraphicCount & " graphics on the page“)} Example: Count all the graphic elements on the layout Public Sub CountLayoutElements () Dim pMxDoc As IMxDocument Dim pGContainer As IGraphicsContainer Dim pElement As IElement Dim intGraphicCount As Integer Set pMxDoc = ThisDocument Set pGContainer = pMxDoc.PageLayout pGContainer.Reset '*Make sure the pointer is on the first item Set pElement = pGContainer.Next '*pull out the first element Do Until pElement Is Nothing '*Loop thru all elements If TypeOf pElement Is IGraphicElement Then intGraphicCount = intGraphicCount + 1 '*increment the count End If Set pElement = pGContainer.Next '*pull out the next element Loop MsgBox "There are " & intGraphicCount & " graphics on the page" Exit Sub
2022-10-20 10:31:55 4.83MB AE编程基础.
1