2017-02-15 129 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