2017-02-15 127 views
0

我無法從「包(擴展)」形狀中獲取方法SpartialNeighbors的信息。Visio:如何獲取包含在一個形狀中的形狀?

通常,我用這個代碼:

Dim s As Shape, vsoShapeOnPage As Shape 
Dim vsoReturnedSelection As Visio.Selection 

's contains the current shape 
Set vsoReturnedSelection = s.SpatialNeighbors(visSpatialContain, 0, visSpatialIncludeContainerShapes) 
     If vsoReturnedSelection.Count = 0 Then 
      'No Shapes contained 
     Else 
      For Each vsoShapeOnPage In vsoReturnedSelection 
       'Code 
      Next 
     End If 

這工作完全正常的形狀,如在默認的UML模板(nameU =「概覽」)

我知道我能集團的形狀,但它增加了努力。

另一點,當我分析其他形狀時,我用「MemberOfContainers」看到該形狀包含在「包(擴展)」中。因此,必須能夠從其他方面獲取信息,而不必通過所有形狀。

在這裏,您可以看到「包」和「接口」 Extract of the diagram

回答

1

的形狀,如果形狀是一個容器,它的ContainerProperties屬性將被填充(即不爲空)。然後,可以通過interogate來檢索一組成員形狀ID。

是在SDK下載發現了一些示例代碼稍加改編版以下 - 基於看起來像這樣的文件:

Visio Container Shapes

你可以得到會員的形狀像這樣的保持:

Sub CheckMyPackageContainer() 
    'Assumes container is selected shape in active drawing window 
    Call ReportContainerShape(ActiveWindow.Selection.PrimaryItem) 
End Sub 


Sub ReportContainerShape(ByRef contShp As Visio.Shape) 
    If Not contShp Is Nothing Then 
     Dim containerProps As ContainerProperties 
     Set containerProps = contShp.ContainerProperties 
     If Not containerProps Is Nothing Then 
      Dim lngContainerMembers() As Long 
      lngContainerMembers = containerProps.GetMemberShapes(Visio.VisContainerFlags.visContainerFlagsDefault) 

      Dim hostingPage As Visio.Page 
      Set hostingPage = contShp.ContainingPage 
      For Each varMember In lngContainerMembers 
       Dim shpItem As Visio.Shape 
       Set shpItem = hostingPage.Shapes.ItemFromID(varMember) 
       Debug.Print shpItem.NameU, "Text = " & shpItem.Text 
      Next 
     End If 
    End If 
End Sub 

這將導致以下的輸出(注意, 'InterfaceThree' 不包含):

Interface  Text = InterfaceOne 
Interface.30 Text = InterfaceTwo