如何根据 GUID 更改 sparx 中的对象颜色
How to change object color in sparx based on GUID
我无法理解它:-)
如何使用程序更改 Sparx 中对象 (BPMN Activity) 的颜色(背景颜色)?
我有 GUID,我可以 select 对象,只是不知道如何更改颜色?
假设我有一个 GUID 为 {E595409F-CFED-4334-8DA3-F13D8A81A534} 的对象,我希望背景颜色为红色。
代码是什么(在 Perl 中,Python 或 Visual Basic,任何代码都可以)。不在 Sparx 脚本中。
这是代码(python)
import win32com.client
eaApp = win32com.client.Dispatch("EA.App")
#print the connection string
eaRep = eaApp.Repository
print('Connection string: ', eaRep.ConnectionString)
#select the activity based on GUID
guid = '{E595409F-CFED-4334-8DA3-F13D8A81A534}'
activity = eaRep.GetElementByGUID(guid)
print('Activity: ', activity.Name)
#Change the backgroud color to red
activity.Style = '''BCol=255;'''
activity.Update
但最后两行是错误的,因为那是我曾经不知道如何做的
元素上的样式是该元素在图表上使用时的默认外观。
在每个图表上都可以覆盖。这些设置存储在 EA.DiagramObject
.
假设您正在尝试更改您应该使用的默认外观 EA.Element.SetAppearance(long Scope, long Item, long Value)
。
help file 说了以下内容:
Void
Notes: Sets the visual appearance of the element.
Parameters:
•Scope: Long - Scope of appearance set to modify
1 - Base
(Default appearance across entire model)
To set appearance for the
element (diagram object) in a selected diagram only, see Setting The
Style in the DiagramObject Class topic
•Item: Long - Appearance
feature to modify
0 - Background color
1 - Font Color
2 - Border
Color
3 - Border Width
•Value: Long - Value to set appearance to
好的,成功了。这是现在可以使用的代码。
import win32com.client
#Declare what
DiagramGUID = '{9262BA28-AE78-45ce-A060-FEC95DE4301E}'
ObjectGUI = '{6B80AB10-0104-4d42-B5BF-2EDC4EA053CC}'
ObjectColor = '''255'''
#connect to EA
eaApp = win32com.client.Dispatch("EA.App")
#get the repository
Repository = eaApp.Repository
print('Connection string: ', Repository.ConnectionString, '\n')
#get diagram using GUID
dia = Repository.GetDiagramByGUID(DiagramGUID)
print('Diagram name selected: ', dia.Name)
#Get the activity ID based on GUID
activity = Repository.GetElementByGUID(ObjectGUI)
ElementID = activity.ElementID
#get the fist object in the diagram
dia_obj = dia.DiagramObjects.GetAt(0)
#start from 0
i = 0
#now find the right diagram object based on ID
while (dia_obj.ElementID != ElementID):
i = i+1
print('i is ', i)
print('comparing ', dia_obj.ElementID, ' with ', ElementID)
dia_obj = dia.DiagramObjects.GetAt(i)
#change the style and update diagram object
dia_obj.SetStyleEx('''BCol''',ObjectColor)
dia_obj.Update()
会出现错误(如果找不到正确的对象,我需要注意这个错误。如果有更好的方法来完成我需要做的事情,请告诉我。
我无法理解它:-) 如何使用程序更改 Sparx 中对象 (BPMN Activity) 的颜色(背景颜色)?
我有 GUID,我可以 select 对象,只是不知道如何更改颜色?
假设我有一个 GUID 为 {E595409F-CFED-4334-8DA3-F13D8A81A534} 的对象,我希望背景颜色为红色。
代码是什么(在 Perl 中,Python 或 Visual Basic,任何代码都可以)。不在 Sparx 脚本中。
这是代码(python)
import win32com.client
eaApp = win32com.client.Dispatch("EA.App")
#print the connection string
eaRep = eaApp.Repository
print('Connection string: ', eaRep.ConnectionString)
#select the activity based on GUID
guid = '{E595409F-CFED-4334-8DA3-F13D8A81A534}'
activity = eaRep.GetElementByGUID(guid)
print('Activity: ', activity.Name)
#Change the backgroud color to red
activity.Style = '''BCol=255;'''
activity.Update
但最后两行是错误的,因为那是我曾经不知道如何做的
元素上的样式是该元素在图表上使用时的默认外观。
在每个图表上都可以覆盖。这些设置存储在 EA.DiagramObject
.
假设您正在尝试更改您应该使用的默认外观 EA.Element.SetAppearance(long Scope, long Item, long Value)
。
help file 说了以下内容:
Void
Notes: Sets the visual appearance of the element.
Parameters:
•Scope: Long - Scope of appearance set to modify
1 - Base (Default appearance across entire model)
To set appearance for the element (diagram object) in a selected diagram only, see Setting The Style in the DiagramObject Class topic
•Item: Long - Appearance feature to modify
0 - Background color
1 - Font Color
2 - Border Color
3 - Border Width
•Value: Long - Value to set appearance to
好的,成功了。这是现在可以使用的代码。
import win32com.client
#Declare what
DiagramGUID = '{9262BA28-AE78-45ce-A060-FEC95DE4301E}'
ObjectGUI = '{6B80AB10-0104-4d42-B5BF-2EDC4EA053CC}'
ObjectColor = '''255'''
#connect to EA
eaApp = win32com.client.Dispatch("EA.App")
#get the repository
Repository = eaApp.Repository
print('Connection string: ', Repository.ConnectionString, '\n')
#get diagram using GUID
dia = Repository.GetDiagramByGUID(DiagramGUID)
print('Diagram name selected: ', dia.Name)
#Get the activity ID based on GUID
activity = Repository.GetElementByGUID(ObjectGUI)
ElementID = activity.ElementID
#get the fist object in the diagram
dia_obj = dia.DiagramObjects.GetAt(0)
#start from 0
i = 0
#now find the right diagram object based on ID
while (dia_obj.ElementID != ElementID):
i = i+1
print('i is ', i)
print('comparing ', dia_obj.ElementID, ' with ', ElementID)
dia_obj = dia.DiagramObjects.GetAt(i)
#change the style and update diagram object
dia_obj.SetStyleEx('''BCol''',ObjectColor)
dia_obj.Update()
会出现错误(如果找不到正确的对象,我需要注意这个错误。如果有更好的方法来完成我需要做的事情,请告诉我。