Question

I often times have the need to import 3D points (x,y,z data) into the CAD software CATIA. Currently I do this by creating an excel spreadsheet using a java library, and then executing a visual basic macro from within excel to add the data to CATIA. Now I'm not much of a VB guy, which is why I'd like to skip the excel step and directly send data to CATIA. Is there a way to do this? Maybe a java library to allow me to call VB code? Or maybe there is a java api to CATIA which I could use?

Kind regards, MHOOO

Was it helpful?

Solution

Unless you are lucky enough to have a CAA licence, the only API exposed by CATIA V5 is the VB one. The good thing is that this is in fact a COM interface, which you can invoke not only from VBA but also from a variety of languages that do support this protocol. (C++, Python, Java, ...).

For Java, you need a library for accessing COM and thus the CATIA API. The easiest for me is Jacob (http://danadler.com/jacob/).

Here's some sample code using Jacob:

import java.net.UnknownHostException;

import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

import com.jacob.activeX.ActiveXComponent;

class TestMacroInvocation
{
    public static void main( String [] args ) throws Exception
    {
        ActiveXComponent catia = new ActiveXComponent("CATIA.Application");
        catia.setProperty("Visible", new Variant(true));
        Dispatch oDocuments = catia.getProperty("Documents").toDispatch();
        Dispatch oDocument = Dispatch.call(oDocuments, "Open", "C:\\Users\\Me\\Desktop\\TestRib.CATPart").toDispatch();

        Dispatch.call(catia, "StartCommand", "MyMacro");
        Dispatch.call(catia, "Quit");
    }

It's just a different way to use the CATIA VBA API, and you'll have to rely on the documentation provided by Dassault Sytèmes.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top