您好,我正在生成一个动态的JavaScript代码,从Sparx的“企业架构师”工具从VB脚本。我面临的问题是: 1)我能够从模型中生成代码,这里我没有problem.But,我想从模型的左侧到右下角的顺序生成输出。现在我的输出是如何生成的,当我添加一个新组件时,首先生成该组件的输出,然后再生成其他组件。

这是我的模型,我生成的输出是: 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发布于 2015-01-26 23:00:35
您的代码显示您循环遍历关系图中的元素。它们不是按地理位置排序的,而是按相加的顺序排序的。您可以检查DiagramObject中的坐标以查找位置顺序。如果你有一个从左到右的顺序,只需检查DiagramObject.Left (左y坐标)并按升序对对象进行排序。
发布于 2015-01-26 17:32:05
EA在生成代码时会忽略图。(否则,如果您在另一个图中以不同的顺序放置相同的元素,会发生什么?)
您也许能够通过重新排序项目浏览器中的元素来影响生成顺序,但我也对此表示怀疑。
如果您想强制执行特定的生成顺序,我认为您最终将不得不编写自己的代码生成脚本。
发布于 2015-01-26 18:18:57
在你的vbscript中,你可以在这个特定的图表上查询diagramObjects来获得它们的位置。
然后,您可以使用它们的位置来确定生成代码的顺序。
https://stackoverflow.com/questions/28147234
复制相似问题