Hi,
I'm using the JDraw API in my Pipeline Pilot protocol to allow drawing of structures in the front end. My protocol has a JDraw component (with an html 'id' attribute set to 'jd') and a button ("Clear Sketcher") with an onclick event handler on the button that calls a javascript function: clearMol('jd') to clear the JDraw sketcher using the clearMolecule() method (mentioned in the JDraw API). My javascript code is as follows:
function clearMol(jdID) {
try {
// The JDraw sketcher has ID set as 'jd' which is passed to this function as jdID and we use it to select it below.
var jdbox= document.getElementById(jDrawID);
if (jdbox != null) {
// Note: The error occurs at the following line of code. Apparently the JDraw sketcher does not recognize this method which is a part of the JDraw API.
jdbox.clearMolecule();
}
}
catch(err) {
window.alert("Error Message: "+ err.message);
}
}
The code above, when executed, shows this error message: "Object does not support property or method 'clearMolecule()'."
I'm unable to figure out why I'm getting this error when the method that I'm using: clearMolecule() is a valid method documented in the JDraw API docs. The approach used by me, i.e., retrieving the JDraw sketcher using its ID is one that I've seen in examples on this forum and also on the JDraw page on the Accelrys website: http://accelrys.com/products/informatics/cheminformatics/draw/jdraw-demo.html
If anyone has any suggestions on what might be causing this error and how should the JDraw sketcher be retrieved and cleared, please let me know.
Thanks.

I have also attempted to initialize JDraw in a javascript function before it's used in the front end using the following code:
var jdrawBox= document.getElementByID(jDrawID);
jdrawBox.init(); // initialize the JDraw applet.
jdrawBox.start(); // start the applet.
However, this also did not work and the same exception was thrown: "Object does not support property or method 'init()'."
I have also tried to access the JDraw sketcher using the ChemSketcher API (javascrupt code shown below) but even that didn't work and I got the following error: "TypeError: Unable to get property 'clearMolecule' of undefined or null reference".
The javascript code for that is below:
/* Clear the JDraw applet. */
function clearMol(jDrawID) {
try {
var sketcher = Pilot.Report.ChemSketcher.getChemSketcher(jDrawID);
if(sketcher) {
var jdbox= document.getElementById(jDrawID);
if(jdbox) {
jdbox.appletRef.clearMolecule();
window.alert("Success ! JDraw Sketcher cleared.");
}
else {
window.alert("INTERNAL ERROR: Unable to find & clear JDraw Sketcher with ID: "+ jDrawID);
}
}
else { window.alert("INTERNAL ERROR: Unable to find JDraw Sketcher with ID: "+ jDrawID); }
}
catch(err) { window.alert("ErrorName: "+ err.name +" ; Message: "+ err.message); }
}
It works now when I use the following javascript:
/* Clear the JDraw applet. */function clearMol(jDrawID) { var sketcher = Pilot.Report.ChemSketcher.getChemSketcher(jDrawID); if(sketcher) { var jdbox= document.getElementById(jDrawID); <strong style="">if</strong>(jdbox) { sketcher.appletRef.clearMolecule(); window.alert("Success ! JDraw Sketcher cleared."); } <strong style="">else</strong> { window.alert("INTERNAL ERROR: Unable to find & clear JDraw Sketcher with ID: "+ jDrawID); } } <strong style="">else</strong> { window.alert("INTERNAL ERROR: Unable to find JDraw Sketcher with ID: "+ jDrawID); }}Thanks to Dr. Martin Hornig from Accelrys for the solution.
The point is that in Pipeline Pilot, JDraw is packaged as a component, i.e. there is a wrapper around it, most likely Javascript. That wrapper doesn’t give you direct access to the JDraw API like in the HTML examples that you have mentioned.
The important bit is the “appletRef” method on the JDraw sketcher object. Using this you can apply the full JDraw API.
As you have also mentioned the ChemSketcher, please be aware that ChemSketcher is a different Java applet and has nothing to do with JDraw. ChemSketcher is the rendering component in the PP Reporting Collection that can launch Accelrys Draw by double-click.