Scripting with Com4J fails "class not registered"

Hello,

I try to work with RhinoScript via Com4J. Creating an application and a interface instance works fine but I’m not able to create a RhinoScript instance. The class is not registered. I checked the registry and the RhinoScript is not entered in the registry. Is it possible to work with the RhinoScript methods without the regisration? Or is it possible to registrate the RhinoScript manual?

Thanks in advance, Johannes

It seems that RhinoScript is not registered in the windows registry. Does usually the Rhino installer register RhinoScript?

Thanks in advance, Johannes

Hi @burkhart.johannes,

You won’t be able to instantiate RhinoScript on it’s own, as it’s dependent on Rhino. You’ll first need to create a Rhino.Application object and, from it, get the RhinoScript object.

https://developer.rhino3d.com/api/rhinoscript/introduction/external_access.htm

– Dale

Hi Dale,

thank you very much for the reply. I will post my code here for the reference.

///////////// CODE START

package rhino  ;

import com4j.*;

/**
 * Defines methods to create COM objects
 */
public abstract class ClassFactory {
  private ClassFactory() {} // instanciation is not allowed


  public static rhino.IRhinoApplication createRhinoApplication() {
    return COM4J.createInstance( rhino.IRhinoApplication.class, "{1C896D49-793C-474D-A3C5-176904543BED}" );
  }

  public static rhino.IRhinoInterface createRhinoInterface() {
    return COM4J.createInstance( rhino.IRhinoInterface.class, "{7EDBB411-45F0-41C7-A4D4-42B51D4B968C}" );
  }
  
  public static IRhinoScript createRhinoScript() {
	    return COM4J.createInstance( IRhinoScript.class, "{48B5D8DC-EDB1-45A9-981B-6C96169A0E7D}" );
  }
  
  
  public static void main(String[] args) {
	  IRhinoApplication application = createRhinoApplication(); // **this works**
	  IRhinoScript script = createRhinoScript(); // this does produce the **error** (but would give access to the methods within IRhinoScript)
	  Object script2 = application.getScriptObject(); // this works but **won't give access...**
  }
  
}

//////////////// CODE END

I tried creating a rhino.application and I created a object script… but in Java I do not have the possibility to access the methods within IRhinoScript when all I get back from the getScriptObject() method is an object (and not an IRhinoScript instance).
There is no way to get an IRhinoscript instance?
Does the windows installer register the rhinoscript.tlb in the windows reg (then the createIRhinScript method should work).

Thanks again in advance,

Johannes

@burkhart.johannes - I edited your post to use code markup: enclose code in tripple backticks.

Hi @burkhart.johannes,

I don’t know Java. But if you import/reference the RhinoScript type library, you should be able to cast the object as an IRhinoScript object.

if (null == m_RhinoScript)
{
  try
  {
    object obj = m_Rhino.GetScriptObject();
    m_RhinoScript = (IRhinoScript)obj;
  }
  catch (Exception ex)
  {
    MessageBox.Show(string.Format("Error = {0}", ex.Message));
  }
}

– Dale

Hi @dale,

unfortunately I can not cast the object.

public abstract class ClassFactory {
private ClassFactory() {
} // instanciation is not allowed

public static rhino.IRhinoApplication createRhinoApplication() {
	return COM4J.createInstance(rhino.IRhinoApplication.class, "{1C896D49-793C-474D-A3C5-176904543BED}");
}

public static rhino.IRhinoInterface createRhinoInterface() {
	return COM4J.createInstance(rhino.IRhinoInterface.class, "{7EDBB411-45F0-41C7-A4D4-42B51D4B968C}");
}

public static IRhinoScript createRhinoScript() {
	return COM4J.createInstance(IRhinoScript.class, "{48B5D8DC-EDB1-45A9-981B-6C96169A0E7D}");
}

public static void main(String[] args) {
	IRhinoApplication m_Rhino = createRhinoApplication(); // this works
	IRhinoScript m_RhinoScript = null;// = createRhinoScript();

	if (null == m_RhinoScript) {
			Object obj = m_Rhino.getScriptObject();
			 m_RhinoScript = (IRhinoScript) obj;
	}
}

}

fails with: “Exception in thread “main” java.lang.ClassCastException: com4j.Wrapper cannot be cast to rhino.IRhinoScript
at rhino.ClassFactory.main(ClassFactory.java:33)”

Do you see the possibilty to register RhinoScript itself in the registry? Then it would be possible to use the methods of the library directly. Or is it possible, that we have to integrate the rhinoscript.tlb somehow other than just importing it like the other classes (as a source code) …

Hi @dale,

do you see a possibility for the registration of RhinoScript in windows? That would save me a lot of work, otherwise I would have to write every method in java by myself.

Or do you know an option to include the tlb in java?

Thanks in advance, Johannes