SHOW:
|
|
- or go back to the newest paste.
| 1 | !INC Local Scripts.EAConstants-JScript | |
| 2 | ||
| 3 | /* | |
| 4 | * This code has been included from the default Diagram Script template. | |
| 5 | * If you wish to modify this template, it is located in the Config\Script Templates | |
| 6 | * directory of your EA install path. | |
| 7 | * | |
| 8 | * Script Name: Convert All Lines In Current Diagram to Any Line Style | |
| 9 | * Author: Nick Roth (rothnic) | |
| 10 | * Purpose: EA does not provide a way to quickly change line styles, so this enables a quick conversion of all on a diagram | |
| 11 | * Date: 08/29/13 | |
| 12 | */ | |
| 13 | ||
| 14 | /* | |
| 15 | * Diagram Script main function | |
| 16 | */ | |
| 17 | ||
| 18 | // UNCOMMENT ONE OF THE LINETYPE LINES BELOW -------------- | |
| 19 | //var LINETYPE = "Direct"; | |
| 20 | //var LINETYPE = "Auto"; | |
| 21 | //var LINETYPE = "Custom"; | |
| 22 | var LINETYPE = "V"; // Tree Style Vertical | |
| 23 | //var LINETYPE = "H"; // Tree Style Horizontal | |
| 24 | //var LINETYPE = "LV"; // Lateral Vertical | |
| 25 | //var LINETYPE = "LH"; // Lateral Horizontal | |
| 26 | //var LINETYPE = "OS"; // Orthogonal - Square | |
| 27 | //var LINETYPE = "OR"; // Orthogonal - Rounded | |
| 28 | // UNCOMMENT ONE OF THE LINETYPE LINES ABOVE -------------- | |
| 29 | ||
| 30 | var MODETYPE = 0; | |
| 31 | var Mode = "" | |
| 32 | ||
| 33 | function OnDiagramScript() | |
| 34 | {
| |
| 35 | ||
| 36 | // Show the script output window | |
| 37 | //Repository.EnsureOutputVisible( "Script" ); | |
| 38 | Session.Output( "Convert All Lines In Current Diagram to Any Line Style" ); | |
| 39 | Session.Output( "=======================================" ); | |
| 40 | ||
| 41 | // Get a reference to the current diagram | |
| 42 | var currentDiagram as EA.Diagram; | |
| 43 | currentDiagram = Repository.GetCurrentDiagram(); | |
| 44 | Repository.SaveDiagram(currentDiagram.DiagramID); | |
| 45 | ||
| 46 | if ( currentDiagram != null ) | |
| 47 | {
| |
| 48 | ||
| 49 | // Get a reference to any selected connector/objects | |
| 50 | var selectedConnector as EA.Connector; | |
| 51 | var selectedObjects as EA.Collection; | |
| 52 | selectedConnector = currentDiagram.SelectedConnector(); | |
| 53 | selectedObjects = currentDiagram.SelectedObjects(); | |
| 54 | ||
| 55 | SetMode(MODETYPE); | |
| 56 | ||
| 57 | if ( selectedConnector != null ) | |
| 58 | {
| |
| 59 | // A connector is selected | |
| 60 | // Expand in future | |
| 61 | } | |
| 62 | else if ( selectedObjects.Count > 0 ) | |
| 63 | {
| |
| 64 | // One or more diagram objects are selected | |
| 65 | // Expand in future | |
| 66 | } | |
| 67 | else | |
| 68 | {
| |
| 69 | // Loop through all Links in Current Diagram | |
| 70 | var len = currentDiagram.DiagramLinks.Count; | |
| 71 | var thisLink as EA.DiagramLink; | |
| 72 | var style = ""; | |
| 73 | for (i=0; i < len; i++){
| |
| 74 | ||
| 75 | thisLink = currentDiagram.DiagramLinks.GetAt(i); | |
| 76 | ||
| 77 | //Save a copy of the Style string value | |
| 78 | style = thisLink.Style; | |
| 79 | Session.Output("Initial style = " + style);
| |
| 80 | var styleLen = style.length; | |
| 81 | ||
| 82 | // If the Style pre-existed | |
| 83 | if (styleLen > 0){
| |
| 84 | ||
| 85 | // Split up the current style to preserve existing modifications | |
| 86 | var styleArray = style.split(";");
| |
| 87 | ||
| 88 | var foundTree = 0; | |
| 89 | var foundMode = 0; | |
| 90 | style = ""; | |
| 91 | var thisStyle = ""; | |
| 92 | ||
| 93 | // Loop through the style elements | |
| 94 | for(j=0; j<styleArray.length; j++){
| |
| 95 | thisStyle = "" + styleArray[j]; | |
| 96 | ||
| 97 | // If we found the TREE style, we update it | |
| 98 | if (thisStyle.indexOf("TREE") != -1){
| |
| 99 | styleArray[j] = "TREE=" + LINETYPE; | |
| 100 | foundTree = 1; | |
| 101 | ||
| 102 | // If the LineType is Direct, Auto, or Custom, Remove the Tree Style | |
| 103 | if ((MODETYPE == 1) || (MODETYPE == 2) || (LINETYPE == "Custom")){
| |
| 104 | styleArray[j] == ""; | |
| 105 | } | |
| 106 | } | |
| 107 | ||
| 108 | // If we find the Mode field of the Style, update Mode | |
| 109 | if (thisStyle.indexOf("Mode") != -1){
| |
| 110 | styleArray[j] = Mode; | |
| 111 | foundMode = 1; | |
| 112 | } | |
| 113 | ||
| 114 | // If we removed the Tree type, don't save this style into array | |
| 115 | if (styleArray[j] != ""){
| |
| 116 | style = style + styleArray[j] + ";"; | |
| 117 | } | |
| 118 | ||
| 119 | // If we are at the end and haven't seen Tree or Mode | |
| 120 | - | Session.Output(j == styleArray.length-1); |
| 120 | + | |
| 121 | if (LINETYPE.length < 3){
| |
| 122 | style = style + "TREE=" + LINETYPE + ";"; | |
| 123 | } | |
| 124 | if (foundMode == 0){
| |
| 125 | style = style + Mode + ";"; | |
| 126 | } | |
| 127 | } | |
| 128 | } | |
| 129 | } | |
| 130 | // No style existing, so adding our desired line styling | |
| 131 | else{
| |
| 132 | // Add Tree style if required | |
| 133 | if (LINETYPE.length < 3){
| |
| 134 | style = "TREE=" + LINETYPE + ";"; | |
| 135 | } | |
| 136 | // Need to add the Mode, either way | |
| 137 | style = style + Mode + ";"; | |
| 138 | } | |
| 139 | ||
| 140 | // Save the local style string into the Link's Style attribute | |
| 141 | thisLink.Style = style; | |
| 142 | Session.Output("Updated style " + thisLink.Style);
| |
| 143 | thisLink.Update(); | |
| 144 | } | |
| 145 | // Reload diagram so changes are displayed | |
| 146 | Repository.ReloadDiagram(currentDiagram.DiagramID); | |
| 147 | } | |
| 148 | } | |
| 149 | else | |
| 150 | {
| |
| 151 | // Would like to expand this in the future to allow selection of type with a single script | |
| 152 | Session.Prompt( "This script requires a diagram to be visible.", promptOK) | |
| 153 | } | |
| 154 | } | |
| 155 | ||
| 156 | // Sets up the mode type for the linetype | |
| 157 | function SetMode(mode){
| |
| 158 | if ( LINETYPE == "Direct" ){
| |
| 159 | mode = 1; | |
| 160 | Mode = "Mode=1"; | |
| 161 | } | |
| 162 | else if ( LINETYPE == "Auto" ){
| |
| 163 | mode = 2 | |
| 164 | Mode = "Mode=2"; | |
| 165 | } | |
| 166 | else {
| |
| 167 | Mode = "Mode=3"; | |
| 168 | } | |
| 169 | } | |
| 170 | ||
| 171 | OnDiagramScript(); |