Continue to Site

Welcome to MCAD Central

Join our MCAD Central community forums, the largest resource for MCAD (Mechanical Computer-Aided Design) professionals, including files, forums, jobs, articles, calendar, and more.

Script to select object from a workspace

canopys

New member
Hello,
I'm trying to write a script to select some objects from whatever workspace.

the following line works for WS1 only :
IL.select( "WSPI", "WS1/" + objectName);

so i tried IL.select( "WSPI", objectName); but it didn't work.

I guess the name of the WS must be in the select function arguments, so my question is how could I catch the name of the active ws ?
 
You could select the first object in the workspace and extract the workspace name from that.
e.g.


import javax.swing.*;


JOptionPane ui = new JOptionPane();


IL.deselectAll( "WSPI" );
IL.select( "WSPI" , 0);
IL.getSelectedObjects ( "WSPI" );
Object workobjects[] = IL.getSelectedObjects ( "WSPI" );
if (workobjects.length != 0) {
String fullname = workobjects[0].toString();
int workindex = fullname.indexOf('/');
String workspacename = fullname.substring(0, workindex);


ui.showMessageDialog(null, workspacename );


}else {
ui.showMessageDialog(null, "No Objects in workspace" );
}
IL.deselectAll( "WSPI" );


Then use


IL.select( "WSPI",workspacename + "/"+ objectName);
 
Thanks for your reply. The idea is good but unfortunatly it doesn't work.
When I launch the script I have the following error message : Error running script: null

It seems that the script doesn't select any object from the ws. The getSelectedObjects give a null value.
 
This is the complete scriptwhich works onIntralink 3.3


import com.ptc.intralink.client.script.*;
import com.ptc.intralink.script.*;


import javax.swing.*;
public class workname extends ILIntralinkScript {
ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();


private void run0 () throws Exception {


JOptionPane ui = new JOptionPane();


IL.deselectAll( "WSPI" );
IL.select( "WSPI" , 0);
IL.getSelectedObjects ( "WSPI" );
Object workobjects[] = IL.getSelectedObjects ( "WSPI" );
if (workobjects.length != 0) {
String fullname = workobjects[0].toString();
int workindex = fullname.indexOf('/');
String workname = fullname.substring(0, workindex);


ui.showMessageDialog(null, workname );


}else {
ui.showMessageDialog(null, "No Objects in workspace" );
}



} // End of run0


public void run () throws Exception {
run0 (); // recorded
} // End of function


} // End Macro Recording
 
Hello doronron,

your script work well. But when I modify it, it doesn't work anymore and I have still the same error message.

Here is my script based on your explantions :

// Version: Intralink v.3.4.M020 (2006080-I6.0.0.412)
// Start Macro Recording
import com.ptc.intralink.client.script.*;
import com.ptc.intralink.script.*;

import java.io.*;
import javax.swing.*;

public class CADExport_r3 extends ILIntralinkScript {
ILIntralinkScriptInterface IL = (ILIntralinkScriptInterface)getScriptInterface();

private void run0 () throws Exception {

JOptionPane ui = new JOptionPane();

IL.deselectAll( "WSPI" );
IL.select( "WSPI" , 0);
IL.getSelectedObjects ( "WSPI" );
Object workobjects[] = IL.getSelectedObjects ( "WSPI" );

if (workobjects.length != 0)
{
String fullname = workobjects[0].toString();
int workindex = fullname.indexOf('/');
String workspacename = fullname.substring(0, workindex);
ui.showMessageDialog(null, workspacename );

try
{
IL.deselectAll( "WSPI" );
String adressedufichier = "C:\\zt\\pro\\exportlist.txt";
String texte = "";
FileReader fr = new FileReader(adressedufichier);
BufferedReader br = new BufferedReader(fr);
texte = br.readLine();

while(texte != null && texte !="")
{
IL.select( "WSPI", workspacename + "/" + texte );
texte = br.readLine();
}

br.close();

}
catch(IOException ioe){System.out.println("erreur : " + ioe);}

IL.openWindow( "Export to Workspace", "", "" );
IL.updateDependents( "Aucun", null, 528 );
IL.exportToWS( "CAD_EXPORT", true, false );
IL.selectTree( "FTWS", "CAD_EXPORT" );
IL.selectAll( "WSPI" );
IL.openWindow( "CheckOut", "", "" );
IL.setCurrentViewer( "PIV" );
IL.updateDependents( "Aucun", "derni
 
I'have just notice something odd. When I don't check "use watch window" i the playback tab, it seems that works !?
smiley5.gif


I really don't unterstand why. Unfortunatly I have other errors and the script don't go to the end but components are selected and exported to the other ws.
 
Add the compiled file from folder "your_ilink_setup"\.proi\.data\user.data\lib to "your_ilink_setup"\.proi\.data\user.data\custom\WS


The script will be available for any workspace by selecting the custom tab from a workspace browser. This requires intralink to be restarted.
 
Hi everyone,

I'm coming back on this topic because now, I'd like to know if there is a way to get the name of an empty workspace to checkout models in it ?
 
You could have your script create a newdummy object, extract the workspace name and then delete the dummy object.
 
I was able to obtain the name of an empty workspace and use it successfully in a script


//============================================== =====
//Get Workspace name from Workspace window
java.awt.Window activewindow = ILEventManager.getActiveWindow();
String WSTitle = activewindow.findComponentAt(activewindow.getWidth()-10,10). getAccessibleContext().getAccessibleName();
// Get slash location
int dashloc1 = WSTitle.indexOf("-");
//============================================== ==
//Manipulating text - Window name is "Workspace - Workspace name"
//dashloc is the location of the "-", "+2" is the location of the
//first character of the actual workspace name
String WSGetName = WSTitle.substring(dashloc1+2 );
//============================================== ===


Then I was able to use WSGetName further down in my script as the target workspace:


IL.openWindow( "Locate", "", "" );
IL.setCurrentViewer( "Locate" );
IL.select( "B - Part Number - Latest Revs", "System" );
IL.clearFilter( );
IL.addFilter( "Name", "=", new Object[]{modelToCopy } );
IL.addFilter( "Revision", "Latest", new Object[]{"" } );
IL.addFilter( "Version", "Latest", new Object[]{new java.lang.Integer(0) } );
IL.applyFilter( );
IL.select("PIV", 0);
IL.openWindow( "CheckOut", "", "" );
IL.setCurrentViewer( "PIV" );
IL.startEditor( false );
IL.setCheckoutMethod( true );
IL.setTargetWorkspace( WSGetName );
IL.checkout( );
IL.closeWindow( );
IL.setActiveWindow( "Workspace", WSGetName, "WSObjects" );


Hope this helps you out
 

Sponsor

Back
Top