您好我正在从Sparx"企业架构师生成一个Kinetic JavaScript代码" VB脚本中的工具。我面临的问题是 1)我能够在这里从模型中生成代码我没有问题。但是我想从模型左侧到右下角按顺序生成输出。 现在我的输出是如何生成的,当我添加一个新组件时,首先生成组件输出,然后是其他组件。
这是我的模型,我生成输出为: 1)Birt 2)igpk ..... 但我想按顺序排序 1)GS-IS 2)Promics 3)FMEA 4)iGPK ...
option explicit
!INC Local Scripts.EAConstants-VBScript
'
sub main
if (Repository.GetTreeSelectedItemType() = otDiagram) then
' Show the script output window
Repository.EnsureOutputVisible "Script"
dim theDiagram as EA.Diagram
set theDiagram = Repository.GetTreeSelectedObject()
dim doOffsetLeft, doOffsetRight, doOffsetTop, doOffsetBottom 'As Integer
dim scaleX, scaleY 'As Integer
dim inputpicSizeX, inputpicSizeY, newpicSizeX1, newpicSizeY2 'As Integer
dim decreasex, newdecreasex, decreasey, newdecreasey ' as Integer
dim connectLink 'As String
scalex = theDiagram.cx
scaley = theDiagram.cy
connectLink=""
'doOffsetLeft = 35
'doOffsetTop = 9
Session.Output("scaleX: " + CStr(scaleX) + "scaleY: " + CStr(scaleY)) 'this have the whole pick size'
connectLink=InputBox("Connect URL for tool list?", "Input required", connectLink)
' next have to take input box and have to calculate % '
newpicSizeX1 = CInt(InputBox("Exported image width (in pixels)?", "Input required", inputpicSizeX))
newpicSizeY2 = CInt(InputBox("Exported image height (in pixels)?", "Input required", inputpicSizeY))
Session.Output("NewscaleX: " + CStr(newpicSizeX1) + "NewscaleY: " + CStr(newpicSizeY2)) 'new scale stored here given by user'
'calculation of % x'
decreasex = scalex - newpicSizex1
newdecreasex = ( decreasex / scalex ) * 100
'calculation of % y'
decreasey = scaley - newpicSizeY2
newdecreasey = ( decreasey/ scaley ) * 100
Session.Output("%decreasex: " + CStr(newdecreasex) + " %decreasey: " + CStr(newdecreasey) )'new % output'
dim diagramObjects as EA.Collection
Set diagramObjects = theDiagram.DiagramObjects
dim diagramObject As EA.DiagramObject
dim x1
dim y1
dim x2
dim y2
dim width
dim height
dim seqCnt
dim found
dim findIdx
seqCnt = 0
found = true
while (found)
seqCnt = seqCnt + 1
findIdx = 0
found = false
while ((Not found) and (findIdx < diagramObjects.Count))
Set diagramObject = diagramObjects.GetAt(findIdx)
if (diagramObject.Sequence = seqCnt) Then
dim doLeft, doRight, doTop, doBottom 'As Integer
dim element AS EA.Element
set element = Repository.GetElementByID(diagramObject.ElementID)
x1 = CInt(diagramObject.left * (( 100 - newdecreasex )/100) ) - 28
y1 = CInt(-1 * diagramObject.top * (( 100 - newdecreasey )/100)) - 42
x2 = 1 * CInt(diagramObject.right * (( 100 - newdecreasex )/100) ) - 28
y2 = CInt(-1 * diagramObject.bottom * (( 100 - newdecreasey )/100)) -45
width = x2 - x1
height = -1 * (y1 - y2)
if (element.Type = "ActivityPartition") Then
dim ElementName
ElementName = Replace(element.Name, " ", "")
'for drawing rectangle outer boundry
Session.Output("var " & ElementName & " = new Kinetic.Rect({")
'Session.Output("X:" & X1 & "," "Y:" & y1 & "," "Width:" & width & "," "Height:" & height & "," "Stroke Width:2})")
Session.Output("x : " & X1 & ",")
Session.Output("y : " & y1 & ",")
Session.Output("width : " & width & ",")
Session.Output("height : " & height & ",")
Session.Output("strokeWidth : 2 " & "," )
Session.Output("stroke : 'Black'" & "," & "});")
'layer.add(EngineeringData);
Session.Output("layer.add(" & ElementName & ");")
'for drawing outer boundry line
dim ElementLine
dim linewidth
dim ywidth
'ElementLine = join(ElementName,"line")
ElementLine = ( Elementname & "line" )
'Session.Output (ElementLine)
ywidth = (y1+20) 'line should come down so adding 20
linewidth= (width+X1) ' till where the line has to end so width + x1 value
'for drawing line
Session.Output("var " & ElementLine & " = new Kinetic.Line({")
'Session.Output("X:" & X1 & "," "Y:" & y1 & "," "Width:" & width & "," "Height:" & height & "," "Stroke Width:2})")
Session.Output("points : " & "[" & X1 & "," & ywidth & "," & linewidth & "," & ywidth & "]," )
Session.Output("stroke : 'black' " & "," )
Session.Output("strokeWidth : 2 " & "," )
Session.Output("tension : 0 " & "," )
Session.Output("linecap : 'round'" & "," & "});")
Session.Output("layer.add(" & ElementLine & ");")
'for drawing message text
dim Elementtext
Elementtext = (Elementname & "text")
dim ActivityName
ActivityName = element.Name
'Session.Output( Elementtext)
Session.Output("var " & Elementtext & " = new Kinetic.Text({")
'Session.Output("X:" & X1 & "," "Y:" & y1 & "," "Width:" & width & "," "Height:" & height & "," "Stroke Width:2})")
Session.Output("x : " & X1 & ",")
Session.Output("y : " & y1 & ",")
Session.Output("width : " & width & ",")
Session.Output("height : " & height & ",")
Session.Output("text : " & "'" & ActivityName & "'" & "," )
Session.Output("fontSize : 17 " & "," )
Session.Output("fontFamily : 'Calibri' " & "," )
Session.Output("fill : 'black' " & "," )
Session.Output("align : 'center'" & "," & "});")
'layer.add(EngineeringData);
Session.Output("layer.add(" & Elementtext & ");")
end if
' diagramObjects.DeleteAt findIdx,true
found = true
end if
findIdx = findIdx + 1
wend
wend
else
' Error message
Session.Prompt "This script does not support items of this type.", promptOK
end if
end sub
function TVGetElementTaggedValue( theElement, taggedValueName, defaultValueMissing, defaultValueEmpty )
if not theElement is nothing and Len(taggedValueName) > 0 then
dim taggedValue as EA.TaggedValue
set taggedValue = theElement.TaggedValues.GetByName( taggedValueName )
if taggedValue is nothing then
TVGetElementTaggedValue = defaultValueMissing
' Dump warning
'Session.Output(theElement.Name & " " & taggedValueName & " TAG Missing")
else
if taggedValue.Value = "" then
TVGetElementTaggedValue = defaultValueEmpty
' Dump warning
'Session.Output(theElement.Name & " " & taggedValueName & " Value Missing")
else
TVGetElementTaggedValue = taggedValue.Value
end if
end if
end if
end function
main
答案 0 :(得分:1)
您的代码显示您循环遍历图表中的元素。它们不按地理位置排序,但按顺序排列。您可以检查DiagramObject中的坐标以查找位置顺序。如果您有从左到右的顺序,只需检查DiagramObject.Left(左侧y坐标)并对对象进行升序排序。
答案 1 :(得分:0)
EA在生成代码时会忽略图表。 (否则,如果您在另一个图表中以不同的顺序放置相同的元素会发生什么?)
您可以通过重新排序项目浏览器中的元素来影响生成顺序,但我也对此表示怀疑。
如果您想强制执行特定的生成订单,我认为您最终必须编写自己的代码生成脚本。
答案 2 :(得分:0)
在您的vbscript中,您可以查询此特定图表上的diagramObjects的位置。
然后,您可以使用其位置来确定生成代码的顺序。
答案 3 :(得分:0)
也许您可以在模型中添加“SORT_CODE”标记值,然后使用脚本中的值对对象进行排序。