By Dwaraka Nadha Reddy, Manchuri, GE-India Innovation Center
PTC has incorporated UI Scripting into Pro/INTRALINK starting with release 3.2. Although the purpose of UI scripting was originally to help debug Pro/INTRALINK, it is also powerful enough to automate many tasks that are repetitive and time-consuming. To put it simply: UI Scripting is to Pro/INTRALINK as Mapkeys are to Pro/ENGINEER.
The UI Scripting utility enables you to record a set of Pro/INTRALINK actions (including menu picks and key-board input), write these recorded actions to a Java file, and compile them to a .class file. Once recorded and compiled, UI Scripts can be played back to perform the set of recorded actions automatically.
Because the scripts are written in Java, they can be edited by adding code snippets built of any normal Java function and then recompiled to enhance the application of the script. For example, when a script is recorded to capture the Checkout of an object, the name of the object and the Workspace is hard-coded. The script can be edited and recompiled so that it prompts you to enter the name of the object(s) and the Workspace.
Note: For those who are new to UI Scripting, Matt Meadows has provided a must-read article on how to record and run a Pro/INTRALINK Script. It is available at www.profilesmagazine.com/p29/tips_meadows.html.
Script as Recorded
Let’s take an object called abcd.prt. Say we want to check out the latest revision and version into a blank workspace called demo. When this task is recorded with the UI Scripting utility, the Java program looks like this:
public class AutoCheckOut extends ILIntralinkScript {
ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();
private void run0 () throws Exception {
IL.openWindow( "Locate", "", "" ); // recorded step: 1
IL.setCurrentViewer( "Locate" ); // recorded step: 2
IL.clearFilter( ); // recorded step: 3
IL.addFilter( "Name", "=", new Object[]{"abcd.prt" } ); // recorded step: 4
IL.addFilter( "Revision", "Latest", new Object[]{"" } ); // recorded step: 5
IL.addFilter( "Version", "Latest", new Object[]{new java.lang.Integer(0) } ); // recorded step: 6
IL.applyFilter( ); // recorded step: 7
IL.deselectAll( "PIV" ); // recorded step: 8
IL.select( "PIV", 0); // recorded step: 9
IL.openWindow( "CheckOut", "", "" ); // recorded step: 10
IL.setCurrentViewer( "PIV" ); // recorded step: 11
IL.startEditor( false ); // recorded step: 12
IL.setCheckoutMethod( true ); // recorded step: 13
IL.setTargetWorkspace( "demo" ); // recorded step: 14
IL.checkout( ); // recorded step: 15
IL.closeWindow( ); // recorded step: 16
IL.closeWindow( ); // recorded step: 17
} // End of run0
public void run () throws Exception {
run0 (); // recorded
} // End of function
} // End Macro Recording
When run, this script always locates abcd.prt and checks out to the workspace demo, because abcd.prt and demo are hard-coded into program (step 4 and step 14, respectively). The above script would be more useful if you could enter the name of the object and the workspace. We’ll now see how to edit it to do just this.
Editing the Script to Make It Interactive
Our objectives for editing the script are to:
Prompt the user to enter the name of the object to be checked out.
Prompt the user to enter the name of workspace into which the objects(s) is to be checked out.
Handle possible errors—for example, if the object is not found in the COMMON SPACE or the WORKSPACE already exists.
Although there are many ways in Java to make the program interactive, javax.swing.JOptionPane methods are perhaps the easiest for creating and displaying dialog boxes. The boxes prompt the user for a value (input) and store it in a variable or convey a message (output).
In this example, we use the following two methods of the JOptionPane.
showInputDialog.Creates a dialog box for inputting a value—in this case, the name of the workspace and name of the object.
showMessageDialog creates a dialog box for displaying a message—in this case, to tell the user about any errors.
The following line of code prompts the user to enter name of the workspace and store it in a variable:
String wspaceName=JOptionPane.showInputDialog(null,”Enter Name of the WS”,”Create Workspace”,JOptionPane.PLAIN_MESSAGE);
The following line of code displays the message “Workspace name not entered, Try again”:
JOptionPane.showMessageDialog(null,”Workspace name not entered,Try Again”,”Oops…”,JOptionPane.QUESTION_MESSAGE);
While it is fairly simple to add the code that prompts for input, error handling is trickier. After all the possible errors are handled properly, the script looks like the one shown below. (Click here to download the source code...)
public class AutoCheckOut extends ILIntralinkScript
{
ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();
String wspaceName,objName;
boolean wscompare=false;
boolean wsexists=false;
void createWorkspaceAndCheckout () throws Exception
{
try{
String wstr="";
LDBInfo linfo=new LDBInfo();
String[] wslist=linfo.getWSNames();
for (int i = 0; i < wslist.length; i++) {
wstr=wstr+wslist[i]+"\n";
}
wspaceName = JOptionPane.showInputDialog(null,"Enter Name of the Work Space","Create Workspace",JOptionPane.PLAIN_MESSAGE);
if(wspaceName==null || wspaceName.length()==0)
{
JOptionPane.showMessageDialog(null, "Workspace name not entered, Try Again","Oops...",JOptionPane.ERROR_MESSAGE);
}
else
{
for (int j= 0; j < wslist.length; j++) {
if(wscompare==true)
{
wsexists=true;
break;
}
}//End of For loop
if(wsexists == true) {
JOptionPane.showMessageDialog(null, "Know the Rules!!!"+"\n"+"Workspace with same name already Exists, Please give a different Name"+"\n"+"You have the following Workspaces in the current LDB"+"\n"+wstr,"Error",JOptionPane.ERROR_MESSAGE);
}
else if(wspaceName.length()!=0 && wsexists == false) {
IL.createWorkspace( wspaceName, "" );
getObjNameAndCheckout ();
}
}//End of else block
}//End of try block
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Know the rules!!!"+"\n"+ e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
return;
}
wsexists = false;
wscompare=false;
}// End of createWorkspaceAndCheckout Method
void getObjNameAndCheckout () throws Exception
{
objName = JOptionPane.showInputDialog( "Enter Object to Checkout");
if(objName==null || objName.length()==0)
{
JOptionPane.showMessageDialog(null, "Object name not entered, Try Again","Oops...",JOptionPane.ERROR_MESSAGE);
}
else
{
IL.openWindow( "Locate", "", "" );
IL.setCurrentViewer( "Locate" );
IL.clearFilter( );
IL.addFilter( "Name", "=", new Object[]{objName} );
IL.addFilter( "Revision", "Latest", new Object[]{"" } );
IL.addFilter( "Version", "Latest", new Object[]{new java.lang.Integer(0) } );
IL.applyFilter( );
IL.deselectAll( "PIV" );
IL.selectAll( "PIV");
Object objToCheckout[]=IL.getSelectedObjects("PIV");
if(objToCheckout.length==0)
{
JOptionPane.showMessageDialog(null, "Object(s) not found, Try Again","Oops...",JOptionPane.ERROR_MESSAGE);
IL.closeWindow( );
}
else
{
IL.openWindow( "CheckOut", "", "" );
IL.setCurrentViewer( "PIV" );
IL.setActiveWindow( "Locate", null, "Locate" );
IL.setActiveWindow( "Checkout", null, "PIV" );
IL.startEditor( false );
IL.setCheckoutMethod( true );
IL.setTargetWorkspace( wspaceName );
IL.checkout( );
IL.closeWindow( );
IL.closeWindow( );
JOptionPane.showMessageDialog(null, "Checkout Completed","Done",JOptionPane.PLAIN_MESSAGE);
}
}
}
public void run () throws Exception
{
createWorkspaceAndCheckout();
} // End of run Method
}//End of Program
Speed Up Your Checkout
When checking out very large assembly/assemblies, you spend a lot of idle time waiting for the checkout dialog box to pop up so that you can click “OK”. This a good opportunity to use a UI Script, enabling you to run the script just before leaving for the day so that assembly is ready for work on the next morning. To use the above script:
1. Copy the AutoCheckOut.java into “...\.proi\.data\user.data\source”.
2. Login to Pro/INTRALINK.
3. Press CTRL+S and compile the script. class file would be saved to “...\.proi\.data\user.data\lib”.
4. If you copy the class file from “...\.proi\.data\user.data\lib” to…
“...\.proi\data\user.data\custom\WS”
“...\.proi\data\user.data\custom\CS”, a custom dropdown menu is added to all the Workspace and Commonspace browsers.
5. To check out multiple objects, enter the names of the objects separated by a colon.
This is just a glimpse of what Pro/INTRALINK Scripting can do for you. The power of UI Scripting is directly proportional to the knowledge/support of Java at your disposal.
Dwaraka Nadha Reddy, Manchuri is a Technical Lead at GE-India Innovation Center in Hyderabad, India.