Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !INC Local Scripts.EAConstants-JScript
- /*
- * This code has been included from the default Diagram Script template.
- * If you wish to modify this template, it is located in the Config\Script Templates
- * directory of your EA install path.
- *
- * Script Name: Convert All Lines In Current Diagram to Any Line Style
- * Author: Nick Roth (rothnic)
- * Purpose: EA does not provide a way to quickly change line styles, so this enables a quick conversion of all on a diagram
- * Date: 08/29/13
- */
- /*
- * Diagram Script main function
- */
- // UNCOMMENT ONE OF THE LINETYPE LINES BELOW --------------
- //var LINETYPE = "Direct";
- //var LINETYPE = "Auto";
- //var LINETYPE = "Custom";
- var LINETYPE = "V"; // Tree Style Vertical
- //var LINETYPE = "H"; // Tree Style Horizontal
- //var LINETYPE = "LV"; // Lateral Vertical
- //var LINETYPE = "LH"; // Lateral Horizontal
- //var LINETYPE = "OS"; // Orthogonal - Square
- //var LINETYPE = "OR"; // Orthogonal - Rounded
- // UNCOMMENT ONE OF THE LINETYPE LINES ABOVE --------------
- var MODETYPE = 0;
- var Mode = ""
- function OnDiagramScript()
- {
- // Show the script output window
- //Repository.EnsureOutputVisible( "Script" );
- Session.Output( "Convert All Lines In Current Diagram to Any Line Style" );
- Session.Output( "=======================================" );
- // Get a reference to the current diagram
- var currentDiagram as EA.Diagram;
- currentDiagram = Repository.GetCurrentDiagram();
- Repository.SaveDiagram(currentDiagram.DiagramID);
- if ( currentDiagram != null )
- {
- // Get a reference to any selected connector/objects
- var selectedConnector as EA.Connector;
- var selectedObjects as EA.Collection;
- selectedConnector = currentDiagram.SelectedConnector();
- selectedObjects = currentDiagram.SelectedObjects();
- SetMode(MODETYPE);
- if ( selectedConnector != null )
- {
- // A connector is selected
- // Expand in future
- }
- else if ( selectedObjects.Count > 0 )
- {
- // One or more diagram objects are selected
- // Expand in future
- }
- else
- {
- // Loop through all Links in Current Diagram
- var len = currentDiagram.DiagramLinks.Count;
- var thisLink as EA.DiagramLink;
- var style = "";
- for (i=0; i < len; i++){
- thisLink = currentDiagram.DiagramLinks.GetAt(i);
- //Save a copy of the Style string value
- style = thisLink.Style;
- Session.Output("Initial style = " + style);
- var styleLen = style.length;
- // If the Style pre-existed
- if (styleLen > 0){
- // Split up the current style to preserve existing modifications
- var styleArray = style.split(";");
- var foundTree = 0;
- var foundMode = 0;
- style = "";
- var thisStyle = "";
- // Loop through the style elements
- for(j=0; j<styleArray.length; j++){
- thisStyle = "" + styleArray[j];
- // If we found the TREE style, we update it
- if (thisStyle.indexOf("TREE") != -1){
- styleArray[j] = "TREE=" + LINETYPE;
- foundTree = 1;
- // If the LineType is Direct, Auto, or Custom, Remove the Tree Style
- if ((MODETYPE == 1) || (MODETYPE == 2) || (LINETYPE == "Custom")){
- styleArray[j] == "";
- }
- }
- // If we find the Mode field of the Style, update Mode
- if (thisStyle.indexOf("Mode") != -1){
- styleArray[j] = Mode;
- foundMode = 1;
- }
- // If we removed the Tree type, don't save this style into array
- if (styleArray[j] != ""){
- style = style + styleArray[j] + ";";
- }
- // If we are at the end and haven't seen Tree or Mode
- if ((j == styleArray.length-1) && (foundTree == 0)){
- if (LINETYPE.length < 3){
- style = style + "TREE=" + LINETYPE + ";";
- }
- if (foundMode == 0){
- style = style + Mode + ";";
- }
- }
- }
- }
- // No style existing, so adding our desired line styling
- else{
- // Add Tree style if required
- if (LINETYPE.length < 3){
- style = "TREE=" + LINETYPE + ";";
- }
- // Need to add the Mode, either way
- style = style + Mode + ";";
- }
- // Save the local style string into the Link's Style attribute
- thisLink.Style = style;
- Session.Output("Updated style " + thisLink.Style);
- thisLink.Update();
- }
- // Reload diagram so changes are displayed
- Repository.ReloadDiagram(currentDiagram.DiagramID);
- }
- }
- else
- {
- // Would like to expand this in the future to allow selection of type with a single script
- Session.Prompt( "This script requires a diagram to be visible.", promptOK)
- }
- }
- // Sets up the mode type for the linetype
- function SetMode(mode){
- if ( LINETYPE == "Direct" ){
- mode = 1;
- Mode = "Mode=1";
- }
- else if ( LINETYPE == "Auto" ){
- mode = 2
- Mode = "Mode=2";
- }
- else {
- Mode = "Mode=3";
- }
- }
- OnDiagramScript();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement