[EA VBscript] 日常工作 2. 对屏幕内选中元素的操作

另一个小组的同事问了我有没有对选中的复数元素进行筛选,将不同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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值