cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Refresh documents using java api

ngibanel
Super Contributor

Hello,

 

I want initialize and refresh documents using Java API.

 

I have a MegaCollection with my documents.

MegaCollection listDocs = mgRoot.getSelection("Select [Document]", "Nom");

for (MegaObject oSelection : listDocs) {

// reinitialize and refresh document

}

 Which method use to refresh document.

 

 In VB this code works

oSelection.InitializeDocument oSelection.RefreshDocument

 but I don't know call this method in java.

 

Thanks for the response.

 

--

N. Gibanel

17 Replies

Unfortunately, the RTF documents are pretty slow in general.

Thus, this script is the best you can do to refresh automatically several documents.

 

 

 



Patrick Bobo

ngibanel
Super Contributor

Document refresh takes considerable time (it's longer than manually).

 

Maybe  an optimization of this script ? I don't know.

I'm glad to know that it works Smiley Wink

 

After a quick look in VB's documentation, the function doEvents is used to force the application to yield its processor use for one cycle, so it might slow down a bit your loop.

So what do you mean by "improving the performance" ? Do you want to improve your loop's speed?



Patrick Bobo

ngibanel
Super Contributor

Ok it's work. 

 

Is there a way to improve performance? (for example doEvent in VB)

 

Thanks for your help.

 

 

--

N. Gibanel 

My bad, the error probably comes from the fact that the method signature includes an "arg" attribute that I didn't set in the sample code I gave you. 

 

This would probably be better :

 

MegaCollection listDocs = mgRoot.getSelection("Select[Document]","Nom");

for(MegaObject oSelection : listDocs)
{
     oSelection.callMethod("InitializeDocument",null);
     oSelection.callMethod("RefreshDocument",null);
}

 



Patrick Bobo

ngibanel
Super Contributor

Thanks but it doesn't work...

 

I have this error :

Exception in thread "main" com.mega.modeling.api.MegaException: MEGA Error 1
at com.mega.modeling.api.jni.MappModuleJNI.InvokeMethod(Native Method)
at com.mega.modeling.api.jni.ComObjectProxy.invokeMethod(Unknown Source)

 

 

 

 

pabobo
Retired

Hi, 

 

Usually, when you know the method in VB, and its equivalent doesn't exist in the Java API, you can use the method callMethod(Object name, Object ... arg) if there's no return or the function callFunction(Object name, Object ... arg) if there's a return. 

 

For you problem, it would probably be something like : 

 

MegaCollection listDocs = mgRoot.getSelection("Select[Document]","Nom");

for(MegaObject oSelection : listDocs)
{
     oSelection.callMethod("InitializeDocument");
     oSelection.callMethod("RefreshDocument");
}

 

This would probably work. 

I hope it helps, 

 

Regards



Patrick Bobo