Hi @jthi and @David_Burnham ,
Thank you both for your feedback and ideas. I like the mini modal window, it came in handy when testing to see if ANY Graph Builder was open.
I decided to change things up and totally rewrote the code. It now does what I want, but it also keeps track through associative arrays which graph builder instance is for which project. With data tables, even with multiple open, it doesn't have a problem distinguishing between the different instances of Graph builder, even within a single data table, but since projects have multiple tabs, I had to make sure the assignment of the grab builder scriptable object was associated with the correct project. I was pretty happy to be able to use AAs and have them help me out, too! The new code also changes the first window depending on if you only have data tables (or projects) open or both.
This was a nice little endeavor and I enjoyed working on it. After testing it some more, I will share with my organization. Below is the code if you're interested. I couldn't figure out how to get the For Each() to work when going through all possible projects and then through all windows within a project, so I did For() loops instead.
Thanks!,
DS
//JSL to add diagonal line and automatically resize to desired size
//Written by SDF1 with help/input from jthi, txnelson, Craige_Hales, David_Burnham, and Mark_Bailey
Names Default To Here( 1 );
Clear Symbols();
lb_width = 80;
Lines_n = 6;
mmw = Function( {title, text, text_icon = "BlankIndex", window_icon = "NewApplication"},
{Default Local},
New Window( title,
<<modal,
<<show toolbars( 0 ),
<<Show Menu( 0 ),
<<Set Window Icon( window_icon ),
H List Box( Icon Box( text_icon ), Spacer Box( size( 10, 1 ) ), V Center Box( Text Box( text ) ) )
)
);
getDTGraphBuilderWindows = Function( {},
{default local},
lst = {};
winList = Get Window List( Type( "Reports" ) );
For Each( {win}, winList,
winTitle = win << get Window Title;
If( Contains( winTitle, "Graph Builder" ),
Insert Into( lst, win )
);
);
Return( lst );
);
getPRJGraphBuilderWindows = Function( {},
{default local},
prjlst = {};
prjGBlist = {};
prj_list = Get Project List();
prjTitle = prj_list << Get Window Title;
For( i = 1, i <= N Items( prj_list ), i++,
prjTitle[i] = prj_list[i] << Get Window Title;
prjwinList = Get Window List( Project( prjTitle[i] ) );
prjGBwinTitle = prjwinList << Get Window Title;
For( l = 1, l <= N Items( prjGBwinTitle ), l++,
If( Contains( prjGBwinTitle[l], "Graph Builder" ),
Insert Into( prjGBlist, prjGBwinTitle[l] );
Insert Into( prjlst, prjTitle[i] );
)
);
prjGBAA = Associative Array( prjGBlist, prjlst );
);
Return( prjGBAA );
);
RprtUpdate_Expr = Expr(
If(
N Items( dtGBedit ) == 1, gb = Get Window( dtGBedit[1] )[Outline Box( 1 )] << Get Scriptable Object,
N Items( PrjGBedit ) == 1,
ActiveProj = PrjGBAA << Get Value( PrjGBedit[1] );
gb = Get Window( Project( ActiveProj ), PrjGBedit[1] )[Outline Box( 1 )] << Get Scriptable Object;
);
Report( gb )[framebox( 1 )] << FrameSize( widthN, heightN );
theMax = Max( Report( gb )[axisbox( 1 )] << get max, Report( gb )[axisbox( 2 )] << get max );
theMin = Min( Report( gb )[axisbox( 1 )] << get min, Report( gb )[axisbox( 2 )] << get min );
Report( gb )[framebox( 1 )] << Xaxis( Min( theMin ), Max( theMax ) );
Report( gb )[framebox( 1 )] << Yaxis( Min( theMin ), Max( theMax ) );
Report( gb )[framebox( 1 )] << AddGraphicsScript(
xmin = X Origin();
xmax = X Origin() + X Range();
ymin = Y Origin();
ymax = Y Origin() + Y Range();
Pen Color( "blue" );
Pen Size( 1 );
Line Style( "solid" );
Line( {xmin, ymin}, {xmax, ymax} );
);
);
SquarifyWin_Expr = Expr(
nwin = New Window( "Enter Size of Desired Graph",
<<Return Result,
<<On Validate,
V List Box(
Outline Box( "Please enter pixel size of graph", <<Set Font Size( 12 ) ),
Lineup Box( N Col( 2 ), Spacing( 3, 3 ),
Text Box( "Width" ),
width_var = Number Edit Box( 250 ),
Text Box( "Height" ),
height_var = Number Edit Box( 250 ),
sq_input = Check Box( "Squarify Graph?", <<Set( 1 ) )
),
H List Box(
Button Box( "OK",
If( (sq_input << Get) == 1,
widthN = nwin[Number Edit Box( 1 )] << Get;
heightN = widthN;
nwin << Close Window;
RprtUpdate_Expr;
);
If( (sq_input) << Get == 0,
widthN = nwin[Number Edit Box( 1 )] << Get;
heightN = nwin[Number Edit Box( 2 )] << Get;
nwin << Close Window;
RprtUpdate_Expr;
);
),
Button Box( "Cancel", nwin << Close Window )
)
)
);
);
Graphic_Expr = Expr(
listDTGBWindows = getDTGraphBuilderWindows();
dt_GB_list = listDTGBWindows << Get Window Title;
PrjGBAA = getPRJGraphBuilderWindows();
If( Is Missing( PrjGBAA ) != 1,
ProjGBList = PrjGBAA << Get Keys; //GB graphs
Projs = PrjGBAA << Get Values; //Project name
);
If(
N Items( dt_GB_list ) == 0 & Is Empty( ProjGBList ) == 1,
mmw( "ERROR", "No Graph Builder Open, Please Create a Graph.", "Error", "ErrorSmall" ),
N Items( dt_GB_list ) != 0 & Is Empty( ProjGBList ) == 1,
GraphicWin = New Window( "Location of graphic",
<<Return Result,
<<On Validate,
Outline Box( "Please Select the Graph Builder Graphic to Modify", <<Set Font Size( 12 ) ),
Lineup Box( N Col( 3 ), Spacing( 4, 4 ),
Panel Box( "Data Table Graphs",
dtGB = List Box( dt_GB_list, width( <<Set Auto Stretching( 1, 0 ) ), nlines( Lines_n ), Max Selected( 1 ) )
),
Panel Box( "Actions",
V List Box(
Button Box( "OK",
dtGBedit = dtGB << Get Selected;
GraphicWin << Close Window;
SquarifyWin_Expr;
),
Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
Button Box( "Cancel", GraphicWin << Close Window )
)
)
)
),
N Items( dt_GB_list ) != 0 & Is Empty( ProjGBList ) != 1,
GraphicWin = New Window( "Location of graphic",
<<Return Result,
<<On Validate,
Outline Box( "Please Select the Graph Builder Graphic to Modify", <<Set Font Size( 12 ) ),
Lineup Box( N Col( 3 ), Spacing( 4, 4 ),
Panel Box( "Data Table Graphs",
dtGB = List Box(
dt_GB_list,
width( <<Set Auto Stretching( 1, 0 ) ),
nlines( Lines_n ),
Max Selected( 1 ),
<<Set Script( PrjGB << Clear Selection )
)
),
Panel Box( "Project Graphs",
PrjGB = List Box(
ProjGBList,
width( <<Set Auto Stretching( 1, 0 ) ),
nlines( Lines_n ),
Max Selected( 1 ),
<<Set Script( dtGB << Clear Selection )
)
),
Panel Box( "Actions",
V List Box(
Button Box( "OK",
If(
N Items( dtGB << Get Selected ) == 1,
dtGBedit = dtGB << Get Selected;
GraphicWin << Close Window;
SquarifyWin_Expr;,
N Items( PrjGB << Get Selected ) == 1,
PrjGBedit = PrjGB << Get Selected;
GraphicWin << Close Window;
SquarifyWin_Expr;
)
),
Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
Button Box( "Cancel", GraphicWin << Close Window )
)
)
)
),
N Items( dt_GB_list ) == 0 & Is Empty( ProjGBList ) != 1,
GraphicWin = New Window( "Location of graphic",
<<Return Result,
<<On Validate,
Outline Box( "Please Select the Graph Builder Graphic to Modify", <<Set Font Size( 12 ) ),
Lineup Box( N Col( 3 ), Spacing( 4, 4 ),
Panel Box( "Project Graphs",
PrjGB = List Box( ProjGBList, width( <<Set Auto Stretching( 1, 0 ) ), nlines( Lines_n ), Max Selected( 1 ), )
),
Panel Box( "Actions",
V List Box(
Button Box( "OK",
PrjGBedit = PrjGB << Get Selected;
GraphicWin << Close Window;
SquarifyWin_Expr;
),
Spacer Box( <<Set Auto Stretching( 0, 1 ) ),
Button Box( "Cancel", GraphicWin << Close Window )
)
)
)
)
);
);
Graphic_Expr;