另一个小组的同事问了我有没有对选中的复数元素进行筛选,将不同type的元素与其他元素自动连线的功能。
我找了官网手册发现这个操作以外地还挺简单的。以下是代码,希望能有所帮助。
!INC Local Scripts.EAConstants-VBScript
'
' Script Name: SelectedElementControlInDiagram
' Author: Sora Fu
' Purpose: To deal with SYS team daily work
' Date: 2018/11/27
'
Sub Main
dim dob as EA.DiagramObject
dim d1 as EA.Diagram
dim p1 as EA.Package
dim dc1 as EA.Collection
dim sobject
dim connector as EA.Connector
set p1=Repository.GetTreeSelectedPackage
For Each d1 in p1.Diagrams
Set dc1 = d1.SelectedObjects 'SelectedObjects attribute of Diagram, very useful
For each dob in dc1
'session.output(Repository.GetElementByID(dob.ElementID).type)
if Repository.GetElementByID(dob.ElementID).type <> "Component" then 'To recognise un-Component type element
set sobject = dob
end if
next
next
for each dob in dc1
if Repository.GetElementByID(dob.ElementID).type = "Component" then
set connector = Repository.GetElementByID(sobject.ElementID).connectors.AddNew("","Realization")
'Add realization connector between two elements. The client end is component type
connector.SupplierID = dob.ElementID 'The supplier end is un-component type
'connector.Stereotype = ""
connector.Update() 'Every change need to update Objects
d1.Update()
end if
next
End sub
main